Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

32 linhas
502 B

  1. package packet
  2. // encodeUint16 converts the unsigned 16-bit integer
  3. // into a slice of bytes in big-endian order.
  4. func encodeUint16(n uint16) []byte {
  5. return []byte{byte(n >> 8), byte(n)}
  6. }
  7. // encodeLength encodes the unsigned integer
  8. // by using a variable length encoding scheme.
  9. func encodeLength(n uint32) uint32 {
  10. var value, digit uint32
  11. for n > 0 {
  12. if value != 0 {
  13. value <<= 8
  14. }
  15. digit = n % 128
  16. n /= 128
  17. if n > 0 {
  18. digit |= 0x80
  19. }
  20. value |= digit
  21. }
  22. return value
  23. }