Skip to content

Commit 1045061

Browse files
authored
rename state to mode (#19)
1 parent 7d32a4a commit 1045061

File tree

6 files changed

+105
-105
lines changed

6 files changed

+105
-105
lines changed

docs/src/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ Error handling
165165
You may encounter an error while processing data with this package. For example,
166166
your compressed data may be corrupted or truncated and the decompression codec
167167
cannot handle it properly. In this case, the codec informs the stream of the
168-
error and the stream goes to an unrecoverable state. In this state, the only
168+
error and the stream goes to an unrecoverable mode. In this mode, the only
169169
possible operations are `isopen` and `close`. Other operations, such as `read`
170170
or `write`, will result in an argument error exception. Resources allocated in
171171
the codec will be released by the stream and hence you must not call the

src/codec.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ and `startproc` have a default implementation.
2828
Your codec type is denoted by `C` and its object by `codec`.
2929
3030
Errors that occur in these methods are supposed to be unrecoverable and the
31-
stream will go to the panic state. Only `Base.isopen` and `Base.close` are
32-
available in that state.
31+
stream will go to the panic mode. Only `Base.isopen` and `Base.close` are
32+
available in that mode.
3333
3434
### `expectedsize`
3535
@@ -59,20 +59,20 @@ you need to release the memory before throwing an exception.
5959
6060
The `finalize(codec::C)::Void` method takes `codec` and returns `nothing`. This
6161
is called once and only only once just before the transcoding stream goes to the
62-
close state (i.e. when `Base.close` is called) or just after `startproc` or
62+
close mode (i.e. when `Base.close` is called) or just after `startproc` or
6363
`process` throws an exception. Other errors that happen inside the stream (e.g.
6464
`EOFError`) will not call this method. Therefore, you may finalize `codec` (e.g.
6565
freeing memory) with this method. If finalization fails for some reason, it may
6666
throw an exception. You should release the allocated memory in codec before
6767
returning or throwing an exception in `finalize` because otherwise nobody cannot
6868
release the memory. Even when an exception is thrown while finalizing a stream,
69-
the stream will become the close state for safety.
69+
the stream will become the close mode for safety.
7070
7171
### `startproc`
7272
73-
The `startproc(codec::C, state::Symbol, error::Error)::Symbol` method takes
74-
`codec`, `state` and `error`, and returns a status code. This is called just
75-
before the stream starts reading or writing data. `state` is either `:read` or
73+
The `startproc(codec::C, mode::Symbol, error::Error)::Symbol` method takes
74+
`codec`, `mode` and `error`, and returns a status code. This is called just
75+
before the stream starts reading or writing data. `mode` is either `:read` or
7676
`:write` and then the stream starts reading or writing, respectively. The
7777
return code must be `:ok` if `codec` is ready to read or write data. Otherwise,
7878
it must be `:error` and the `error` argument must be set to an exception object.
@@ -146,13 +146,13 @@ function finalize(codec::Codec)::Void
146146
end
147147

148148
"""
149-
startproc(codec::Codec, state::Symbol, error::Error)::Symbol
149+
startproc(codec::Codec, mode::Symbol, error::Error)::Symbol
150150
151-
Start data processing with `codec` of `state`.
151+
Start data processing with `codec` of `mode`.
152152
153153
The default method does nothing and returns `:ok`.
154154
"""
155-
function startproc(codec::Codec, state::Symbol, error::Error)::Symbol
155+
function startproc(codec::Codec, mode::Symbol, error::Error)::Symbol
156156
return :ok
157157
end
158158

src/noop.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function TranscodingStream(codec::Noop, stream::IO; bufsize::Integer=DEFAULT_BUF
3939
end
4040

4141
function Base.unsafe_read(stream::NoopStream, output::Ptr{UInt8}, nbytes::UInt)
42-
changestate!(stream, :read)
42+
changemode!(stream, :read)
4343
buffer = stream.state.buffer1
4444
p = output
4545
p_end = output + nbytes
@@ -62,7 +62,7 @@ function Base.unsafe_read(stream::NoopStream, output::Ptr{UInt8}, nbytes::UInt)
6262
end
6363

6464
function Base.unsafe_write(stream::NoopStream, input::Ptr{UInt8}, nbytes::UInt)
65-
changestate!(stream, :write)
65+
changemode!(stream, :write)
6666
buffer = stream.state.buffer1
6767
if marginsize(buffer) nbytes
6868
unsafe_copy!(marginptr(buffer), input, nbytes)
@@ -89,7 +89,7 @@ end
8989
# buffer for efficiency.
9090

9191
function fillbuffer(stream::NoopStream)
92-
changestate!(stream, :read)
92+
changemode!(stream, :read)
9393
buffer = stream.state.buffer1
9494
@assert buffer === stream.state.buffer2
9595
nfilled::Int = 0
@@ -103,7 +103,7 @@ function fillbuffer(stream::NoopStream)
103103
end
104104

105105
function flushbuffer(stream::NoopStream)
106-
changestate!(stream, :write)
106+
changemode!(stream, :write)
107107
buffer = stream.state.buffer1
108108
@assert buffer === stream.state.buffer2
109109
nflushed::Int = 0
@@ -117,7 +117,7 @@ function flushbuffer(stream::NoopStream)
117117
end
118118

119119
function flushbufferall(stream::NoopStream)
120-
@assert stream.state.state == :write
120+
@assert stream.state.mode == :write
121121
buffer = stream.state.buffer1
122122
bufsize = buffersize(buffer)
123123
while buffersize(buffer) > 0

src/state.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
"""
55
Stream state.
66
7-
A state will be one of the following states:
7+
A state will be one of the following modes:
88
9-
- `:idle` : initial and intermediate state, no buffered data.
9+
- `:idle` : initial and intermediate mode, no buffered data.
1010
- `:read` : ready to read data, data may be buffered.
1111
- `:write`: ready to write data, data may be buffered.
1212
- `:close`: closed, no buffered data.
1313
- `:panic`: an exception has been thrown in codec, data may be buffered but we
1414
cannot do anything.
1515
"""
1616
mutable struct State
17-
# current stream state
18-
state::Symbol
17+
# current stream mode
18+
mode::Symbol
1919

2020
# return code of the last method call (:ok or :end)
2121
code::Symbol

0 commit comments

Comments
 (0)