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

Method Encode

internal/core/entry.go:68–86  ·  view source on GitHub ↗

Encode returns the slice after the entry be encoded. the entry stored format: |----------------------------------------------------------------------------------------------------------| | crc | timestamp | ksz | valueSize | flag | TTL | status | ds | txId | bucketId | key | value |

()

Source from the content-addressed store, hash-verified

66// | uint32| uint64 |uint32 | uint32 | uint16 | uint32| uint16 | uint16 |uint64 | uint64 | []byte | []byte |
67// |----------------------------------------------------------------------------------------------------------|
68func (e *Entry) Encode() []byte {
69 keySize := e.Meta.KeySize
70 valueSize := e.Meta.ValueSize
71
72 buf := make([]byte, MaxEntryHeaderSize+keySize+valueSize)
73
74 index := e.setEntryHeaderBuf(buf)
75 copy(buf[index:], e.Key)
76 index += int(keySize)
77 copy(buf[index:], e.Value)
78 index += int(valueSize)
79
80 buf = buf[:index]
81
82 c32 := crc32.ChecksumIEEE(buf[4:])
83 binary.LittleEndian.PutUint32(buf[0:4], c32)
84
85 return buf
86}
87
88// setEntryHeaderBuf sets the entry header buff.
89func (e *Entry) setEntryHeaderBuf(buf []byte) int {

Callers 2

createTestEntryFunction · 0.95
Test_EntryMostFunctionsFunction · 0.45

Calls 1

setEntryHeaderBufMethod · 0.95

Tested by 2

createTestEntryFunction · 0.76
Test_EntryMostFunctionsFunction · 0.36