You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
v8.serialize produce different output, still decodable but it's different bytes, and different length. it's matter for me.
same PC, same version.
just want to know: what cause that difference and how to avoid it.
constv8=require('v8');letdata={key: 'value',arrValue: [1,2,3,4],objValue: {nestedKey: 'value'}};constbuffData=v8.serialize(data);constdataCopy=v8.deserialize(buffData);// it seems we still have same objectconsole.log(JSON.stringify(dataCopy)===JSON.stringify(data));// but encoded buffer is different!constbuffEncoded=v8.serialize(Object.assign({},dataCopy));console.log(buffData.length!==buffEncoded.length);console.log(buffData.toString('hex'));console.log(buffEncoded.toString('hex'));
V8 uses different internal representations for some values, for example, Arrays in V8 can be dense or sparse, with special cases for integer arrays or floating-point-value arrays, and strings can have different internal representations as well, e.g. using UTF16 encoding or using ISO-8859-1.
Generally, you can’t rely on the exact output from v8.serialize(), that’s correct. If it’s important to you to have deterministic output, it might not be the right tool for you.
V8 uses different internal representations for some values, for example, Arrays in V8 can be dense or sparse, with special cases for integer arrays or floating-point-value arrays, and strings can have different internal representations as well, e.g. using UTF16 encoding or using ISO-8859-1.
it's ok, but i didn't expect diffrent output for "same" values.
Activity
trueshura commentedon Jan 28, 2020
If you remove array element - it works like a charm again!
i mean
encodes as expected
addaleax commentedon Jan 28, 2020
V8 uses different internal representations for some values, for example,
Arrays in V8 can be dense or sparse, with special cases for integer arrays or floating-point-value arrays, and strings can have different internal representations as well, e.g. using UTF16 encoding or using ISO-8859-1.Generally, you can’t rely on the exact output from
v8.serialize(), that’s correct. If it’s important to you to have deterministic output, it might not be the right tool for you.trueshura commentedon Jan 28, 2020
it's ok, but i didn't expect diffrent output for "same" values.
doc: clarify that `v8.serialize()` is not deterministic
doc: clarify that `v8.serialize()` is not deterministic
doc: clarify that `v8.serialize()` is not deterministic
doc: clarify that `v8.serialize()` is not deterministic
doc: clarify that `v8.serialize()` is not deterministic
doc: clarify that `v8.serialize()` is not deterministic