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

Function _encode

lib.esm/utils/rlp-encode.js:11–36  ·  view source on GitHub ↗
(object)

Source from the content-addressed store, hash-verified

9 return result;
10}
11function _encode(object) {
12 if (Array.isArray(object)) {
13 let payload = [];
14 object.forEach(function (child) {
15 payload = payload.concat(_encode(child));
16 });
17 if (payload.length <= 55) {
18 payload.unshift(0xc0 + payload.length);
19 return payload;
20 }
21 const length = arrayifyInteger(payload.length);
22 length.unshift(0xf7 + length.length);
23 return length.concat(payload);
24 }
25 const data = Array.prototype.slice.call(getBytes(object, "object"));
26 if (data.length === 1 && data[0] <= 0x7f) {
27 return data;
28 }
29 else if (data.length <= 55) {
30 data.unshift(0x80 + data.length);
31 return data;
32 }
33 const length = arrayifyInteger(data.length);
34 length.unshift(0xb7 + length.length);
35 return length.concat(data);
36}
37const nibbles = "0123456789abcdef";
38/**
39 * Encodes %%object%% as an RLP-encoded [[DataHexString]].

Callers 1

encodeRlpFunction · 0.70

Calls 4

getBytesFunction · 0.90
arrayifyIntegerFunction · 0.70
callMethod · 0.65
isArrayMethod · 0.45

Tested by

no test coverage detected