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

Function encodeHeader

cbor/_common_encode.ts:97–124  ·  view source on GitHub ↗
(
  majorType: number,
  input: number | bigint,
  output: Uint8Array,
  offset: number,
)

Source from the content-addressed store, hash-verified

95}
96
97function encodeHeader(
98 majorType: number,
99 input: number | bigint,
100 output: Uint8Array,
101 offset: number,
102): number {
103 if (input < 24) output[offset++] = majorType + Number(input);
104 else if (input < 2 ** 8) {
105 output[offset++] = majorType + 0b000_11000;
106 output[offset++] = Number(input);
107 } else {
108 const view = new DataView(output.buffer);
109 if (input < 2 ** 16) {
110 output[offset++] = majorType + 0b000_11001;
111 view.setUint16(offset, Number(input));
112 offset += 2;
113 } else if (input < 2 ** 32) {
114 output[offset++] = majorType + 0b000_11010;
115 view.setUint32(offset, Number(input));
116 offset += 4;
117 } else {
118 output[offset++] = majorType + 0b000_11011;
119 view.setBigUint64(offset, BigInt(input));
120 offset += 8;
121 }
122 }
123 return offset;
124}
125
126function encodeNumber(
127 input: number,

Callers 8

encodeNumberFunction · 0.85
encodeBigIntFunction · 0.85
encodeUint8ArrayFunction · 0.85
encodeStringFunction · 0.85
encodeArrayFunction · 0.85
encodeObjectFunction · 0.85
encodeTagFunction · 0.85
encodeMapFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected