@@ -32,39 +32,39 @@ function Base.length(buf::Buffer)
32
32
return length (buf. data)
33
33
end
34
34
35
- function bufferptr (buf)
35
+ function bufferptr (buf:: Buffer )
36
36
return pointer (buf. data, buf. bufferpos)
37
37
end
38
38
39
- function buffersize (buf)
39
+ function buffersize (buf:: Buffer )
40
40
return buf. marginpos - buf. bufferpos
41
41
end
42
42
43
- function buffermem (buf)
43
+ function buffermem (buf:: Buffer )
44
44
return Memory (bufferptr (buf), buffersize (buf))
45
45
end
46
46
47
- function readbyte! (buf)
47
+ function readbyte! (buf:: Buffer )
48
48
b = buf. data[buf. bufferpos]
49
49
buf. bufferpos += 1
50
50
return b
51
51
end
52
52
53
- function writebyte! (buf, b:: UInt8 )
53
+ function writebyte! (buf:: Buffer , b:: UInt8 )
54
54
buf. data[buf. marginpos] = b
55
55
buf. marginpos += 1
56
56
return 1
57
57
end
58
58
59
- function marginptr (buf)
59
+ function marginptr (buf:: Buffer )
60
60
return pointer (buf. data, buf. marginpos)
61
61
end
62
62
63
- function marginsize (buf)
63
+ function marginsize (buf:: Buffer )
64
64
return endof (buf. data) - buf. marginpos + 1
65
65
end
66
66
67
- function marginmem (buf)
67
+ function marginmem (buf:: Buffer )
68
68
return Memory (marginptr (buf), marginsize (buf))
69
69
end
70
70
@@ -91,7 +91,8 @@ function reset!(buf::Buffer)
91
91
end
92
92
93
93
# Make margin with ≥`minsize`.
94
- function makemargin! (buf, minsize:: Int ):: Int
94
+ function makemargin! (buf:: Buffer , minsize:: Integer )
95
+ @assert minsize ≥ 0
95
96
if buffersize (buf) == 0
96
97
if buf. markpos == 0
97
98
buf. bufferpos = buf. marginpos = 1
@@ -120,6 +121,7 @@ function makemargin!(buf, minsize::Int)::Int
120
121
return marginsize (buf)
121
122
end
122
123
124
+ # Remove all buffered data.
123
125
function emptybuffer! (buf:: Buffer )
124
126
buf. marginpos = buf. bufferpos
125
127
return buf
@@ -156,20 +158,22 @@ function readdata!(input::IO, output::Buffer)
156
158
return nread
157
159
end
158
160
161
+ # Read data from `buf` to `dst`.
159
162
function readdata! (buf:: Buffer , dst:: Vector{UInt8} , dpos:: Integer , sz:: Integer )
160
163
copy! (dst, dpos, buf. data, buf. bufferpos, sz)
161
164
buf. bufferpos += sz
162
165
return dst
163
166
end
164
167
165
- # Write as much data as possible to `output` from the buffer of `input`.
168
+ # Write all data to `output` from the buffer of `input`.
166
169
function writebuffer! (output:: IO , input:: Buffer )
167
170
while buffersize (input) > 0
168
171
input. bufferpos += Base. unsafe_write (output, bufferptr (input), buffersize (input))
169
172
end
170
173
end
171
174
172
- function findbyte (buf, byte:: UInt8 )
175
+ # Find the first occurrence of a specific byte.
176
+ function findbyte (buf:: Buffer , byte:: UInt8 )
173
177
ptr = ccall (:memchr , Ptr{Void}, (Ptr{Void}, Cint, Csize_t), pointer (buf. data, buf. bufferpos), byte, buffersize (buf))
174
178
if ptr == C_NULL
175
179
return 0
0 commit comments