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

Method MarshalBinary

group/mod/int.go:314–329  ·  view source on GitHub ↗

MarshalBinary encodes the value of this Int into a byte-slice exactly Len() bytes long. It uses i's ByteOrder to determine which byte order to output.

()

Source from the content-addressed store, hash-verified

312// MarshalBinary encodes the value of this Int into a byte-slice exactly Len() bytes long.
313// It uses i's ByteOrder to determine which byte order to output.
314func (i *Int) MarshalBinary() ([]byte, error) {
315 l := i.MarshalSize()
316 b := i.V.Bytes() // may be shorter than l
317 offset := l - len(b)
318
319 if i.BO == LittleEndian {
320 return i.LittleEndian(l, l), nil
321 }
322
323 if offset != 0 {
324 nb := make([]byte, l)
325 copy(nb[offset:], b)
326 b = nb
327 }
328 return b, nil
329}
330
331// UnmarshalBinary tries to decode a Int from a byte-slice buffer.
332// Returns an error if the buffer is not exactly Len() bytes long

Callers 7

receiveIDMethod · 0.45
sendIDMethod · 0.45
TestIntEndiannessFunction · 0.45
TestInitsFunction · 0.45
TestIntCloneFunction · 0.45
PointMarshalToFunction · 0.45
ScalarMarshalToFunction · 0.45

Calls 2

MarshalSizeMethod · 0.95
LittleEndianMethod · 0.95

Tested by 3

TestIntEndiannessFunction · 0.36
TestInitsFunction · 0.36
TestIntCloneFunction · 0.36