File: ReaderBufferImpl.html

package info (click to toggle)
libnet-ssh-ruby 1%3A1.1.4-1.1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 3,532 kB
  • ctags: 2,464
  • sloc: ruby: 10,876; makefile: 3
file content (389 lines) | stat: -rw-r--r-- 15,993 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>Module: Net::SSH::Util::ReaderBufferImpl</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <link rel="stylesheet" href="../../../.././rdoc-style.css" type="text/css" media="screen" />

    <script language="JavaScript" type="text/javascript">
    // <![CDATA[

        function toggleSource( id )
        {
          var elem
          var link

          if( document.getElementById )
          {
            elem = document.getElementById( id )
            link = document.getElementById( "l_" + id )
          }
          else if ( document.all )
          {
            elem = eval( "document.all." + id )
            link = eval( "document.all.l_" + id )
          }
          else
            return false;

          if( elem.style.display == "block" )
          {
            elem.style.display = "none"
            link.innerHTML = "show source"
          }
          else
          {
            elem.style.display = "block"
            link.innerHTML = "hide source"
          }
        }

        function openCode( url )
        {
          window.open( url, "SOURCE_CODE", "width=400,height=400,scrollbars=yes" )
        }
      // ]]>
    </script>
  </head>

  <body>
  <table width="100%" border='0' cellpadding='0' cellspacing='0' class='banner'><tr>
  <td class="file-title"><span class="file-title-prefix">Module</span><br />Net::SSH::Util::ReaderBufferImpl</td>
  <td align="right">
    <table cellspacing=0 cellpadding=2>
      <tr valign="top">
        <td>In:</td>
        <td>
<a href="../../../../files/lib/net/ssh/util/buffer_rb.html">lib/net/ssh/util/buffer.rb</a>
        </td>
      </tr>
         </table>
        </td>
        </tr>
      </table>
 <!-- banner header -->

  <div id="bodyContent">
      <div id="content">

  <div class="description"><p>
A convenience module for representing a string of encoded data. It provides
an interface for easily reading and decoding the buffer.
</p>
</div>



  <div class="sectiontitle">Methods</div>
  <ul>
  <li><a href="#M000105">append</a></li>
  <li><a href="#M000116">clear!</a></li>
  <li><a href="#M000115">eof?</a></li>
  <li><a href="#M000107">read</a></li>
  <li><a href="#M000113">read_bool</a></li>
  <li><a href="#M000111">read_byte</a></li>
  <li><a href="#M000108">read_int64</a></li>
  <li><a href="#M000109">read_long</a></li>
  <li><a href="#M000110">read_short</a></li>
  <li><a href="#M000112">read_string</a></li>
  <li><a href="#M000106">remainder_as_buffer</a></li>
  <li><a href="#M000114">reset!</a></li>
  </ul>





  <div class="sectiontitle">Attributes</div>
  <table border='0' cellpadding='5'>
  <tr valign='top'>
    <td class='attr-rw'>
[R]
    </td>
    <td class='attr-name'>position</td>
    <td class='attr-desc'>
the current position of the pointer in the buffer

</td>
  </tr>
  </table>

<div class="sectiontitle">Public Instance methods</div>
<div class="method">
  <div class="title">
    <a name="M000105"></a><b>append</b>( text )
  </div>
  <div class="description">
  <p>
Appends the given text to the end of the buffer.
</p>
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000105_source')" id="l_M000105_source">show source</a> ]</p>
  <div id="M000105_source" class="dyn-source">
<pre>
    <span class="ruby-comment cmt"># File lib/net/ssh/util/buffer.rb, line 71</span>
71:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">append</span>( <span class="ruby-identifier">text</span> )
72:           <span class="ruby-ivar">@content</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">text</span>
73:         <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000116"></a><b>clear!</b>()
  </div>
  <div class="description">
  <p>
Resets the buffer, making it empty.
</p>
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000116_source')" id="l_M000116_source">show source</a> ]</p>
  <div id="M000116_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File lib/net/ssh/util/buffer.rb, line 142</span>
142:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">clear!</span>
143:           <span class="ruby-ivar">@content</span> = <span class="ruby-value str">&quot;&quot;</span>
144:           <span class="ruby-ivar">@position</span> = <span class="ruby-value">0</span>
145:         <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000115"></a><b>eof?</b>()
  </div>
  <div class="description">
  <p>
Returns true if the pointer is at the end of the buffer.
</p>
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000115_source')" id="l_M000115_source">show source</a> ]</p>
  <div id="M000115_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File lib/net/ssh/util/buffer.rb, line 137</span>
137:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">eof?</span>
138:           <span class="ruby-ivar">@position</span> <span class="ruby-operator">&gt;=</span> <span class="ruby-identifier">length</span>
139:         <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000107"></a><b>read</b>( count = nil )
  </div>
  <div class="description">
  <p>
Reads <tt>count</tt> bytes from the buffer. If <tt>count</tt> is
<tt>nil</tt>, this will return all remaining text in the buffer. This
method will increment the pointer.
</p>
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000107_source')" id="l_M000107_source">show source</a> ]</p>
  <div id="M000107_source" class="dyn-source">
<pre>
    <span class="ruby-comment cmt"># File lib/net/ssh/util/buffer.rb, line 84</span>
84:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">read</span>( <span class="ruby-identifier">count</span> = <span class="ruby-keyword kw">nil</span> )
85:           <span class="ruby-identifier">count</span> = <span class="ruby-identifier">length</span> <span class="ruby-operator">-</span> <span class="ruby-ivar">@position</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">count</span>
86:           <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@position</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">count</span> <span class="ruby-operator">&gt;</span> <span class="ruby-identifier">length</span>
87: 
88:           <span class="ruby-ivar">@position</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">count</span>
89:           <span class="ruby-ivar">@content</span>[ <span class="ruby-ivar">@position</span><span class="ruby-operator">-</span><span class="ruby-identifier">count</span>, <span class="ruby-identifier">count</span> ]
90:         <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000113"></a><b>read_bool</b>()
  </div>
  <div class="description">
  <p>
