A convenience module for representing a string of encoded data. It provides an interface for easily reading and decoding the buffer.

Methods
Attributes
[R] position the current position of the pointer in the buffer
Public Instance methods
append( text )

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
clear!()

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
eof?()

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
read( count = nil )

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_bool()

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_byte()

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
read_int64()

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
read_long()

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_short()

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_string()

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
remainder_as_buffer()

Returns all text from the current pointer to the end of the buffer as a new buffer as the same class as the receiver.

    # File lib/net/ssh/util/buffer.rb, line 77
77:         def remainder_as_buffer
78:           self.class.new( @content[ @position..-1 ] )
79:         end
reset!()

Resets the pointer to the start of the buffer.

     # File lib/net/ssh/util/buffer.rb, line 132
132:         def reset!
133:           @position = 0
134:         end