Skip to content

Commit a493d9d

Browse files
committed
Fix PCCC typed write encoding bugs caught by golden tests
- EncodeDataDescriptor passed the offset ref object instead of the offset number in the extended-type-id branch, so every typed write whose type id needs an extension byte (notably floats, id 0x08) threw ERR_INVALID_ARG_TYPE instead of writing - TypedWriteRequest now rejects timer/counter/control/string/long addresses with a clear unsupported-type error; previously the undefined type id flowed into the descriptor encoder and produced the same cryptic TypeError - PCCC internal replies no longer fall through to forward() when the context callback was already consumed https://claude.ai/code/session_01AuAYuP6dTn8ALpkKErQuby
1 parent 116a0c3 commit a493d9d

3 files changed

Lines changed: 8 additions & 2 deletions

File tree

src/layers/pccc/encoding.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export function EncodeDataDescriptor(data, offsetRef, id, size) {
6565
}
6666

6767
if (idLength > 0 && sizeLength === 0) {
68-
offsetRef.current = data.writeUInt8(((0b1000 | idLength) << 4) | size, offsetRef);
68+
offsetRef.current = data.writeUInt8(((0b1000 | idLength) << 4) | size, offsetRef.current);
6969
offsetRef.current = encodeUnsignedInteger(data, offsetRef.current, id, idLength);
7070
return;
7171
}

src/layers/pccc/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,10 @@ export default class PCCCLayer extends Layer {
248248
const callback = this.callbackForContext(savedContext.context);
249249
if (callback != null) {
250250
callback(getError(packet.status), packet, info);
251-
return;
252251
}
252+
/** internal replies must never be forwarded to upper layers,
253+
* even if the callback was already consumed */
254+
return;
253255
}
254256

255257
this.forward(packet.data, info, savedContext.context);

src/layers/pccc/packet.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ export default class PCCCPacket {
229229
throw new Error(`Unsupported address: ${address}`);
230230
}
231231

232+
if (info.id == null) {
233+
throw new Error(`Writing to ${info.datatype} files is not currently supported (address: ${address})`);
234+
}
235+
232236
const valueCount = values.length;
233237
const dataValueLength = valueCount * info.size;
234238
const dataTypeLength = DataTypeEncodingLength(info.id, info.size);

0 commit comments

Comments
 (0)