Class: Borsh::String

Inherits:
Object
  • Object
show all
Defined in:
lib/borsh/string.rb

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ String

Returns a new instance of String.



2
3
4
# File 'lib/borsh/string.rb', line 2

def initialize(value)
  @value = value
end

Instance Method Details

#to_borshObject



6
7
8
9
10
11
# File 'lib/borsh/string.rb', line 6

def to_borsh
  length = [value.length].pack('V')
  raise Borsh::ArgumentError, 'string too long' if length.unpack('V') != [value.length]

  length + value
end