me.cmoz.grizzly.protobuf
Class Varint32ProtobufDecoder

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

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

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


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
Varint32ProtobufDecoder(com.google.protobuf.MessageLite prototype, com.google.protobuf.ExtensionRegistryLite extensionRegistry)
          A protobuf decoder that uses a Varint32 encoded header to determine the size of a 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

Varint32ProtobufDecoder

public Varint32ProtobufDecoder(@NonNull
                               com.google.protobuf.MessageLite prototype,
                               com.google.protobuf.ExtensionRegistryLite extensionRegistry)
A protobuf decoder that uses a Varint32 encoded header to determine the size of a 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.
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)