MCPcopy Create free account
hub / github.com/DOSNetwork/core / UnmarshalBinary

Method UnmarshalBinary

group/mod/int.go:334–347  ·  view source on GitHub ↗

UnmarshalBinary tries to decode a Int from a byte-slice buffer. Returns an error if the buffer is not exactly Len() bytes long or if the contents of the buffer represents an out-of-range integer.

(buf []byte)

Source from the content-addressed store, hash-verified

332// Returns an error if the buffer is not exactly Len() bytes long
333// or if the contents of the buffer represents an out-of-range integer.
334func (i *Int) UnmarshalBinary(buf []byte) error {
335 if len(buf) != i.MarshalSize() {
336 return errors.New("UnmarshalBinary: wrong size buffer")
337 }
338 // Still needed here because of the comparison with the modulo
339 if i.BO == LittleEndian {
340 buf = reverse(nil, buf)
341 }
342 i.V.SetBytes(buf)
343 if i.V.Cmp(i.M) >= 0 {
344 return errors.New("UnmarshalBinary: value out of range")
345 }
346 return nil
347}
348
349// MarshalTo encodes this Int to the given Writer.
350func (i *Int) MarshalTo(w io.Writer) (int, error) {

Callers 4

receiveIDMethod · 0.45
TestIntEndiannessFunction · 0.45
PointUnmarshalFromFunction · 0.45
ScalarUnmarshalFromFunction · 0.45

Calls 5

MarshalSizeMethod · 0.95
reverseFunction · 0.85
CmpMethod · 0.80
NewMethod · 0.65
SetBytesMethod · 0.45

Tested by 1

TestIntEndiannessFunction · 0.36