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

Method encode

lib.commonjs/abi/coders/number.js:24–39  ·  view source on GitHub ↗
(writer, _value)

Source from the content-addressed store, hash-verified

22 return 0;
23 }
24 encode(writer, _value) {
25 let value = (0, index_js_1.getBigInt)(typed_js_1.Typed.dereference(_value, this.type));
26 // Check bounds are safe for encoding
27 let maxUintValue = (0, index_js_1.mask)(BN_MAX_UINT256, abstract_coder_js_1.WordSize * 8);
28 if (this.signed) {
29 let bounds = (0, index_js_1.mask)(maxUintValue, (this.size * 8) - 1);
30 if (value > bounds || value < -(bounds + BN_1)) {
31 this._throwError("value out-of-bounds", _value);
32 }
33 value = (0, index_js_1.toTwos)(value, 8 * abstract_coder_js_1.WordSize);
34 }
35 else if (value < BN_0 || value > (0, index_js_1.mask)(maxUintValue, this.size * 8)) {
36 this._throwError("value out-of-bounds", _value);
37 }
38 return writer.writeValue(value);
39 }
40 decode(reader) {
41 let value = (0, index_js_1.mask)(reader.readValue(), this.size * 8);
42 if (this.signed) {

Callers

nothing calls this directly

Calls 3

dereferenceMethod · 0.45
_throwErrorMethod · 0.45
writeValueMethod · 0.45

Tested by

no test coverage detected