me.cmoz.grizzly.protobuf
Class FixedLengthProtobufDecoder

java.lang.Object
  extended by org.glassfish.grizzly.AbstractTransformer<org.glassfish.grizzly.Buffer,com.google.protobuf.MessageLite>
      extended by me.cmoz.grizzly.protobuf.FixedLengthProtobufDecoder
All Implemented Interfaces:
org.glassfish.grizzly.Transformer<org.glassfish.grizzly.Buffer,com.google.protobuf.MessageLite>

public class FixedLengthProtobufDecoder
extends org.glassfish.grizzly.AbstractTransformer<org.glassfish.grizzly.Buffer,com.google.protobuf.MessageLite>

Decodes Protocol Buffers messages from the input stream using a fixed header to determine the size of a message.


Nested Class Summary
 
Nested classes/interfaces inherited from class org.glassfish.grizzly.AbstractTransformer
org.glassfish.grizzly.AbstractTransformer.LastResultAwareState<K,L>
 
Field Summary
static int IO_HEADER_ENCODING_ERROR
          The error code for a malformed header.
static int IO_PROTOBUF_PARSE_ERROR
          The error code for a failed protobuf parse of a message.
static java.lang.String MESSAGE_LENGTH_ATTR
          The name of the decoder attribute for the size of the message.
 
Fields inherited from class org.glassfish.grizzly.AbstractTransformer
attributeBuilder, stateAttr
 
Constructor Summary
FixedLengthProtobufDecoder(com.google.protobuf.MessageLite prototype, com.google.protobuf.ExtensionRegistryLite extensionRegistry, int headerLength)
          A protobuf decoder that uses the supplied headerLength to determine the size of the message to be decoded.
 
Method Summary
 java.lang.String getName()
          
 boolean hasInputRemaining(org.glassfish.grizzly.attributes.AttributeStorage storage, org.glassfish.grizzly.Buffer input)
          
 int readHeader(org.glassfish.grizzly.Buffer input)
          Reads the header from the supplied input.
protected  org.glassfish.grizzly.TransformationResult<org.glassfish.grizzly.Buffer,com.google.protobuf.MessageLite> transformImpl(org.glassfish.grizzly.attributes.AttributeStorage storage, org.glassfish.grizzly.Buffer input)
          
 
Methods inherited from class org.glassfish.grizzly.AbstractTransformer
createStateObject, getLastResult, getMemoryManager, getNamePrefix, getValue, obtainMemoryManager, obtainStateObject, release, saveLastResult, setMemoryManager, transform
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IO_PROTOBUF_PARSE_ERROR

public static final int IO_PROTOBUF_PARSE_ERROR
The error code for a failed protobuf parse of a message.

See Also:
Constant Field Values

IO_HEADER_ENCODING_ERROR

public static final int IO_HEADER_ENCODING_ERROR
The error code for a malformed header.

See Also:
Constant Field Values

MESSAGE_LENGTH_ATTR

public static final java.lang.String MESSAGE_LENGTH_ATTR
The name of the decoder attribute for the size of the message.

See Also:
Constant Field Values
Constructor Detail

FixedLengthProtobufDecoder

public FixedLengthProtobufDecoder(@NonNull
                                  com.google.protobuf.MessageLite prototype,
                                  com.google.protobuf.ExtensionRegistryLite extensionRegistry,
                                  int headerLength)
A protobuf decoder that uses the supplied headerLength to determine the size of the message to be decoded.

Parameters:
prototype - The base protocol buffers serialization unit.
extensionRegistry - A table of known extensions, searchable by name or field number, may be null.
headerLength - The length of the fixed header storing the size of the message.
Method Detail

readHeader

public int readHeader(org.glassfish.grizzly.Buffer input)
               throws java.io.IOException
Reads the header from the supplied input.

Parameters:
input - The input buffer to read the header from.
Returns:
The size of the protobuf message to parse.
Throws:
java.io.IOException - If the header could not be read.

getName

public java.lang.String getName()

Specified by:
getName in interface org.glassfish.grizzly.Transformer<org.glassfish.grizzly.Buffer,com.google.protobuf.MessageLite>

transformImpl

protected final org.glassfish.grizzly.TransformationResult<org.glassfish.grizzly.Buffer,com.google.protobuf.MessageLite> transformImpl(org.glassfish.grizzly.attributes.AttributeStorage storage,
                                                                                                                                       @NonNull
                                                                                                                                       org.glassfish.grizzly.Buffer input)
                                                                                                                                throws org.glassfish.grizzly.TransformationException

Specified by:
transformImpl in class org.glassfish.grizzly.AbstractTransformer<org.glassfish.grizzly.Buffer,com.google.protobuf.MessageLite>
Throws:
org.glassfish.grizzly.TransformationException

hasInputRemaining

public final boolean hasInputRemaining(org.glassfish.grizzly.attributes.AttributeStorage storage,
                                       org.glassfish.grizzly.Buffer input)