(data, offset)
| 33 | } |
| 34 | // returns { consumed: number, result: Object } |
| 35 | function _decode(data, offset) { |
| 36 | (0, errors_js_1.assert)(data.length !== 0, "data too short", "BUFFER_OVERRUN", { |
| 37 | buffer: data, length: 0, offset: 1 |
| 38 | }); |
| 39 | const checkOffset = (offset) => { |
| 40 | (0, errors_js_1.assert)(offset <= data.length, "data short segment too short", "BUFFER_OVERRUN", { |
| 41 | buffer: data, length: data.length, offset |
| 42 | }); |
| 43 | }; |
| 44 | // Array with extra length prefix |
| 45 | if (data[offset] >= 0xf8) { |
| 46 | const lengthLength = data[offset] - 0xf7; |
| 47 | checkOffset(offset + 1 + lengthLength); |
| 48 | const length = unarrayifyInteger(data, offset + 1, lengthLength); |
| 49 | checkOffset(offset + 1 + lengthLength + length); |
| 50 | return _decodeChildren(data, offset, offset + 1 + lengthLength, lengthLength + length); |
| 51 | } |
| 52 | else if (data[offset] >= 0xc0) { |
| 53 | const length = data[offset] - 0xc0; |
| 54 | checkOffset(offset + 1 + length); |
| 55 | return _decodeChildren(data, offset, offset + 1, length); |
| 56 | } |
| 57 | else if (data[offset] >= 0xb8) { |
| 58 | const lengthLength = data[offset] - 0xb7; |
| 59 | checkOffset(offset + 1 + lengthLength); |
| 60 | const length = unarrayifyInteger(data, offset + 1, lengthLength); |
| 61 | checkOffset(offset + 1 + lengthLength + length); |
| 62 | const result = (0, data_js_1.hexlify)(data.slice(offset + 1 + lengthLength, offset + 1 + lengthLength + length)); |
| 63 | return { consumed: (1 + lengthLength + length), result: result }; |
| 64 | } |
| 65 | else if (data[offset] >= 0x80) { |
| 66 | const length = data[offset] - 0x80; |
| 67 | checkOffset(offset + 1 + length); |
| 68 | const result = (0, data_js_1.hexlify)(data.slice(offset + 1, offset + 1 + length)); |
| 69 | return { consumed: (1 + length), result: result }; |
| 70 | } |
| 71 | return { consumed: 1, result: hexlifyByte(data[offset]) }; |
| 72 | } |
| 73 | /** |
| 74 | * Decodes %%data%% into the structured data it represents. |
| 75 | */ |
no test coverage detected