Class: BinaryCodec::BytesList

Inherits:
Object
  • Object
show all
Defined in:
lib/binary-codec/serdes/bytes_list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBytesList

Returns a new instance of BytesList.



8
9
10
# File 'lib/binary-codec/serdes/bytes_list.rb', line 8

def initialize
  @bytes_array = []
end

Instance Attribute Details

#bytes_arrayObject (readonly)

Returns the value of attribute bytes_array.



6
7
8
# File 'lib/binary-codec/serdes/bytes_list.rb', line 6

def bytes_array
  @bytes_array
end

Instance Method Details

#get_lengthObject



12
13
14
# File 'lib/binary-codec/serdes/bytes_list.rb', line 12

def get_length
  @bytes_array.inject(0) { |sum, arr| sum + arr.length }
end

#put(bytes_arg) ⇒ Object



16
17
18
19
20
# File 'lib/binary-codec/serdes/bytes_list.rb', line 16

def put(bytes_arg)
  bytes = bytes_arg.dup
  @bytes_array << bytes
  self # Allow chaining
end

#to_byte_sink(list) ⇒ Object



22
23
24
# File 'lib/binary-codec/serdes/bytes_list.rb', line 22

def to_byte_sink(list)
  list.put(to_bytes)
end

#to_bytesObject



26
27
28
# File 'lib/binary-codec/serdes/bytes_list.rb', line 26

def to_bytes
  @bytes_array.flatten # TODO: Uses concat in xrpl.js, maybe implement that instead
end

#to_hexObject



30
31
32
# File 'lib/binary-codec/serdes/bytes_list.rb', line 30

def to_hex
  bytes_to_hex(to_bytes)
end