MCPcopy Create free account
hub / github.com/ccxt/ccxt / encode

Method encode

js/src/static_dependencies/ethers/coders/number.js:19–34  ·  view source on GitHub ↗
(writer, _value)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 6

getBigIntFunction · 0.90
maskFunction · 0.90
toTwosFunction · 0.90
_throwErrorMethod · 0.80
dereferenceMethod · 0.45
writeValueMethod · 0.45

Tested by

no test coverage detected