Skip to content

Commit 9c9d94a

Browse files
committed
rename ReadMode to Read and WriteMode to Write
1 parent 82f686d commit 9c9d94a

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

src/codec.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
abstract type Codec end
55

66
abstract type Mode end
7-
struct ReadMode <: Mode end
8-
struct WriteMode <: Mode end
7+
struct Read <: Mode end
8+
struct Write <: Mode end
99

1010
primitive type ProcCode 8 end
1111
const PROC_INIT = reinterpret(ProcCode, 0x00)
@@ -17,28 +17,28 @@ const PROC_FINISH = reinterpret(ProcCode, 0x02)
1717
# -----
1818

1919
"""
20-
start(::Type{ReadMode}, codec::Codec, source::IO)::Void
20+
start(::Type{Read}, codec::Codec, source::IO)::Void
2121
2222
Start transcoding using `codec` with read mode.
2323
2424
This method will be called only once before calling `process` first time.
2525
2626
Implementing this method is optional; there is a default method that does nothing.
2727
"""
28-
function start(::Type{ReadMode}, ::Codec, ::IO)
28+
function start(::Type{Read}, ::Codec, ::IO)
2929
return nothing
3030
end
3131

3232
"""
33-
start(::Type{WriteMode}, codec::Codec, sink::IO)::Void
33+
start(::Type{Write}, codec::Codec, sink::IO)::Void
3434
3535
Start transcoding using `codec` with write mode.
3636
3737
This method will be called only once before calling `process` first time.
3838
3939
Implementing this method is optional; there is a default method that does nothing.
4040
"""
41-
function start(::Type{WriteMode}, ::Codec, ::IO)
41+
function start(::Type{Write}, ::Codec, ::IO)
4242
return nothing
4343
end
4444

@@ -47,7 +47,7 @@ end
4747
# -------
4848

4949
"""
50-
process(::Type{ReadMode}, codec::Codec, source::IO, output::Ptr{UInt8}, nbytes::Int)::Tuple{Int,ProcCode}
50+
process(::Type{Read}, codec::Codec, source::IO, output::Ptr{UInt8}, nbytes::Int)::Tuple{Int,ProcCode}
5151
5252
Transcode data using `codec` with read mode.
5353
@@ -72,12 +72,12 @@ malfomed data from `source`. However, this method must not throw `EOFError`
7272
when reading data from `source`. Also note that it is responsible for this
7373
method to release resources allocated by `codec` when an exception happens.
7474
"""
75-
function process(::Type{ReadMode}, codec::Codec, stream::IO, data::Ptr{UInt8}, nbytes::Int)
75+
function process(::Type{Read}, codec::Codec, stream::IO, data::Ptr{UInt8}, nbytes::Int)
7676
error("codec $(codec) does not implement read mode")
7777
end
7878

7979
"""
80-
process(::Type{WriteMode}, codec::Codec, sink::IO, input::Ptr{UInt8}, nbytes::Int)::Tuple{Int,ProcCode}
80+
process(::Type{Write}, codec::Codec, sink::IO, input::Ptr{UInt8}, nbytes::Int)::Tuple{Int,ProcCode}
8181
8282
Transcode data using `codec` with write mode.
8383
@@ -86,7 +86,7 @@ Transcode data using `codec` with write mode.
8686
8787
This method reads some data from `input` and write the transcoded bytes to `sink`.
8888
"""
89-
function process(::Type{WriteMode}, codec::Codec, stream::IO, data::Ptr{UInt8}, nbytes::Int)
89+
function process(::Type{Write}, codec::Codec, stream::IO, data::Ptr{UInt8}, nbytes::Int)
9090
error("codec $(codec) does not implement write mode")
9191
end
9292

@@ -95,27 +95,27 @@ end
9595
# ------
9696

9797
"""
98-
finish(::Type{ReadMode}, codec::Codec, source::IO)::Void
98+
finish(::Type{Read}, codec::Codec, source::IO)::Void
9999
100100
Finish transcoding using `codec` with read mode.
101101
102102
This method will be called only once after calling `process` last time.
103103
104104
Implementing this method is optional; there is a default method that does nothing.
105105
"""
106-
function finish(::Type{ReadMode}, ::Codec, ::IO)
106+
function finish(::Type{Read}, ::Codec, ::IO)
107107
return nothing
108108
end
109109

