mcollina / msgpack5

A msgpack v5 implementation for node.js, with extension points / msgpack.org[Node]
MIT License
492 stars 76 forks source link

Add an option to support predicable encoding #52

Closed hh9527 closed 5 years ago

hh9527 commented 7 years ago
// file: lib/encoder.js:201 function encodeObject
    for (key in obj) {
      if (obj.hasOwnProperty(key) &&
        obj[key] !== undefined &&
        typeof obj[key] !== 'function') {
        ++length
        acc.push(encode(key, true))
        acc.push(encode(obj[key], true))
      }
    }

this will cause the properties order is unpredicable, that will cause some digest mechanism will failed: same value in different case produce different encoded result.

mcollina commented 7 years ago

It follows the same order as JSON.

hh9527 commented 7 years ago

Yes, it follows the order from JSON. but JSON's order is unpredicable. so MsgPack is also unpredicable.

mcollina commented 7 years ago

Send a PR AND i will review it.