MCPcopy Create free account
hub / github.com/nutsdb/nutsdb / Decode

Method Decode

hintfile.go:131–216  ·  view source on GitHub ↗

Decode decodes the hint entry from bytes

(buf []byte)

Source from the content-addressed store, hash-verified

129
130// Decode decodes the hint entry from bytes
131func (h *HintEntry) Decode(buf []byte) error {
132 if len(buf) == 0 {
133 return ErrHintFileEntryInvalid
134 }
135
136 index := 0
137
138 bucketId, n := binary.Uvarint(buf[index:])
139 if n <= 0 {
140 return ErrHintFileCorrupted
141 }
142 index += n
143 h.BucketId = bucketId
144
145 keySize, n := binary.Uvarint(buf[index:])
146 if n <= 0 {
147 return ErrHintFileCorrupted
148 }
149 index += n
150 h.KeySize = uint32(keySize)
151
152 valueSize, n := binary.Uvarint(buf[index:])
153 if n <= 0 {
154 return ErrHintFileCorrupted
155 }
156 index += n
157 h.ValueSize = uint32(valueSize)
158
159 timestamp, n := binary.Uvarint(buf[index:])
160 if n <= 0 {
161 return ErrHintFileCorrupted
162 }
163 index += n
164 h.Timestamp = timestamp
165
166 ttl, n := binary.Uvarint(buf[index:])
167 if n <= 0 {
168 return ErrHintFileCorrupted
169 }
170 index += n
171 h.TTL = uint32(ttl)
172
173 flag, n := binary.Uvarint(buf[index:])
174 if n <= 0 {
175 return ErrHintFileCorrupted
176 }
177 index += n
178 h.Flag = uint16(flag)
179
180 status, n := binary.Uvarint(buf[index:])
181 if n <= 0 {
182 return ErrHintFileCorrupted
183 }
184 index += n
185 h.Status = uint16(status)
186
187 ds, n := binary.Uvarint(buf[index:])
188 if n <= 0 {

Callers 5

BenchmarkHintFileDecodeFunction · 0.95
readBucketMethod · 0.45

Calls 1

decodeCompatInt64Function · 0.85