You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
312 B

  1. package ber
  2. func encodeUnsignedInteger(i uint64) []byte {
  3. n := uint64Length(i)
  4. out := make([]byte, n)
  5. var j int
  6. for ; n > 0; n-- {
  7. out[j] = (byte(i >> uint((n-1)*8)))
  8. j++
  9. }
  10. return out
  11. }
  12. func uint64Length(i uint64) (numBytes int) {
  13. numBytes = 1
  14. for i > 255 {
  15. numBytes++
  16. i >>= 8
  17. }
  18. return
  19. }