This file is part of Niowire.
Niowire is free software: you can redistribute it and/or modify it under the
terms of the Lesser GNU General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option) any
Niowire is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the Lesser GNU General Public License for more
You should have received a copy of the Lesser GNU General Public License
along with Niowire. If not, see <http://www.gnu.org/licenses/>.
This class is the most basic serializer. It scans the input stream for a
particular byte (or set of bytes) and removes them from the stream, and uses
all the data up to that point as it's data. This class may be overridden and
the serializeBlob() method can be used to take the delimited output to be
Note that this class as it uses a static byte buffer for its operations, is
not thread safe across instances. Only one instance of this class can be
performing operations at any one time. In the context of Niowire as there is
one main thread doing all of the IO this should not be a problem. But if it
is going to be used elsewhere this must be considered.
- Trent Houliston
This is the static byte buffer shared between all instances of the
private boolean open = true;
tb.position(startPoint - delimiter.length < 0 ? 0 : startPoint - delimiter.length);
if (delimiter[depth] == b)
if (depth == delimiter.length)
LOG.warn("There was a packet of invalid data sent to the deserializer");
LOG.warn("There was a packet of invalid data sent to the serializer");
This method is used to deserialize a blob of data after we have found our
delimiter. It passes a byte buffer with its position and limit set to the
data of interest.
with its position and limit set to our
point of interest.
- a list of packets which were found in that delimited blob
NioInvalidDataException if the given data was invalid
This method is used to convert a NioPacket object into a serialized byte
buffer form. It should accept a packet and convert it into a ByteBuffer
containing the data to be sent to the client. When sent to the client a
delimiter will be added after this ByteBuffers content.
This method should return the multi byte delimiter to use when delimiting
the incoming data. It should not change as it may miss packets in this
- a multi byte delimiter to search and use to split up the incoming