decodeLogRecordHeader decodes the header information from a byte buffer.
(buf []byte)
| 101 | |
| 102 | // decodeLogRecordHeader decodes the header information from a byte buffer. |
| 103 | func decodeLogRecordHeader(buf []byte) (*LogRecordHeader, int64) { |
| 104 | if len(buf) <= 4 { |
| 105 | return nil, 0 |
| 106 | } |
| 107 | |
| 108 | header := &LogRecordHeader{ |
| 109 | crc: binary.LittleEndian.Uint32(buf[:4]), // Decode CRC checksum |
| 110 | recordType: buf[4], // Decode record type |
| 111 | } |
| 112 | |
| 113 | var headerIndex = 5 |
| 114 | // Extract key/value sizes |
| 115 | keySize, lens := binary.Varint(buf[headerIndex:]) // Decode key size |
| 116 | header.keySize = uint32(keySize) |
| 117 | headerIndex += lens |
| 118 | |
| 119 | valueSize, lens := binary.Varint(buf[headerIndex:]) // Decode value size |
| 120 | header.valueSize = uint32(valueSize) |
| 121 | headerIndex += lens |
| 122 | |
| 123 | return header, int64(headerIndex) |
| 124 | } |
| 125 | |
| 126 | // getLogRecordCRC calculates the CRC checksum for a LogRecord. |
| 127 | func getLogRecordCRC(logRecord *LogRecord, header []byte) uint32 { |
no outgoing calls