110110
"""
111-
finish(::Type{WriteMode}, codec::Codec, sink::IO)::Void
111+
finish(::Type{Write}, codec::Codec, sink::IO)::Void
112112
113113
Finish transcoding using `codec` with write mode.
114114
115115
This method will be called only once after calling `process` last time.
116116
117117
Implementing this method is optional; there is a default method that does nothing.
118118
"""
119-
function finish(::Type{WriteMode}, ::Codec, ::IO)
119+
function finish(::Type{Write}, ::Codec, ::IO)
120120
return nothing
121121
end

src/identity.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
struct Identity <: Codec end
55

6-
function process(::Type{ReadMode}, ::Identity, stream::IO, data::Ptr{UInt8}, nbytes::Int)::Tuple{Int,ProcCode}
6+
function process(::Type{Read}, ::Identity, stream::IO, data::Ptr{UInt8}, nbytes::Int)::Tuple{Int,ProcCode}
77
n = unsafe_read(stream, data, nbytes)
88
if eof(stream)
99
return n, PROC_FINISH
@@ -12,7 +12,7 @@ function process(::Type{ReadMode}, ::Identity, stream::IO, data::Ptr{UInt8}, nby
1212
end
1313
end
1414

15-
function process(::Type{WriteMode}, ::Identity, stream::IO, data::Ptr{UInt8}, nbytes::Int)::Tuple{Int,ProcCode}
15+
function process(::Type{Write}, ::Identity, stream::IO, data::Ptr{UInt8}, nbytes::Int)::Tuple{Int,ProcCode}
1616
n = unsafe_write(stream, data, nbytes)
1717
return Int(n), PROC_OK
1818
end

src/stream.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ function Base.close(stream::TranscodingStream)
5252
# pass
5353
elseif state.mode == :read
5454
flushbuffer(stream)
55-
finish(ReadMode, stream.codec, stream.stream)
55+
finish(Read, stream.codec, stream.stream)
5656
elseif state.mode == :write
5757
flushbuffer(stream)
58-
finish(WriteMode, stream.codec, stream.stream)
58+
finish(Write, stream.codec, stream.stream)
5959
elseif state.mode == :closed
6060
# pass
6161
else
@@ -154,7 +154,7 @@ function fillbuffer(stream::TranscodingStream)::Int
154154
nfilled = 0
155155
makemargin!(state, 1)
156156
while !isfullbuf(state) && state.proc != PROC_FINISH
157-
n, code = process(ReadMode, stream.codec, stream.stream, marginptr(state), marginsize(state))
157+
n, code = process(Read, stream.codec, stream.stream, marginptr(state), marginsize(state))
158158
state.fposition += n
159159
state.proc = code
160160
nfilled += n
@@ -169,7 +169,7 @@ function flushbuffer(stream::TranscodingStream)::Int
169169
end
170170
nflushed = 0
171171
while !isemptybuf(state)
172-
n, code = process(WriteMode, stream.codec, stream.stream, bufferptr(state), buffersize(state))
172+
n, code = process(Write, stream.codec, stream.stream, bufferptr(state), buffersize(state))
173173
state.position += n
174174
state.proc = code
175175
nflushed += n
@@ -191,18 +191,18 @@ function prepare(stream::TranscodingStream, mode::Symbol)
191191
flushbuffer(stream)
192192
if state.mode == :init
193193
elseif state.mode == :read
194-
finish(ReadMode, stream.codec, stream.stream)
194+
finish(Read, stream.codec, stream.stream)
195195
elseif state.mode == :write
196-
finish(WriteMode, stream.codec, stream.stream)
196+
finish(Write, stream.codec, stream.stream)
197197
else
198198
assert(false)
199199
end
200200

201201
# start
202202
if mode == :read
203-
start(ReadMode, stream.codec, stream.stream)
203+
start(Read, stream.codec, stream.stream)
204204
elseif mode == :write
205-
start(WriteMode, stream.codec, stream.stream)
205+
start(Write, stream.codec, stream.stream)
206206
else
207207
assert(false)
208208
end

0 commit comments

Comments
 (0)