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

Method ReadEntry

datafile.go:59–99  ·  view source on GitHub ↗

ReadEntry returns entry at the given off(offset). payloadSize = bucketSize + keySize + valueSize

(off int, payloadSize int64)

Source from the content-addressed store, hash-verified

57// ReadEntry returns entry at the given off(offset).
58// payloadSize = bucketSize + keySize + valueSize
59func (df *DataFile) ReadEntry(off int, payloadSize int64) (e *core.Entry, err error) {
60 size := core.MaxEntryHeaderSize + payloadSize
61 // Since core.MaxEntryHeaderSize + payloadSize may be larger than the actual entry size, it needs to be calculated
62 if int64(off)+size > df.rwManager.Size() {
63 size = df.rwManager.Size() - int64(off)
64 }
65 buf := make([]byte, size)
66
67 if _, err := df.rwManager.ReadAt(buf, int64(off)); err != nil {
68 return nil, err
69 }
70
71 e = new(core.Entry)
72 headerSize, err := e.ParseMeta(buf)
73 if err != nil {
74 return nil, err
75 }
76
77 // Remove the content after the Header
78 buf = buf[:int(headerSize+payloadSize)]
79
80 if e.IsZero() {
81 return nil, ErrEntryZero
82 }
83
84 if err := e.CheckPayloadSize(payloadSize); err != nil {
85 return nil, err
86 }
87
88 err = e.ParsePayload(buf[headerSize:])
89 if err != nil {
90 return nil, err
91 }
92
93 crc := e.GetCrc(buf[:headerSize])
94 if crc != e.Meta.Crc {
95 return nil, ErrCrc
96 }
97
98 return
99}
100
101// WriteAt copies data to mapped region from the b slice starting at
102// given off and returns number of bytes copied to the mapped region.

Callers 5

getValueByRecordMethod · 0.80
TestDataFile1Function · 0.80
TestDataFile2Function · 0.80
TestDataFile_ReadRecordFunction · 0.80
TestDataFile_Crc_ErrFunction · 0.80

Calls 7

ParseMetaMethod · 0.80
IsZeroMethod · 0.80
CheckPayloadSizeMethod · 0.80
ParsePayloadMethod · 0.80
GetCrcMethod · 0.80
SizeMethod · 0.65
ReadAtMethod · 0.65

Tested by 4

TestDataFile1Function · 0.64
TestDataFile2Function · 0.64
TestDataFile_ReadRecordFunction · 0.64
TestDataFile_Crc_ErrFunction · 0.64