dao-xyz / borsh-ts

⚡️fast TypeScript implementation of Borsh serialization format
Apache License 2.0
37 stars 2 forks source link

Type consistency discussion #23

Open hanakannzashi opened 1 year ago

hanakannzashi commented 1 year ago

Should we avoid inconsistent serialization? For example, if a field type is number, and we mark its borsh type is u64, currently the serialization will success, but should we throw an error here? because when we deserialize, constructed type will be bigint, they are inconsistent, and may cause unexpected behavior.

This also refers to

marcus-pousette commented 1 year ago

Yeap, I agree with you, there are a few inconsistencies regarding serialization. Initially the idea was to have relaxed constraints (limited type checking) to make this library one of the fastest serialization libraries in js.

There is now an "unchecked" flag one can pass to make it even more relaxed. But, this is kind of in the other direction. Perhaps another flag would be necessary, or an enum

serialize(x, { validation: 'none' |  'strict' | 'normal' })