unpackMapWithAllocator takes a dense map of u32 -> structure, flattens the map into a slice, allocates the appropriate data using a custom provided allocation function and returns it as well as the length of the map.
(alloc func(v ...interface{}) api.AllocResult, m interface{})
| 28 | // map into a slice, allocates the appropriate data using a custom provided |
| 29 | // allocation function and returns it as well as the length of the map. |
| 30 | func unpackMapWithAllocator(alloc func(v ...interface{}) api.AllocResult, m interface{}) (api.AllocResult, uint32) { |
| 31 | u32Type := reflect.TypeOf(uint32(0)) |
| 32 | d := dictionary.From(m) |
| 33 | if d == nil || d.KeyTy() != u32Type { |
| 34 | msg := fmt.Sprintf("Expecting a map of u32 -> structures: got %T", m) |
| 35 | panic(msg) |
| 36 | } |
| 37 | |
| 38 | sl := reflect.MakeSlice(reflect.SliceOf(d.ValTy()), d.Len(), d.Len()) |
| 39 | for _, e := range dictionary.Entries(d) { |
| 40 | i := e.K.(uint32) |
| 41 | v := reflect.ValueOf(e.V) |
| 42 | sl.Index(int(i)).Set(v) |
| 43 | } |
| 44 | |
| 45 | return alloc(sl.Interface()), uint32(d.Len()) |
| 46 | } |
| 47 | |
| 48 | // unpackMap takes a dense map of u32 -> structure, flattens the map into |
| 49 | // a slice, allocates the appropriate data and returns it as well as the |
no test coverage detected