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 ⇒ Integer
Returns the total length of all bytes in the list.
-
#initialize ⇒ BytesList
constructor
A new instance of BytesList.
-
#put(bytes_arg) ⇒ BytesList
Adds bytes to the list.
-
#to_byte_sink(list) ⇒ Object
Puts the bytes into another byte sink.
-
#to_bytes ⇒ Array<Integer>
Returns all bytes as a single flat array.
-
#to_hex ⇒ String
Returns the hex representation of all bytes in the list.
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 ⇒ Integer
Returns the total length of all bytes in the list.
14 15 16 |
# File 'lib/binary-codec/serdes/bytes_list.rb', line 14 def get_length @bytes_array.inject(0) { |sum, arr| sum + arr.length } end |
#put(bytes_arg) ⇒ BytesList
Adds bytes to the list.
21 22 23 24 25 |
# File 'lib/binary-codec/serdes/bytes_list.rb', line 21 def put(bytes_arg) bytes = bytes_arg.dup @bytes_array << bytes self # Allow chaining end |
#to_byte_sink(list) ⇒ Object
Puts the bytes into another byte sink.
29 30 31 |
# File 'lib/binary-codec/serdes/bytes_list.rb', line 29 def to_byte_sink(list) list.put(to_bytes) end |
#to_bytes ⇒ Array<Integer>
Returns all bytes as a single flat array.
35 36 37 |
# File 'lib/binary-codec/serdes/bytes_list.rb', line 35 def to_bytes @bytes_array.flatten # TODO: Uses concat in xrpl.js, maybe implement that instead end |
#to_hex ⇒ String
Returns the hex representation of all bytes in the list.
41 42 43 |
# File 'lib/binary-codec/serdes/bytes_list.rb', line 41 def to_hex bytes_to_hex(to_bytes) end |