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

Method encodeListPackString

core/stream.go:816–836  ·  view source on GitHub ↗

encodeListPackString encodes a string for listpack

(s string)

Source from the content-addressed store, hash-verified

814
815// encodeListPackString encodes a string for listpack
816func (enc *Encoder) encodeListPackString(s string) []byte {
817 bytes := []byte(s)
818 length := len(bytes)
819
820 if length <= 63 {
821 // 10xxxxxx + content, string(len<=63)
822 return append([]byte{byte(0x80 | length)}, bytes...)
823 } else if length < 4096 {
824 // 1110xxxx yyyyyyyy + content, string(len < 1<<12)
825 header := make([]byte, 2)
826 header[0] = byte(0xE0 | (length >> 8))
827 header[1] = byte(length & 0xFF)
828 return append(header, bytes...)
829 } else {
830 // 11110000 aaaaaaaa bbbbbbbb cccccccc dddddddd + content, string(len < 1<<32)
831 header := make([]byte, 5)
832 header[0] = 0xF0
833 binary.LittleEndian.PutUint32(header[1:5], uint32(length))
834 return append(header, bytes...)
835 }
836}

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected