Skip to content

Commit edd4250

Browse files
committed
map: allow partial unmarshaling
Signed-off-by: Florian Lehner <[email protected]>
1 parent 278ac23 commit edd4250

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

internal/sysenc/buffer.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,17 @@ func (b Buffer) Pointer() sys.Pointer {
6868

6969
// Unmarshal the buffer into the provided value.
7070
func (b Buffer) Unmarshal(data any) error {
71+
return b.UnmarshalWithLimit(data, b.size)
72+
}
73+
74+
// UnmarshalWithLimit unmarshals the buffer up to limit into the provided value.
75+
func (b Buffer) UnmarshalWithLimit(data any, limit int) error {
7176
if b.size == syscallPointerOnly {
7277
return nil
7378
}
74-
79+
if b.size != limit {
80+
return Unmarshal(data, b.unsafeBytes()[:limit])
81+
}
7582
return Unmarshal(data, b.unsafeBytes())
7683
}
7784

map.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1155,7 +1155,7 @@ func (m *Map) batchLookupCmd(cmd sys.Cmd, cursor *MapBatchCursor, count int, key
11551155
return int(attr.Count), sysErr
11561156
}
11571157

1158-
if err := keyBuf.Unmarshal(keysOut); err != nil {
1158+
if err := keyBuf.UnmarshalWithLimit(keysOut, int(attr.Count)*int(m.keySize)); err != nil {
11591159
return 0, err
11601160
}
11611161

0 commit comments

Comments
 (0)