diff --git a/previews/PR239/.documenter-siteinfo.json b/previews/PR239/.documenter-siteinfo.json index 9ceb50c..3ca034d 100644 --- a/previews/PR239/.documenter-siteinfo.json +++ b/previews/PR239/.documenter-siteinfo.json @@ -1 +1 @@ -{"documenter":{"julia_version":"1.10.5","generation_timestamp":"2024-09-06T02:47:43","documenter_version":"1.7.0"}} \ No newline at end of file +{"documenter":{"julia_version":"1.10.5","generation_timestamp":"2024-09-06T23:45:15","documenter_version":"1.7.0"}} \ No newline at end of file diff --git a/previews/PR239/devnotes/index.html b/previews/PR239/devnotes/index.html index 66720c8..7fc51bc 100644 --- a/previews/PR239/devnotes/index.html +++ b/previews/PR239/devnotes/index.html @@ -3,4 +3,4 @@ user <--- |state.buffer1| <--- <stream.codec> <--- |state.buffer2| <--- stream When writing data (`state.mode == :write`): - user ---> |state.buffer1| ---> <stream.codec> ---> |state.buffer2| ---> stream
In the read mode, a user pull out data from state.buffer1
and pre-transcoded data are filled in state.buffer2
. In the write mode, a user will push data into state.buffer1
and transcoded data are filled in state.buffer2
. The default buffer size is 16KiB for each.
State
(defined in src/state.jl) has five fields:
mode
: current stream mode (<:Symbol
)code
: return code of the last codec's method call (<:Symbol
)error
: exception returned by the codec (<:Error
)buffer1
: data buffer that is closer to the user (<:Buffer
)buffer2
: data buffer that is farther to the user (<:Buffer
)bytes_written_out
: number of bytes written to the underlying stream (<:Int64
)The mode
field may be one of the following value:
:idle
: initial and intermediate mode, no buffered data:read
: being ready to read data, data may be buffered:write
: being ready to write data, data may be buffered:stop
: transcoding is stopped after read, data may be buffered:close
: closed, no buffered data:panic
: an exception has been thrown in codec, data may be buffered but we cannot do anythingNote that mode=:stop
does not mean there is no data available in the stream. This is because transcoded data may be left in the buffer.
The initial mode is :idle
and mode transition happens as shown in the following diagram:
Modes surrounded by a bold circle are a state in which the transcoding stream has released resources by calling finalize(codec)
. The mode transition should happen in the changemode!(stream, newmode)
function in src/stream.jl. Trying an undefined transition will thrown an exception.
A transition happens according to internal or external events of the transcoding stream. The status code and the error object returned by codec methods are internal events, and user's method calls are external events. For example, calling read(stream)
will change the mode from :init
to :read
and then calling close(stream)
will change the mode from :read
to :close
. When data processing fails in the codec, a codec will return :error
and the stream will result in :panic
.
Adjacent transcoding streams may share their buffers. This will reduce memory allocation and eliminate data copy between buffers.
If buffer2
is shared it is considered to be owned by the underlying stream by the stats
and position
functions.
readdata!(input::IO, output::Buffer)
and flush_buffer2(stream::TranscodingStream)
do the actual work of read/write data from/to the underlying stream. These methods have a special pass for shared buffers.
Noop
codecNoop
(NoopStream
) is a codec that does nothing. It works as a buffering layer on top of the underlying stream. Since NoopStream
does not need to have two distinct buffers, buffer1
and buffer2
in the State
object are shared and some specialized methods are defined for the type. All of these are defined in src/noop.jl.
Settings
This document was generated with Documenter.jl version 1.7.0 on Friday 6 September 2024. Using Julia version 1.10.5.