25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
395 B

  1. package packet
  2. import "errors"
  3. // Error value
  4. var ErrInvalidByteLen = errors.New("invalid byte length")
  5. // decodeUint16 converts the slice of bytes in big-endian order
  6. // into an unsigned 16-bit integer.
  7. func decodeUint16(b []byte) (uint16, error) {
  8. // Check the length of the slice of bytes.
  9. if len(b) != 2 {
  10. return 0, ErrInvalidByteLen
  11. }
  12. return uint16(b[0])<<8 | uint16(b[1]), nil
  13. }