Read a single byte and convert it into a boolean, using &#8216;C&#8217;
rules (i.e., zero is false, non-zero is true).
</p>
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000113_source')" id="l_M000113_source">show source</a> ]</p>
  <div id="M000113_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File lib/net/ssh/util/buffer.rb, line 126</span>
126:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">read_bool</span>
127:           <span class="ruby-identifier">b</span> = <span class="ruby-identifier">read</span>( <span class="ruby-value">1</span> ) <span class="ruby-keyword kw">or</span> <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span>
128:           <span class="ruby-identifier">b</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">!=</span> <span class="ruby-value">0</span>
129:         <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000111"></a><b>read_byte</b>()
  </div>
  <div class="description">
  <p>
Read and return the next byte in the buffer.
</p>
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000111_source')" id="l_M000111_source">show source</a> ]</p>
  <div id="M000111_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File lib/net/ssh/util/buffer.rb, line 112</span>
112:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">read_byte</span>
113:           <span class="ruby-identifier">b</span> = <span class="ruby-identifier">read</span>( <span class="ruby-value">1</span> ) <span class="ruby-keyword kw">or</span> <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span>
114:           <span class="ruby-identifier">b</span>[<span class="ruby-value">0</span>]
115:         <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000108"></a><b>read_int64</b>()
  </div>
  <div class="description">
  <p>
Return the next 8 bytes as a 64-bit integer (in network byte order).
</p>
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000108_source')" id="l_M000108_source">show source</a> ]</p>
  <div id="M000108_source" class="dyn-source">
<pre>
    <span class="ruby-comment cmt"># File lib/net/ssh/util/buffer.rb, line 93</span>
93:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">read_int64</span>
94:           <span class="ruby-identifier">hi</span> = <span class="ruby-identifier">read_long</span>
95:           <span class="ruby-identifier">lo</span> = <span class="ruby-identifier">read_long</span>
96:           <span class="ruby-keyword kw">return</span> ( <span class="ruby-identifier">hi</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">32</span> ) <span class="ruby-operator">+</span> <span class="ruby-identifier">lo</span>
97:         <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000109"></a><b>read_long</b>()
  </div>
  <div class="description">
  <p>
Return the next four bytes as a long integer (in network byte order).
</p>
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000109_source')" id="l_M000109_source">show source</a> ]</p>
  <div id="M000109_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File lib/net/ssh/util/buffer.rb, line 100</span>
100:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">read_long</span>
101:           <span class="ruby-identifier">b</span> = <span class="ruby-identifier">read</span>( <span class="ruby-value">4</span> ) <span class="ruby-keyword kw">or</span> <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span>
102:           <span class="ruby-identifier">b</span>.<span class="ruby-identifier">unpack</span>( <span class="ruby-value str">&quot;N&quot;</span> ).<span class="ruby-identifier">first</span>
103:         <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000110"></a><b>read_short</b>()
  </div>
  <div class="description">
  <p>
Read the next two bytes as a short integer (in network byte order).
</p>
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000110_source')" id="l_M000110_source">show source</a> ]</p>
  <div id="M000110_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File lib/net/ssh/util/buffer.rb, line 106</span>
106:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">read_short</span>
107:           <span class="ruby-identifier">b</span> = <span class="ruby-identifier">read</span>( <span class="ruby-value">2</span> ) <span class="ruby-keyword kw">or</span> <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span>
108:           <span class="ruby-identifier">b</span>.<span class="ruby-identifier">unpack</span>( <span class="ruby-value str">&quot;n&quot;</span> ).<span class="ruby-identifier">first</span>
109:         <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000112"></a><b>read_string</b>()
  </div>
  <div class="description">
  <p>
Read and return an SSH2-encoded string. The string starts with a long
integer that describes the number of bytes remaining in the string.
</p>
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000112_source')" id="l_M000112_source">show source</a> ]</p>
  <div id="M000112_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File lib/net/ssh/util/buffer.rb, line 119</span>
119:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">read_string</span>
120:           <span class="ruby-identifier">length</span> = <span class="ruby-identifier">read_long</span> <span class="ruby-keyword kw">or</span> <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span>
121:           <span class="ruby-identifier">read</span>( <span class="ruby-identifier">length</span> )
122:         <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000106"></a><b>remainder_as_buffer</b>()
  </div>
  <div class="description">
  <p>
Returns all text from the current pointer to the end of the buffer as a new
buffer as the same class as the receiver.
</p>
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000106_source')" id="l_M000106_source">show source</a> ]</p>
  <div id="M000106_source" class="dyn-source">
<pre>
    <span class="ruby-comment cmt"># File lib/net/ssh/util/buffer.rb, line 77</span>
77:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">remainder_as_buffer</span>
78:           <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>( <span class="ruby-ivar">@content</span>[ <span class="ruby-ivar">@position</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span> ] )
79:         <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000114"></a><b>reset!</b>()
  </div>
  <div class="description">
  <p>
Resets the pointer to the start of the buffer.
</p>
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000114_source')" id="l_M000114_source">show source</a> ]</p>
  <div id="M000114_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File lib/net/ssh/util/buffer.rb, line 132</span>
132:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">reset!</span>
133:           <span class="ruby-ivar">@position</span> = <span class="ruby-value">0</span>
134:         <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
</div>

  </div>

    </body>
</html>