org.apache.ignite.internal.processors.rest.protocols.tcp

## Class GridTcpRestParser

- java.lang.Object
- - org.apache.ignite.internal.processors.rest.protocols.tcp.GridTcpRestParser

All Implemented Interfaces:
  GridNioParser

    public class GridTcpRestParser
    extends Object
    implements GridNioParser

Parser for extended memcache protocol. Handles parsing and encoding activity.

### Nested Class Summary

Nested Classes
`protected static class` `GridTcpRestParser.HeaderData` Header.
`protected static class` `GridTcpRestParser.ParserState` Holder for parser state and temporary buffer.

### Constructor Summary

Constructors
Constructor and Description
`GridTcpRestParser(boolean routerClient)`

### Method Summary

Methods
`GridClientMessage` `decode(GridNioSession ses, ByteBuffer buf)` This method is called when input bytes are available on the underlying network connection.
`ByteBuffer` `encode(GridNioSession ses, Object msg0)` This method is called whenever a message should be sent to the network connection and network buffer is ready to be filled with bytes.
`protected GridClientMarshaller` `marshaller(GridNioSession ses)` Returns marshaller.
`protected GridClientMessage` `parseClientMessage(GridNioSession ses, GridTcpRestParser.ParserState state)` Parses `GridClientMessage` from raw bytes.
`String` `toString()`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Constructor Detail

#### GridTcpRestParser

    public GridTcpRestParser(boolean routerClient)

Parameters:
  `routerClient` - Router client flag.

### Method Detail

#### decode

    @Nullable
    public GridClientMessage 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.

Specified by:
  `decode` in interface `GridNioParser`
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

    public ByteBuffer encode(GridNioSession ses,
                    Object msg0)
                      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.

Specified by:
  `encode` in interface `GridNioParser`
Parameters:
  `ses` - Session on which message is being sent.
  `msg0` - 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.

#### parseClientMessage

    protected GridClientMessage parseClientMessage(GridNioSession ses,
                                       GridTcpRestParser.ParserState state)
                                            throws IOException,
                                                   IgniteCheckedException

Parses `GridClientMessage` from raw bytes.

Parameters:
  `ses` - Session.
  `state` - Parser state.
Returns:
  A parsed client message.
Throws:
  `IOException` - On marshaller error.
  `IgniteCheckedException` - If no marshaller was defined for the session.

#### marshaller

    protected GridClientMarshaller marshaller(GridNioSession ses)

Returns marshaller.

Returns:
  Marshaller.

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.0.0
Release Date | : March 31 2015