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

Function _encode

lib.commonjs/utils/rlp-encode.js:14–39  ·  view source on GitHub ↗
(object)

Source from the content-addressed store, hash-verified

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

Callers 1

encodeRlpFunction · 0.70

Calls 3

arrayifyIntegerFunction · 0.70
callMethod · 0.65
isArrayMethod · 0.45

Tested by

no test coverage detected