Module | Net::SSH::Util::ReaderBufferImpl |
In: |
lib/net/ssh/util/buffer.rb
|
A convenience module for representing a string of encoded data. It provides an interface for easily reading and decoding the buffer.
position | [R] | the current position of the pointer in the buffer |
Appends the given text to the end of the buffer.
# File lib/net/ssh/util/buffer.rb, line 71 71: def append( text ) 72: @content << text 73: end
Resets the buffer, making it empty.
# File lib/net/ssh/util/buffer.rb, line 142 142: def clear! 143: @content = "" 144: @position = 0 145: end
Returns true if the pointer is at the end of the buffer.
# File lib/net/ssh/util/buffer.rb, line 137 137: def eof? 138: @position >= length 139: end
Reads count bytes from the buffer. If count is nil, this will return all remaining text in the buffer. This method will increment the pointer.
# File lib/net/ssh/util/buffer.rb, line 84 84: def read( count = nil ) 85: count = length - @position unless count 86: return nil if @position + count > length 87: 88: @position += count 89: @content[ @position-count, count ] 90: end
Read a single byte and convert it into a boolean, using ‘C’ rules (i.e., zero is false, non-zero is true).
# File lib/net/ssh/util/buffer.rb, line 126 126: def read_bool 127: b = read( 1 ) or return nil 128: b[0] != 0 129: end
Read and return the next byte in the buffer.
# File lib/net/ssh/util/buffer.rb, line 112 112: def read_byte 113: b = read( 1 ) or return nil 114: b[0] 115: end
Return the next 8 bytes as a 64-bit integer (in network byte order).
# File lib/net/ssh/util/buffer.rb, line 93 93: def read_int64 94: hi = read_long 95: lo = read_long 96: return ( hi << 32 ) + lo 97: end
Return the next four bytes as a long integer (in network byte order).
# File lib/net/ssh/util/buffer.rb, line 100 100: def read_long 101: b = read( 4 ) or return nil 102: b.unpack( "N" ).first 103: end
Read the next two bytes as a short integer (in network byte order).
# File lib/net/ssh/util/buffer.rb, line 106 106: def read_short 107: b = read( 2 ) or return nil 108: b.unpack( "n" ).first 109: end
Read and return an SSH2-encoded string. The string starts with a long integer that describes the number of bytes remaining in the string.
# File lib/net/ssh/util/buffer.rb, line 119 119: def read_string 120: length = read_long or return nil 121: read( length ) 122: end