me.cmoz.grizzly.protobuf
Class Varint32ProtobufEncoder

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

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

Encodes Protocol Buffers messages to the output stream using a Varint32 encoded header to store the length of the serialized 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_WRITE_ERROR
          The error code for a failed write to the output stream.
 
Fields inherited from class org.glassfish.grizzly.AbstractTransformer
attributeBuilder, stateAttr
 
Constructor Summary
Varint32ProtobufEncoder()
           
 
Method Summary
 java.lang.String getName()
          
 boolean hasInputRemaining(org.glassfish.grizzly.attributes.AttributeStorage storage, com.google.protobuf.MessageLite input)
          
protected  org.glassfish.grizzly.TransformationResult<com.google.protobuf.MessageLite,org.glassfish.grizzly.Buffer> transformImpl(org.glassfish.grizzly.attributes.AttributeStorage storage, com.google.protobuf.MessageLite input)
          
 void writeHeader(org.glassfish.grizzly.utils.BufferOutputStream outputStream, int messageLength)
          Writes a header to the supplied outputStream.
 
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_WRITE_ERROR

public static final int IO_WRITE_ERROR
The error code for a failed write to the output stream.

See Also:
Constant Field Values
Constructor Detail

Varint32ProtobufEncoder

public Varint32ProtobufEncoder()
Method Detail

writeHeader

public void writeHeader(org.glassfish.grizzly.utils.BufferOutputStream outputStream,
                        int messageLength)
                 throws java.io.IOException
Writes a header to the supplied outputStream.

Note Do not close the outputStream this will be handled automatically.

Parameters:
outputStream - The stream to write the header to.
messageLength - The length of the message to write.
Throws:
java.io.IOException - If there was a problem writing the header.

getName

public java.lang.String getName()

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

transformImpl

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

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

hasInputRemaining

public final boolean hasInputRemaining(org.glassfish.grizzly.attributes.AttributeStorage storage,
                                       com.google.protobuf.MessageLite input)