Class AltsFraming.Producer

java.lang.Object
io.grpc.alts.internal.AltsFraming.Producer
Enclosing class:
AltsFraming

static final class AltsFraming.Producer extends Object
A helper class to write a frame.

This class guarantees that one of the following is true:

  • readBytes will read from the input
  • writeBytes will write to the output

Sample usage:


 Producer producer = new Producer();
 ByteBuffer inputBuffer = readBytesFromMyStream();
 ByteBuffer outputBuffer = writeBytesToMyStream();
 while (inputBuffer.hasRemaining() || outputBuffer.hasRemaining()) {
   producer.readBytes(inputBuffer);
   producer.writeBytes(outputBuffer);
 }
 

Alternatively, this class guarantees that one of the following is true:

  • readBytes will read from the input
  • isComplete() returns true and getByteBuffer() returns the contents of a processed frame.

Sample usage:


 Producer producer = new Producer();
 while (!producer.isComplete()) {
   ByteBuffer inputBuffer = readBytesFromMyStream();
   producer.readBytes(inputBuffer);
 }
 producer.flush();
 ByteBuffer outputBuffer = producer.getRawFrame();
 
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private ByteBuffer
     
    private boolean
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    Producer(int maxFrameSize)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) void
    Completes the current frame, signaling that no further data is available to be passed to readBytes and that the client requires writeBytes to start returning data.
    (package private) int
    The length of the frame prefix data, including the message length/type fields.
    (package private) int
     
    (package private) ByteBuffer
    Returns a ByteBuffer containing a complete raw frame, if it's available.
    (package private) boolean
    Reads bytes from input, parsing them into a frame.
    private void
    Resets the state, preparing to construct a new frame.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • buffer

      private ByteBuffer buffer
    • isComplete

      private boolean isComplete
  • Constructor Details

    • Producer

      Producer(int maxFrameSize)
    • Producer

      Producer()
  • Method Details

    • getFramePrefixLength

      int getFramePrefixLength()
      The length of the frame prefix data, including the message length/type fields.
    • getFrameSuffixLength

      int getFrameSuffixLength()
    • readBytes

      boolean readBytes(ByteBuffer input) throws GeneralSecurityException
      Reads bytes from input, parsing them into a frame. Returns false if and only if more data is needed. To obtain a full frame this method must be called repeatedly until it returns true.
      Throws:
      GeneralSecurityException
    • flush

      void flush() throws GeneralSecurityException
      Completes the current frame, signaling that no further data is available to be passed to readBytes and that the client requires writeBytes to start returning data. isComplete() is guaranteed to return true after this call.
      Throws:
      GeneralSecurityException
    • reset

      private void reset()
      Resets the state, preparing to construct a new frame. Must be called between frames.
    • getRawFrame

      ByteBuffer getRawFrame()
      Returns a ByteBuffer containing a complete raw frame, if it's available. Should only be called when isComplete() returns true, otherwise null is returned. The returned object aliases the internal buffer, that is, it shares memory with the internal buffer. No further operations are permitted on this object until the caller has processed the data it needs from the returned byte buffer.