Skip to content

Commit 17c3c3a

Browse files
committed
Fixed map's key type problem.
Any msgpack object can be map's key now. This fix is the same as follows: msgpack#1 The source repository of the pull request seems to be lost, so I created the same fix.
1 parent da6d906 commit 17c3c3a

File tree

2 files changed

+6
-24
lines changed

2 files changed

+6
-24
lines changed

msgpack.codec.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ function encode(rv, // @param ByteArray: result
230230
// inner - decoder
231231
function decode() { // @return Mix:
232232
var size, i, iz, c, num = 0,
233-
sign, exp, frac, ary, hash,
233+
sign, exp, frac, ary, key, hash,
234234
buf = _buf, type = buf[++_idx];
235235

236236
if (type >= 0xe0) { // Negative FixNum (111x xxxx) (-32 ~ -1)
@@ -344,17 +344,8 @@ function decode() { // @return Mix:
344344
case 0x80: hash = {};
345345
while (num--) {
346346
// make key/value pair
347-
size = buf[++_idx] - 0xa0;
348-
349-
for (ary = [], i = _idx, iz = i + size; i < iz; ) {
350-
c = buf[++i]; // lead byte
351-
ary.push(c < 0x80 ? c : // ASCII(0x00 ~ 0x7f)
352-
c < 0xe0 ? ((c & 0x1f) << 6 | (buf[++i] & 0x3f)) :
353-
((c & 0x0f) << 12 | (buf[++i] & 0x3f) << 6
354-
| (buf[++i] & 0x3f)));
355-
}
356-
_idx = i;
357-
hash[_toString.apply(null, ary)] = decode();
347+
key = decode();
348+
hash[key] = decode();
358349
}
359350
return hash;
360351
// 0xdd: array32, 0xdc: array16, 0x90: array

msgpack.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ function encode(rv, // @param ByteArray: result
245245
// inner - decoder
246246
function decode() { // @return Mix:
247247
var size, i, iz, c, num = 0,
248-
sign, exp, frac, ary, hash,
248+
sign, exp, frac, ary, key, hash,
249249
buf = _buf, type = buf[++_idx];
250250

251251
if (type >= 0xe0) { // Negative FixNum (111x xxxx) (-32 ~ -1)
@@ -359,17 +359,8 @@ function decode() { // @return Mix:
359359
case 0x80: hash = {};
360360
while (num--) {
361361
// make key/value pair
362-
size = buf[++_idx] - 0xa0;
363-
364-
for (ary = [], i = _idx, iz = i + size; i < iz; ) {
365-
c = buf[++i]; // lead byte
366-
ary.push(c < 0x80 ? c : // ASCII(0x00 ~ 0x7f)
367-
c < 0xe0 ? ((c & 0x1f) << 6 | (buf[++i] & 0x3f)) :
368-
((c & 0x0f) << 12 | (buf[++i] & 0x3f) << 6
369-
| (buf[++i] & 0x3f)));
370-
}
371-
_idx = i;
372-
hash[_toString.apply(null, ary)] = decode();
362+
key = decode();
363+
hash[key] = decode();
373364
}
374365
return hash;
375366
// 0xdd: array32, 0xdc: array16, 0x90: array

0 commit comments

Comments
 (0)