First, do not mix everything together. '$' is a Char, it can be represented by a single byte in most encodings, but this is hardly the case for a common char (in UTF-8, char is encoded variable length and can use 1, 2 or 3 bytes).
It depends on the length of your stream.
1) The easiest solution, if it can fit inside your senderβs memory , is to use a frame with the header of two fields :
- one byte for type (byte or string)
- 2 ( Int16, ) ( ).
, FrameDecoder .
2) , :
- ( - )
- Channel.close(), EndOfStream ( , , ...
Netty StringEncoder StringDecoder . FrameDecoder FrameEncoder .