@@ -983,6 +983,65 @@ func TestMapBatchLookupAllocations(t *testing.T) {
983
983
qt .Assert (t , qt .Equals (allocs , 0 ))
984
984
}
985
985
986
+ type customTestUnmarshaler []uint8
987
+
988
+ func (c customTestUnmarshaler ) UnmarshalBinary (data []byte ) error {
989
+ chunkSize := len (data ) / len (c )
990
+
991
+ for i := range len (data ) / chunkSize {
992
+ c [i ] = data [i * chunkSize ]
993
+ }
994
+
995
+ return nil
996
+ }
997
+
998
+ func TestMapBatchLookupCustomUnmarshaler (t * testing.T ) {
999
+ testutils .SkipIfNotSupported (t , haveBatchAPI ())
1000
+
1001
+ m := mustNewMap (t , & MapSpec {
1002
+ Type : Array ,
1003
+ MaxEntries : 3 ,
1004
+ KeySize : 4 ,
1005
+ ValueSize : 4 ,
1006
+ Contents : []MapKV {
1007
+ {uint32 (0 ), uint32 (3 )},
1008
+ {uint32 (1 ), uint32 (4 )},
1009
+ {uint32 (2 ), uint32 (5 )},
1010
+ },
1011
+ }, nil )
1012
+
1013
+ var (
1014
+ cursor MapBatchCursor
1015
+ // Use data structures that result in different memory size than the
1016
+ // map keys and values. Otherwise their memory is used as backing
1017
+ // memory for the syscall directly and Unmarshal is a no-op.
1018
+ // Use batch size that results in partial second lookup.
1019
+ batchKeys = make (customTestUnmarshaler , 2 )
1020
+ batchValues = make (customTestUnmarshaler , 2 )
1021
+ keys []uint8
1022
+ values []uint8
1023
+ )
1024
+
1025
+ _ , err := m .BatchLookup (& cursor , batchKeys , batchValues , nil )
1026
+ if err != nil {
1027
+ t .Fatal ("Full batch lookup failed:" , err )
1028
+ }
1029
+
1030
+ keys = append (keys , batchKeys ... )
1031
+ values = append (values , batchValues ... )
1032
+
1033
+ _ , err = m .BatchLookup (& cursor , batchKeys , batchValues , nil )
1034
+ if ! errors .Is (err , ErrKeyNotExist ) {
1035
+ t .Fatal ("Partial batch lookup doesn't return ErrKeyNotExist:" , err )
1036
+ }
1037
+
1038
+ keys = append (keys , batchKeys [0 ])
1039
+ values = append (values , batchValues [0 ])
1040
+
1041
+ qt .Assert (t , qt .DeepEquals (keys , []uint8 {0 , 1 , 2 }))
1042
+ qt .Assert (t , qt .DeepEquals (values , []uint8 {3 , 4 , 5 }))
1043
+ }
1044
+
986
1045
func TestMapIterateHashKeyOneByteFull (t * testing.T ) {
987
1046
hash := mustNewMap (t , & MapSpec {
988
1047
Type : Hash ,
0 commit comments