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 |
()
| 66 | // | uint32| uint64 |uint32 | uint32 | uint16 | uint32| uint16 | uint16 |uint64 | uint64 | []byte | []byte | |
| 67 | // |----------------------------------------------------------------------------------------------------------| |
| 68 | func (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. |
| 89 | func (e *Entry) setEntryHeaderBuf(buf []byte) int { |