near / borsh

Binary Object Representation Serializer for Hashing

Home Page:https://borsh.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Big endian encoding attribute

delbonis opened this issue · comments

For network protocols, there is an established convention to encode integers as big endian. Borsh isn't designed specifically for network protocols, but with its compactness and its other nice properties, it's also fairly well-suited for defining network protocols.

Implementation wise, after reasoning through a few different stragies, I believe it would make the most sense to implement this by defining an attribute that can be defined on a struct or a field that has a #[derive(BorshSerialize, BorshDeserialize)] to indicate the integer encoding policy just for integers in that scope. This is fairly backwards compatible and allows types with little endian integers to be used interchangeably mixed in with types that use big endian ones.