Unofficial implementation of Borsh serializer https://borsh.io/
Add this line to your application's Gemfile:
gem 'borsh-rb'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install borsh-rb
include Borsh
module and define serialisation schema
class User
include Borsh
borsh id: :string, type: :u8, key: 32, admin: :borsh
def id
'test'
end
def type
1
end
def key
'abcd'
end
admin
return unless admin?
User.new
end
end
Serialize as: User.new.to_borsh
Supported types: :string, :u8, :u16, :u32, :u64, :u128, Integer, Array, :borsh
Integer as a type is supported to validate preserialized value length (for ex. public key)
Bug reports and pull requests are welcome on GitHub at https://github.com/2rba/borsh-rb.
The gem is available as open source under the terms of the MIT License.