File: buffer.rb

package info (click to toggle)
ruby-cbor 0.5.9.8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 424 kB
  • sloc: ansic: 3,437; ruby: 1,732; makefile: 4
file content (193 lines) | stat: -rw-r--r-- 4,960 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
module CBOR

  class Buffer
    #
    # Creates a CBOR::Buffer instance.
    #
    # @overload initialize(options={})
    #   @param options [Hash]
    #
    # @overload initialize(io, options={})
    #   @param io [IO]
    #   @param options [Hash]
    #   This buffer writes written data into the IO when it is filled.
    #   This buffer reads data from the IO when it is empty.
    #
    # _io_ must respond to readpartial(length, [,string]) or read(string) method and
    # write(string) or append(string) method.
    #
    # Supported options:
    #
    # * *:io_buffer_size* buffer size to read data from the internal IO. (default: 32768)
    # * *:read_reference_threshold* the threshold size to enable zero-copy deserialize optimization. Read strings longer than this threshold will refer the original string instead of copying it. (default: 256) (supported in MRI only)
    # * *:write_reference_threshold* the threshold size to enable zero-copy serialize optimization. The buffer refers written strings longer than this threshold instead of copying it. (default: 524288) (supported in MRI only)
    #
    def initialize(*args)
    end

    #
    # Makes the buffer empty
    #
    # @return nil
    #
    def clear
    end

    #
    # Returns byte size of the buffer.
    #
    # @return nil
    #
    def size
    end

    #
    # Returns _true_ if the buffer is empty.
    # This method is slightly faster than _size_.
    #
    # @return [Boolean]
    #
    def empty?
    end

    #
    # Appends the given data to the buffer.
    #
    # @param data [String]
    # @return [Integer] byte size written
    #
    def write(data)
    end

    #
    # Appends the given data to the buffer.
    #
    # @param data [String]
    # @return [Buffer] self
    #
    def <<(data)
    end

    #
    # Consumes _n_ bytes from the head of the buffer and returns consumed data.
    # If the size of the buffer is less than _n_, it reads all of data in the buffer.
    #
    # If _n_ is 0, it does nothing and returns an empty string.
    # If the optional _buffer_ argument is given, the content of the string will be replaced with the consumed data.
    #
    # @overload read
    #
    # @overload read(n)
    #   @param n [Integer] bytes to read
    #
    # @overload read(n, buffer)
    #   @param n [Integer] bytes to read
    #   @param buffer [String] buffer to read into
    #
    # @return [String]
    #
    def read(n)
    end

    #
    # Consumes _n_ bytes from the head of the buffer and returns consumed data.
    # If the size of the buffer is less than _n_, it does nothing and raises EOFError.
    #
    # If _n_ is 0, it does nothing and returns an empty string.
    # If the optional _buffer_ argument is given, the content of the string will be replaced with the consumed data.
    #
    # @overload read_all
    #
    # @overload read_all(n)
    #   @param n [Integer] bytes to read
    #
    # @overload read_all(n, buffer)
    #   @param n [Integer] bytes to read
    #   @param buffer [String] buffer to read into
    #
    # @return [String]
    #
    def read_all(n, buffer=nil)
    end

    #
    # Consumes _n_ bytes from the head of the buffer.
    # If the size of the buffer is less than _n_, it skips all of data in the buffer and returns integer less than _n_.
    #
    # If _n_ is 0, it does nothing and returns _0_.
    #
    # @param n [Integer] byte size to skip
    # @return [Integer] byte size actually skipped
    #
    def skip(n)
    end

    #
    # Consumes _n_ bytes from the head of the buffer.
    # If the size of the buffer is less than _n_, it does nothing and raises EOFError.
    # If _n_ is 0, it does nothing.
    #
    # @param n [Integer] byte size to skip
    # @return [Buffer] self
    #
    def skip_all(n)
    end

    #
    # Returns all data in the buffer as a string.
    # Destructive update to the returned string does NOT effect the buffer.
    #
    # @return [String]
    #
    def to_str
    end

    #
    # Returns content of the buffer as an array of strings.
    #
    # This method is sometimes faster than to_s because the internal
    # structure of the buffer is a queue of buffer chunks.
    #
    # @return [Array] array of strings
    #
    def to_a
    end

    #
    # Internal io
    #
    # @return IO
    #
    attr_reader :io

    #
    # Flushes data in the internal buffer to the internal IO.
    # If internal IO is not set, it does nothing.
    #
    # @return [Buffer] self
    #
    def flush
    end

    #
    # Closes internal IO if its set.
    # If internal IO is not set, it does nothing
    #
    # @return nil
    #
    def close
    end

    #
    # Writes all of data in the internal buffer into the given IO.
    # This method consumes and removes data from the internal buffer.
    # _io_ must respond to write(data) method.
    #
    # @param io [IO]
    # @return [Integer] byte size of written data
    #
    def write_to(io)
    end
  end

end