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

Method Encode

hintfile.go:106–128  ·  view source on GitHub ↗

Encode encodes the hint entry to bytes

()

Source from the content-addressed store, hash-verified

104
105// Encode encodes the hint entry to bytes
106func (h *HintEntry) Encode() []byte {
107 keySize := len(h.Key)
108 h.KeySize = uint32(keySize)
109
110 buf := make([]byte, h.Size())
111 index := 0
112
113 index += binary.PutUvarint(buf[index:], h.BucketId)
114 index += binary.PutUvarint(buf[index:], uint64(keySize))
115 index += binary.PutUvarint(buf[index:], uint64(h.ValueSize))
116 index += binary.PutUvarint(buf[index:], h.Timestamp)
117 index += binary.PutUvarint(buf[index:], uint64(h.TTL))
118 index += binary.PutUvarint(buf[index:], uint64(h.Flag))
119 index += binary.PutUvarint(buf[index:], uint64(h.Status))
120 index += binary.PutUvarint(buf[index:], uint64(h.Ds))
121 index += binary.PutUvarint(buf[index:], h.DataPos)
122 index += binary.PutVarint(buf[index:], h.FileID)
123
124 copy(buf[index:], h.Key)
125 index += keySize
126
127 return buf[:index]
128}
129
130// Decode decodes the hint entry from bytes
131func (h *HintEntry) Decode(buf []byte) error {

Callers 14

BenchmarkHintFileEncodeFunction · 0.95
BenchmarkHintFileDecodeFunction · 0.95
TestHintEntrySizeFunction · 0.95
Test_readEntryFunction · 0.45
writeEntryMethod · 0.45
CommitMethod · 0.45
WriteMethod · 0.45
TestDataFile1Function · 0.45
TestDataFile2Function · 0.45

Calls 1

SizeMethod · 0.95

Tested by 10

BenchmarkHintFileEncodeFunction · 0.76
BenchmarkHintFileDecodeFunction · 0.76
TestHintEntrySizeFunction · 0.76
Test_readEntryFunction · 0.36
TestDataFile1Function · 0.36
TestDataFile2Function · 0.36
TestDataFile_Crc_ErrFunction · 0.36