Class: BinaryCodec::BytesList
- Inherits:
-
Object
- Object
- BinaryCodec::BytesList
- Defined in:
- lib/binary-codec/serdes/bytes_list.rb
Instance Attribute Summary collapse
-
#bytes_array ⇒ Object
readonly
Returns the value of attribute bytes_array.
Instance Method Summary collapse
- #get_length ⇒ Object
-
#initialize ⇒ BytesList
constructor
A new instance of BytesList.
- #put(bytes_arg) ⇒ Object
- #to_byte_sink(list) ⇒ Object
- #to_bytes ⇒ Object
- #to_hex ⇒ Object
Constructor Details
#initialize ⇒ BytesList
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_array ⇒ Object (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_length ⇒ Object
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_bytes ⇒ Object
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_hex ⇒ Object
30 31 32 |
# File 'lib/binary-codec/serdes/bytes_list.rb', line 30 def to_hex bytes_to_hex(to_bytes) end |