MCPcopy Create free account
hub / github.com/PageLeay/celestial-runtime / _decode

Function _decode

lib.commonjs/utils/rlp-decode.js:35–72  ·  view source on GitHub ↗
(data, offset)

Source from the content-addressed store, hash-verified

33}
34// returns { consumed: number, result: Object }
35function _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 */

Callers 2

_decodeChildrenFunction · 0.70
decodeRlpFunction · 0.70

Calls 5

checkOffsetFunction · 0.70
unarrayifyIntegerFunction · 0.70
_decodeChildrenFunction · 0.70
hexlifyByteFunction · 0.70
sliceMethod · 0.45

Tested by

no test coverage detected