Skip to content

Commit afe4f62

Browse files
committed
tweaks
1 parent 9a40747 commit afe4f62

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/Encoder.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,18 @@ export class Encoder {
220220
}
221221
}
222222

223-
encodeMap(object: Record<string, unknown>, depth: number) {
224-
let size = 0;
223+
countObjectKeys(object: Record<string, unknown>): number {
224+
let count = 0;
225225
for (const key in object) {
226226
if (Object.prototype.hasOwnProperty.call(object, key)) {
227-
size++;
227+
count++;
228228
}
229229
}
230-
// map
230+
return count;
231+
}
232+
233+
encodeMap(object: Record<string, unknown>, depth: number) {
234+
const size = this.countObjectKeys(object);
231235
if (size < 16) {
232236
// fixmap
233237
this.writeU8(0x80 + size);

0 commit comments

Comments
 (0)