MCPcopy Create free account
hub / github.com/HDT3213/rdb / writeLength

Method writeLength

core/string.go:199–219  ·  view source on GitHub ↗
(value uint64)

Source from the content-addressed store, hash-verified

197}
198
199func (enc *Encoder) writeLength(value uint64) error {
200 var buf []byte
201 if value <= maxUint6 {
202 // 00 + 6 bits of data
203 enc.buffer[0] = byte(value)
204 buf = enc.buffer[0:1]
205 } else if value <= maxUint14 {
206 enc.buffer[0] = byte(value>>8) | len14BitMask // high 6 bit and mask(0x40)
207 enc.buffer[1] = byte(value) // low 8 bit
208 buf = enc.buffer[0:2]
209 } else if value <= math.MaxUint32 {
210 buf = make([]byte, 5)
211 buf[0] = len32Bit
212 binary.BigEndian.PutUint32(buf[1:], uint32(value))
213 } else {
214 buf = make([]byte, 9)
215 buf[0] = len64Bit
216 binary.BigEndian.PutUint64(buf[1:], value)
217 }
218 return enc.write(buf)
219}
220
221func (enc *Encoder) writeSimpleString(s string) error {
222 err := enc.writeLength(uint64(len(s)))

Callers 15

writeSetEncodingMethod · 0.95
writeHashEncodingMethod · 0.95
writeHashEncodingExMethod · 0.95
writeHash2EncodingMethod · 0.95
TestLengthEncodingFunction · 0.95
writeSimpleStringMethod · 0.95
writeLZFStringMethod · 0.95
WriteDBHeaderMethod · 0.95
writeZSet2EncodingMethod · 0.95
WriteStreamObjectMethod · 0.95
writeStreamIdMethod · 0.95
writeStreamEntriesMethod · 0.95

Calls 1

writeMethod · 0.95

Tested by 2

TestLengthEncodingFunction · 0.76
TestModuleTypeFunction · 0.76