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)
| 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. |
| 334 | func (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. |
| 350 | func (i *Int) MarshalTo(w io.Writer) (int, error) { |