Class: Trezor::Utils::Buffer
- Inherits:
-
Net::SSH::Buffer
- Object
- Net::SSH::Buffer
- Trezor::Utils::Buffer
- Defined in:
- lib/trezor/utils/buffer.rb
Instance Method Summary collapse
-
#read_short ⇒ Object
Return the next two bytes as a short integer (in network byte order).
-
#write_bth(*blobs) ⇒ Object
Writes each argument to the buffer as hex data (binary to hex) Does not alter the read position.
-
#write_htb(*blobs) ⇒ Object
Writes each argument to the buffer as binary data (hex to binary) Does not alter the read position.
-
#write_short(*n) ⇒ Object
Writes each argument to the buffer as a network-byte-order-encoded short (2-byte) integer.
Instance Method Details
#read_short ⇒ Object
Return the next two bytes as a short integer (in network byte order). Returns nil if there are less than 2 bytes remaining to be read in the buffer.
17 18 19 20 |
# File 'lib/trezor/utils/buffer.rb', line 17 def read_short b = read(2) or return nil b.unpack('n').first end |
#write_bth(*blobs) ⇒ Object
Writes each argument to the buffer as hex data (binary to hex) Does not alter the read position. Returns the buffer object.
33 34 35 36 |
# File 'lib/trezor/utils/buffer.rb', line 33 def write_bth(*blobs) blobs.each { |b| @content << b.unpack('H*').first } self end |
#write_htb(*blobs) ⇒ Object
Writes each argument to the buffer as binary data (hex to binary) Does not alter the read position. Returns the buffer object.
25 26 27 28 |
# File 'lib/trezor/utils/buffer.rb', line 25 def write_htb(*blobs) @content << blobs.pack('H*') self end |
#write_short(*n) ⇒ Object
Writes each argument to the buffer as a network-byte-order-encoded short (2-byte) integer. Does not alter the read position. Returns the buffer object.
9 10 11 12 |
# File 'lib/trezor/utils/buffer.rb', line 9 def write_short(*n) @content << n.pack('n*') self end |