Skip to content

Immediate re-encoding of a decoded value adds extra bytes #52

Answered by kriszyp
MasterKale asked this question in Q&A
Discussion options

You must be logged in to vote

This maintains 77 bytes for me:

const encoder = new cborx.Encoder({ mapsAsObjects: false })
const decoded = encoder.decode(publicKey);
const reEncoded = encoder.encode(decoded);

console.log('Re-encoded bytes length:', reEncoded.length); // 77

Does that work for you?

(the reason for this is that JavaScript objects do not preserve the type of the keys and so the keys were getting converted to strings when deserialized as objects, whereas Maps preserve the number type of the keys)

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@MasterKale
Comment options

@MasterKale
Comment options

@kriszyp
Comment options

@MasterKale
Comment options

Answer selected by MasterKale
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants