MCPcopy Create free account
hub / github.com/ZeppelinMC/Zeppelin / VarInt

Function VarInt

protocol/net/io/encoding/encoding.go:69–98  ·  view source on GitHub ↗
(data []byte)

Source from the content-addressed store, hash-verified

67}
68
69func VarInt(data []byte) (int32, []byte, error) {
70 var (
71 position int
72 currentByte byte
73
74 value int32
75 )
76
77 for {
78 if len(data) == 0 {
79 return value, data, io.EOF
80 }
81 currentByte = data[0]
82 data = data[1:]
83
84 value |= int32(currentByte&127) << position
85
86 if (currentByte & 128) == 0 {
87 break
88 }
89
90 position += 7
91
92 if position >= 32 {
93 return value, data, fmt.Errorf("VarInt is too big")
94 }
95 }
96
97 return value, data, nil
98}
99
100func ReadVarInt(r io.Reader) (int32, error) {
101 var (

Callers 2

ReadPacketMethod · 0.92
StringFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected