org.apache.ignite.internal.util.nio

## Interface GridNioParser

All Known Implementing Classes:
  GridBufferedParser, GridDelimitedParser, GridDirectParser, GridTcpRestParser

    public interface GridNioParser

This interface declares a basic contract on message parsing and encoding to the underlying network layer.

Note that methods of this interface are called within NIO threads and should be as fast as possible. If any of methods throw an exception, corresponding session will be closed and listener will be notified with exception passed in as argument.

### Method Summary

Methods
`Object` `decode(GridNioSession ses, ByteBuffer buf)` This method is called when input bytes are available on the underlying network connection.
`ByteBuffer` `encode(GridNioSession ses, Object msg)` This method is called whenever a message should be sent to the network connection and network buffer is ready to be filled with bytes.

### Method Detail

#### decode

    @Nullable
    Object decode(GridNioSession ses,
                         ByteBuffer buf)
                  throws IOException,
                         IgniteCheckedException

This method is called when input bytes are available on the underlying network connection.

Method must read given buffer until either it reaches the end of buffer or a valid user message is encountered. In this case it must return parsed message.

Parameters:
  `ses` - Session on which bytes are read.
  `buf` - Buffer that contains input data.
Returns:
  Parsed user message or `null` if complete message has not been received yet. Note that in case of returning `null` given buffer must be completely read.
Throws:
  `IOException` - If exception occurred while reading data.
  `IgniteCheckedException` - If any user-specific error occurred.

#### encode

    ByteBuffer encode(GridNioSession ses,
                    Object msg)
                      throws IOException,
                             IgniteCheckedException

This method is called whenever a message should be sent to the network connection and network buffer is ready to be filled with bytes.

Method must encode the complete message and return byte buffer from which data should be read.

Parameters:
  `ses` - Session on which message is being sent.
  `msg` - Message to encode.
Returns:
  Buffer containing encoded message.
Throws:
  `IOException` - If exception occurred while encoding data.
  `IgniteCheckedException` - If any user-specific error occurred while encoding data.

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.3.0-incubating
Release Date | : July 10 2015