me.cmoz.grizzly.protobuf
Class FixedLengthProtobufEncoder

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

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

Encodes Protocol Buffers messages to the output stream with a fixed length header containing the size of the 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
FixedLengthProtobufEncoder(int headerLength)
          A protobuf encoder that uses the supplied headerSize to add a header to the message containing the size of the message.
 
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

FixedLengthProtobufEncoder

public FixedLengthProtobufEncoder(int headerLength)
A protobuf encoder that uses the supplied headerSize to add a header to the message containing the size of the message.

Parameters:
headerLength - The length of the header storing the size of the message.
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)