Skip to content

Commit 3c15dad

Browse files
committed
updated documents
1 parent a4e05b3 commit 3c15dad

3 files changed

Lines changed: 40 additions & 20 deletions

File tree

doclib/msgpack/buffer.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,19 @@ def empty?
3737
# Appends the given data to the buffer.
3838
#
3939
# @param data [String]
40-
# @return [Buffer] self
40+
# @return [Integer] byte size written
4141
#
42-
def append(data)
42+
def write(data)
4343
end
4444

45-
alias << append
45+
#
46+
# Appends the given data to the buffer.
47+
#
48+
# @param data [String]
49+
# @return [Buffer] self
50+
#
51+
def <<(data)
52+
end
4653

4754
# Consumes _n_ bytes from the head of the buffer and returns consumed data.
4855
# If the size of the buffer is less than _n_, it reads all of data in the buffer.
@@ -87,7 +94,6 @@ def read_all
8794

8895
#
8996
# Consumes _n_ bytes from the head of the buffer.
90-
#
9197
# If the size of the buffer is less than _n_, it skips all of data in the buffer and returns integer less than _n_.
9298
#
9399
# If _n_ is 0, it does nothing and returns _0_.

doclib/msgpack/unpacker.rb

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,25 @@ class Unpacker
1616
# @param io [IO]
1717
# @param options [Hash]
1818
# This unpacker reads data from the _io_ to fill the internal buffer.
19-
# _io_ must respond to readpartial(length,string) or read(length,string) method.
19+
# _io_ must respond to readpartial(length[,string]) or read(length[,string]) method.
2020
#
2121
def initialize(*args)
2222
end
2323

2424
#
2525
# Internal buffer
2626
#
27-
# @return MessagePack::Unpacker
27+
# @return [MessagePack::Unpacker]
2828
#
2929
attr_reader :buffer
3030

3131
#
3232
# Deserializes an object from internal buffer and returns it.
3333
#
34+
# If there're not enough buffer, this method raises EOFError.
35+
# If data format is invalid, this method raises MessagePack::MalformedFormatError.
36+
# If the stack is too deep, this method raises MessagePack::StackError.
37+
#
3438
# @return [Object] deserialized object
3539
#
3640
def read
@@ -41,25 +45,31 @@ def read
4145
#
4246
# Deserializes an object and ignores it. This method is faster than _read_.
4347
#
48+
# This method could raise same errors with _read_.
49+
#
4450
# @return nil
4551
#
4652
def skip
4753
end
4854

4955
#
5056
# Deserializes a nil value if it exists and returns _true_.
51-
# Otherwise, if a byte exists but the byte is not nil value or the internal buffer is empty, returns _false_.
57+
# Otherwise, if a byte exists but the byte doesn't represent nil value,
58+
# returns _false_.
59+
#
60+
# If there're not enough buffer, this method raises EOFError.
5261
#
5362
# @return [Boolean]
5463
#
55-
def skip
64+
def skip_nil
5665
end
5766

5867
#
5968
# Read a header of an array and returns its size.
6069
# It converts a serialized array into a stream of elements.
6170
#
6271
# If the serialized object is not an array, it raises MessagePack::TypeError.
72+
# If there're not enough buffer, this method raises EOFError.
6373
#
6474
# @return [Integer] size of the array
6575
#
@@ -71,6 +81,7 @@ def read_array_header
7181
# It converts a serialized map into a stream of key-value pairs.
7282
#
7383
# If the serialized object is not a map, it raises MessagePack::TypeError.
84+
# If there're not enough buffer, this method raises EOFError.
7485
#
7586
# @return [Integer] size of the map
7687
#
@@ -82,6 +93,7 @@ def read_map_header
8293
# This method calls buffer.append(data).
8394
#
8495
# @param data [String]
96+
# @return [Unpacker] self
8597
#
8698
def feed(data)
8799
end
@@ -91,8 +103,10 @@ def feed(data)
91103
#
92104
# It repeats until the internal buffer does not include any complete objects.
93105
#
94-
# If the internal IO was set, it reads data from the IO when the buffer becomes empty,
95-
# and returns when the IO raised EOFError.
106+
# If the an IO is set, it repeats to read data from the IO when the buffer
107+
# becomes empty until the IO raises EOFError.
108+
#
109+
# This method could raise same errors with _read_ excepting EOFError.
96110
#
97111
# @yieldparam object [Object] deserialized object
98112
# @return nil

spec/buffer_spec.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,11 @@
180180
}
181181
end
182182

183-
it 'short append increments size' do
183+
it 'short write increments size' do
184184
case_keys.each {|k|
185185
sz = examples[k].size
186186
10.times do |i|
187-
cases[k].append 'short'
187+
cases[k].write 'short'
188188
sz += 'short'.size
189189
cases[k].size.should == sz
190190
end
@@ -320,28 +320,28 @@
320320
}
321321
end
322322

323-
it 'big append and modify reference' do
323+
it 'big write and modify reference' do
324324
big2 = "a" * (1024*1024 + 2)
325325

326326
case_keys.each {|k|
327327
big1 = "a" * (1024*1024 + 2)
328-
cases[k].append(big1)
328+
cases[k].write(big1)
329329
big1 << 'x'
330330
cases[k].read.should == examples[k] + big2
331331
}
332332
end
333333

334-
it 'big append -> short append' do
334+
it 'big write -> short write' do
335335
biglen = 1024*1024 + 2
336336
big1 = "a" * (1024*1024 + 2)
337337

338338
case_keys.each {|k|
339339
sz = examples[k].size
340340

341-
cases[k].append big1
341+
cases[k].write big1
342342
cases[k].size.should == sz + big1.size
343343

344-
cases[k].append("c")
344+
cases[k].write("c")
345345
cases[k].size.should == sz + big1.size + 1
346346

347347
cases[k].read_all.should == examples[k] + big1 + "c"
@@ -350,15 +350,15 @@
350350
}
351351
end
352352

353-
it 'big append 2'do
353+
it 'big write 2'do
354354
big1 = "a" * (1024*1024 + 2)
355355
big2 = "b" * (1024*1024 + 2)
356356

357357
case_keys.each {|k|
358358
sz = examples[k].size
359359

360-
cases[k].append big1
361-
cases[k].append big2
360+
cases[k].write big1
361+
cases[k].write big2
362362
cases[k].size.should == sz + big1.size + big2.size
363363

364364
cases[k].read_all(sz + big1.size).should == examples[k] + big1

0 commit comments

Comments
 (0)