10000 support numeric keys · arduino/cbor-js@c7b941b · GitHub
[go: up one dir, main page]

Skip to content

Commit c7b941b

Browse files
author
Stefania
committed
support numeric keys
1 parent a75e168 commit c7b941b

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

cbor.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const POW_2_32 = 4294967296;
2828
const POW_2_53 = 9007199254740992;
2929
const DECODE_CHUNK_SIZE = 8192;
3030

31-
function encode(value) {
31+
function encode(value, numericKeys) {
3232
var data = new ArrayBuffer(256);
3333
var dataView = new DataView(data);
3434
var byteView = new Uint8Array(data);
@@ -166,6 +166,9 @@ function encode(value) {
166166
writeTypeAndLength(5, length);
167167
for (i = 0; i < length; ++i) {
168168
var key = keys[i];
169+
if (numericKeys) {
170+
key = parseInt(key);
171+
}
169172
encodeItem(key);
170173
encodeItem(value[key]);
171174
}

0 commit comments

Comments
 (0)
0