Package io.grpc.alts.internal
Class AltsFraming.Parser
- java.lang.Object
-
- io.grpc.alts.internal.AltsFraming.Parser
-
- Enclosing class:
- AltsFraming
public static final class AltsFraming.Parser extends java.lang.Object
A helper class to read 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:
Parser parser = new Parser(); ByteBuffer inputBuffer = readBytesFromMyStream(); ByteBuffer outputBuffer = writeBytesToMyStream(); while (inputBuffer.hasRemaining() || outputBuffer.hasRemaining()) { parser.readBytes(inputBuffer); parser.writeBytes(outputBuffer); }
Alternatively, this class guarantees that one of the following is true:
- readBytes will read from the input
isComplete()
returns true andgetByteBuffer()
returns the contents of a processed frame.
Sample usage:
Parser parser = new Parser(); while (!parser.isComplete()) { ByteBuffer inputBuffer = readBytesFromMyStream(); parser.readBytes(inputBuffer); } ByteBuffer outputBuffer = parser.getRawFrame();
-
-
Field Summary
Fields Modifier and Type Field Description private java.nio.ByteBuffer
buffer
private boolean
isComplete
-
Constructor Summary
Constructors Constructor Description Parser()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) int
getFramePrefixLength()
The length of the frame prefix data, including the message length/type fields.(package private) int
getFrameSuffixLength()
java.nio.ByteBuffer
getRawFrame()
Returns a ByteBuffer containing a complete raw frame, if it's available.boolean
isComplete()
Returns true if we've parsed a complete frame.boolean
readBytes(java.nio.ByteBuffer input)
Reads bytes from input, parsing them into a frame.private void
reset()
Resets the state, preparing to parse a new frame.
-
-
-
Method Detail
-
readBytes
public boolean readBytes(java.nio.ByteBuffer input) throws java.security.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:
java.security.GeneralSecurityException
-
getFramePrefixLength
int getFramePrefixLength()
The length of the frame prefix data, including the message length/type fields.
-
getFrameSuffixLength
int getFrameSuffixLength()
-
isComplete
public boolean isComplete()
Returns true if we've parsed a complete frame.
-
reset
private void reset()
Resets the state, preparing to parse a new frame. Must be called between frames.
-
getRawFrame
public java.nio.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.
-
-