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

Function ReadVarInt

protocol/net/io/encoding/encoding.go:100–129  ·  view source on GitHub ↗
(r io.Reader)

Source from the content-addressed store, hash-verified

98}
99
100func ReadVarInt(r io.Reader) (int32, error) {
101 var (
102 position int32
103 currentByte byte
104 continueBit byte = 128
105 segmentBits byte = 127
106
107 value int32
108 )
109
110 for {
111 if _, err := r.Read(unsafe.Slice(&currentByte, 1)); err != nil {
112 return value, err
113 }
114
115 value |= int32(currentByte&segmentBits) << position
116
117 if (currentByte & continueBit) == 0 {
118 break
119 }
120
121 position += 7
122
123 if position >= 32 {
124 return value, fmt.Errorf("VarInt is too big")
125 }
126 }
127
128 return value, nil
129}
130
131func AppendVarLong(data []byte, value int64) []byte {
132 var (

Callers

nothing calls this directly

Calls 1

ReadMethod · 0.45

Tested by

no test coverage detected