Skip to content

Commit 67d493b

Browse files
committed
Byte parser, new test and tweak hex threshold
1 parent 2d503f4 commit 67d493b

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

utils/ByteStringParser.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,13 @@ gingin-chasm-1 | [00] 2025-10-16T10:50:50.223Z INFO in/udp.go:296 Received
222222
expect(result.bytes[0]).toBe(0x03);
223223
expect(result.bytes[1]).toBe(0x1a);
224224
});
225+
226+
it('should parse space-separated hex message with prefix (4C 42)', () => {
227+
const input = '4C 42 03 42 00 3A 00 01 00 01 04 1D 00 00 00 02 00 01 0A 02 C3 07 2B FE 02 01 51 24 00 88 01 00 CF 8A 02 69 00 00 00 00 00 00 01 1E 00 C2 80 9A 40 00 00 00 00 40 80 00 00 01 40 00 00 00 C0 00 00 04 29 B2';
228+
const result = parseByteString(input);
229+
expect(result.hasHex).toBe(true);
230+
expect(result.bytes).toEqual([0x4C, 0x42, 0x03, 0x42, 0x00, 0x3A, 0x00, 0x01, 0x00, 0x01, 0x04, 0x1D, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x0A, 0x02, 0xC3, 0x07, 0x2B, 0xFE, 0x02, 0x01, 0x51, 0x24, 0x00, 0x88, 0x01, 0x00, 0xCF, 0x8A, 0x02, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x1E, 0x00, 0xC2, 0x80, 0x9A, 0x40, 0x00, 0x00, 0x00, 0x00, 0x40, 0x80, 0x00, 0x00, 0x01, 0x40, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x04, 0x29, 0xB2]);
231+
});
225232
});
226233

227234
describe('base64 mode', () => {

utils/ByteStringParser.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,9 @@ function parseSingleByteString(input: string): ParsedBytes {
152152
// Count how many of the hex pairs contain a-f (strong hex indicators)
153153
if (hexPairs.length >= 2 && hasHexLetters) {
154154
const hexPairsWithLetters = hexPairs.filter(pair => /[a-fA-F]/.test(pair)).length;
155-
// If at least one hex pair contains letters, and most pairs are hex-like, use hex mode
156-
if (hexPairsWithLetters >= 1 && hexPairsWithLetters / hexPairs.length > 0.3) {
155+
// If at least one hex pair contains letters, and reasonable ratio, use hex mode
156+
// Lower threshold (0.15) handles messages with many 00/01 bytes but clear hex letters
157+
if (hexPairsWithLetters >= 1 && hexPairsWithLetters / hexPairs.length > 0.15) {
157158
return parseHexBytes(normalized);
158159
}
159160
}

0 commit comments

Comments
 (0)