Package org.jdrupes.httpcodec
Interface Encoder<T extends MessageHeader,D extends MessageHeader>
- Type Parameters:
T
- the type of the message header to be encodedD
- the type of the message header decoded by the peer decoder
- All Superinterfaces:
Codec
- All Known Implementing Classes:
HttpEncoder
,HttpRequestEncoder
,HttpResponseEncoder
,WsEncoder
The general interface of an encoder.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.jdrupes.httpcodec.Codec
Codec.ProtocolSwitchResult, Codec.Result
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionencode
(Buffer in, ByteBuffer out, boolean endOfInput) Encodes a message.default Codec.Result
encode
(ByteBuffer out) Convenience method for invokingencode(Buffer, ByteBuffer, boolean)
with an empty in buffer and true.void
Set the header of the message that is to be encoded.encoding()
Returns the type of the messages encoded by this encoder.header()
Returns the last message (header) encoded.setPeerDecoder
(Decoder<D, T> decoder) Sets the peer decoder.
-
Method Details
-
setPeerDecoder
Sets the peer decoder.Some decoder implementations need to know the state of the decoder or the last decoded message.
- Parameters:
decoder
- the decoder- Returns:
- the encoder
-
encoding
Returns the type of the messages encoded by this encoder.- Returns:
- the value
-
encode
Set the header of the message that is to be encoded.Must be invoked before the first invocation to any encode method for a given message.
- Parameters:
messageHeader
- the message header
-
encode
Encodes a message.First encodes the message header set by
encode(MessageHeader)
and then (optionally) adds payload data from in.- Parameters:
in
- the body dataout
- the buffer to which data is writtenendOfInput
- true if there is no input left beyond the data currently in the in buffer (indicates end of body or no body at all)- Returns:
- the result
-
encode
Convenience method for invokingencode(Buffer, ByteBuffer, boolean)
with an empty in buffer and true.Can be used to get the result of encoding a message without body.
- Parameters:
out
- the buffer to which data is written- Returns:
- the result
-
header
Returns the last message (header) encoded.- Returns:
- the result
-