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.
()
| 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. |
| 314 | func (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 |