Java Code Examples for org.apache.mina.common.ByteBuffer#prefixedDataAvailable()

The following examples show how to use org.apache.mina.common.ByteBuffer#prefixedDataAvailable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StructDecoder.java    From javastruct with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected boolean doDecode(IoSession session, ByteBuffer in,
		ProtocolDecoderOutput out) throws Exception {
	
	if(in.prefixedDataAvailable(4, MAX_MESSAGE_SIZE)){
		int len = in.getInt();
		int type = in.getInt();
		byte[] b = new byte[len];
		in.get(b);
		StructMessage m = Messages.getMessage(type);
		JavaStruct.unpack(m, b);
		out.write(m);
		return true;
	}
	
	return false;
}