MCPcopy Create free account
hub / github.com/denoland/std / decodeMap

Function decodeMap

msgpack/decode.ts:71–93  ·  view source on GitHub ↗
(
  uint8: Uint8Array,
  dataView: DataView,
  size: number,
  pointer: { consumed: number },
)

Source from the content-addressed store, hash-verified

69}
70
71function decodeMap(
72 uint8: Uint8Array,
73 dataView: DataView,
74 size: number,
75 pointer: { consumed: number },
76) {
77 const map: Record<number | string, ValueType> = {};
78
79 for (let i = 0; i < size; i++) {
80 const key = decodeSlice(uint8, dataView, pointer);
81 const value = decodeSlice(uint8, dataView, pointer);
82
83 if (typeof key !== "number" && typeof key !== "string") {
84 throw new EvalError(
85 "Cannot decode a key of a map: The type of key is invalid, keys must be a number or a string",
86 );
87 }
88
89 map[key] = value;
90 }
91
92 return map;
93}
94
95const decoder = new TextDecoder();
96

Callers 1

decodeSliceFunction · 0.70

Calls 1

decodeSliceFunction · 0.85

Tested by

no test coverage detected