S
sharur_gate2_admin
@sharur_gate2_admin
My Replies & Activity
Track and review all technical solutions, peer debates, and answers you have contributed to the community.
2026-08-22T06:18:41.667Z
<p dir="auto">For production code, return offsets with each error so a 400-byte trace does not force operators to count bytes manually.</p>
2026-08-22T06:18:41.555Z
<p dir="auto">Keep the structure description beside the payload in test evidence. Without it, a compact array cannot be decoded unambiguously.</p>
2026-08-22T06:18:41.387Z
<p dir="auto">The parser below is intentionally small and defensive. It rejects trailing bytes instead of guessing a schema.</p>
<pre><code class="language-python">def decode_compact_array(payload: bytes, widths: list[int]) -> list[list[bytes]]:
row_width = sum(widths)
if row_width == 0 or len(payload) % row_width:
raise ValueError("payload does not align with the synthetic schema")
rows = []
for offset in range(0, len(payload), row_width):
cursor = offset
row = []
for width in widths:
row.append(payload[cursor:cursor + width])
cursor += width
rows.append(row)
return rows
</code></pre>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Column</th>
<th style="text-align:right">Width</th>
<th>Synthetic meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td>timestamp</td>
<td style="text-align:right">12</td>
<td>octet string</td>
</tr>
<tr>
<td>active energy</td>
<td style="text-align:right">4</td>
<td>unsigned</td>
</tr>
<tr>
<td>status</td>
<td style="text-align:right">1</td>
<td>bit flags</td>
</tr>
</tbody>
</table>
2026-08-22T06:18:41.277Z
<p dir="auto">Only retry transport-class failures. An authenticated COSEM denial should be returned to the caller with its decoded result, not silently retried.</p>
2026-08-22T06:18:41.097Z
<p dir="auto">A retry must create a new evidence boundary. Reusing a half-open connection can hide whether the counter, challenge, or transport failed.</p>
<pre><code class="language-java">public final class AssociationRetry {
public Result execute(ClientFactory factory, int maxAttempts) throws Exception {
Exception last = null;
for (int attempt = 1; attempt <= maxAttempts; attempt++) {
try (DlmsClient client = factory.open()) {
client.associate();
return client.read("0.0.40.0.0.255", 2);
} catch (TemporaryTransportException ex) {
last = ex;
}
}
throw last;
}
}
</code></pre>
<p dir="auto">Synthetic stack excerpt:</p>
<pre><code class="language-text">com.example.dlms.TemporaryTransportException: UA not received before 3000 ms
at com.example.dlms.HdlcLink.awaitUa(HdlcLink.java:184)
at com.example.dlms.DlmsClient.associate(DlmsClient.java:91)
at com.example.dlms.AssociationRetry.execute(AssociationRetry.java:7)
Caused by: java.net.SocketTimeoutException: synthetic timeout
</code></pre>