Skip to content

Commit 486c073

Browse files
committed
fix comments
1 parent 9d798eb commit 486c073

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

src/buffer.jl

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,39 +32,39 @@ function Base.length(buf::Buffer)
3232
return length(buf.data)
3333
end
3434

35-
function bufferptr(buf)
35+
function bufferptr(buf::Buffer)
3636
return pointer(buf.data, buf.bufferpos)
3737
end
3838

39-
function buffersize(buf)
39+
function buffersize(buf::Buffer)
4040
return buf.marginpos - buf.bufferpos
4141
end
4242

43-
function buffermem(buf)
43+
function buffermem(buf::Buffer)
4444
return Memory(bufferptr(buf), buffersize(buf))
4545
end
4646

47-
function readbyte!(buf)
47+
function readbyte!(buf::Buffer)
4848
b = buf.data[buf.bufferpos]
4949
buf.bufferpos += 1
5050
return b
5151
end
5252

53-
function writebyte!(buf, b::UInt8)
53+
function writebyte!(buf::Buffer, b::UInt8)
5454
buf.data[buf.marginpos] = b
5555
buf.marginpos += 1
5656
return 1
5757
end
5858

59-
function marginptr(buf)
59+
function marginptr(buf::Buffer)
6060
return pointer(buf.data, buf.marginpos)
6161
end
6262

63-
function marginsize(buf)
63+
function marginsize(buf::Buffer)
6464
return endof(buf.data) - buf.marginpos + 1
6565
end
6666

67-
function marginmem(buf)
67+
function marginmem(buf::Buffer)
6868
return Memory(marginptr(buf), marginsize(buf))
6969
end
7070

@@ -91,7 +91,8 @@ function reset!(buf::Buffer)
9191
end
9292

9393
# Make margin with ≥`minsize`.
94-
function makemargin!(buf, minsize::Int)::Int
94+
function makemargin!(buf::Buffer, minsize::Integer)
95+
@assert minsize 0
9596
if buffersize(buf) == 0
9697
if buf.markpos == 0
9798
buf.bufferpos = buf.marginpos = 1
@@ -120,6 +121,7 @@ function makemargin!(buf, minsize::Int)::Int
120121
return marginsize(buf)
121122
end
122123

124+
# Remove all buffered data.
123125
function emptybuffer!(buf::Buffer)
124126
buf.marginpos = buf.bufferpos
125127
return buf
@@ -156,20 +158,22 @@ function readdata!(input::IO, output::Buffer)
156158
return nread
157159
end
158160

161+
# Read data from `buf` to `dst`.
159162
function readdata!(buf::Buffer, dst::Vector{UInt8}, dpos::Integer, sz::Integer)
160163
copy!(dst, dpos, buf.data, buf.bufferpos, sz)
161164
buf.bufferpos += sz
162165
return dst
163166
end
164167

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`.
166169
function writebuffer!(output::IO, input::Buffer)
167170
while buffersize(input) > 0
168171
input.bufferpos += Base.unsafe_write(output, bufferptr(input), buffersize(input))
169172
end
170173
end
171174

172-
function findbyte(buf, byte::UInt8)
175+
# Find the first occurrence of a specific byte.
176+
function findbyte(buf::Buffer, byte::UInt8)
173177
ptr = ccall(:memchr, Ptr{Void}, (Ptr{Void}, Cint, Csize_t), pointer(buf.data, buf.bufferpos), byte, buffersize(buf))
174178
if ptr == C_NULL
175179
return 0

src/state.jl

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
11
# Transcoding State
22
# =================
33

4-
# Data Layout
5-
# -----------
6-
#
7-
# Buffered data are stored in `data` and two position fields are used to keep
8-
# track of buffered data and margin.
9-
#
10-
# buffered data margin
11-
# |<----------->||<----------->|
12-
# |......XXXXXXXXXXXXXXX..............|
13-
# ^ ^ ^ ^
14-
# 1 bufferpos marginpos endof(data)
15-
#
16-
#
174
# Stream States
185
# -------------
196
#

src/stream.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# Transcoding Stream
22
# ==================
33

4+
# Data Flow
5+
# ---------
6+
#
7+
# When reading data (`state.state == :read`):
8+
# user <--- |state.buffer1| <--- <codec> <--- |state.buffer2| <--- stream
9+
#
10+
# When writing data (`state.state == :write`):
11+
# user ---> |state.buffer1| ---> <codec> ---> |state.buffer2| ---> stream
12+
413
struct TranscodingStream{C<:Codec,S<:IO} <: IO
514
# codec object
615
codec::C

0 commit comments

Comments
 (0)