Package com.rabbitmq.client.impl
Class Frame
- java.lang.Object
-
- com.rabbitmq.client.impl.Frame
-
public class Frame extends java.lang.Object
Represents an AMQP wire-protocol frame, with frame type, channel number, and payload bytes. TODO: make state private
-
-
Field Summary
Fields Modifier and Type Field Description private java.io.ByteArrayOutputStream
accumulator
Frame payload (for outbound frames)int
channel
Frame channel number, 0-65535private static int
NON_BODY_SIZE
private byte[]
payload
Frame payload bytes (for inbound frames)int
type
Frame type code
-
Constructor Summary
Constructors Constructor Description Frame(int type, int channel)
Constructs a frame for output with a type and a channel number and a fresh accumulator waiting for payload.Frame(int type, int channel, byte[] payload)
Constructs a frame for input with a type, a channel number and a payload byte array.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static long
arraySize(java.lang.Object[] values)
Computes the AMQP wire-protocol length of an encoded field-array of type Object[]static long
arraySize(java.util.List<?> values)
Computes the AMQP 0-9-1 wire-protocol length of an encoded field-array of type Listprivate static long
fieldValueSize(java.lang.Object value)
Computes the AMQP wire-protocol length of a protocol-encoded field-value.static Frame
fromBodyFragment(int channelNumber, byte[] body, int offset, int length)
java.io.DataInputStream
getInputStream()
Public API - retrieves a new DataInputStream streaming over the payloadjava.io.DataOutputStream
getOutputStream()
Public API - retrieves a fresh DataOutputStream streaming into the accumulatorbyte[]
getPayload()
Public API - retrieves the frame payloadprivate static int
longStrSize(java.lang.String str)
Computes the AMQP wire-protocol length of a protocol-encoded long string.static void
protocolVersionMismatch(java.io.DataInputStream is)
Private API - A protocol version mismatch is detected by checking the three next bytes if a frame type of (int)'A' is read from an input stream.static Frame
readFrom(java.io.DataInputStream is, int maxPayloadSize)
Protected API - Factory method to instantiate a Frame by reading an AMQP-wire-protocol frame from the given input stream.private static int
shortStrSize(java.lang.String str)
Computes the AMQP wire-protocol length of a protocol-encoded short string.int
size()
static long
tableSize(java.util.Map<java.lang.String,java.lang.Object> table)
Computes the AMQP wire-protocol length of protocol-encoded table entries.java.lang.String
toString()
void
writeTo(java.io.DataOutputStream os)
Public API - writes this Frame to the given DataOutputStream
-
-
-
Field Detail
-
type
public final int type
Frame type code
-
channel
public final int channel
Frame channel number, 0-65535
-
payload
private final byte[] payload
Frame payload bytes (for inbound frames)
-
accumulator
private final java.io.ByteArrayOutputStream accumulator
Frame payload (for outbound frames)
-
NON_BODY_SIZE
private static final int NON_BODY_SIZE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Frame
public Frame(int type, int channel)
Constructs a frame for output with a type and a channel number and a fresh accumulator waiting for payload.
-
Frame
public Frame(int type, int channel, byte[] payload)
Constructs a frame for input with a type, a channel number and a payload byte array.
-
-
Method Detail
-
fromBodyFragment
public static Frame fromBodyFragment(int channelNumber, byte[] body, int offset, int length) throws java.io.IOException
- Throws:
java.io.IOException
-
readFrom
public static Frame readFrom(java.io.DataInputStream is, int maxPayloadSize) throws java.io.IOException
Protected API - Factory method to instantiate a Frame by reading an AMQP-wire-protocol frame from the given input stream.- Returns:
- a new Frame if we read a frame successfully, otherwise null
- Throws:
java.io.IOException
-
protocolVersionMismatch
public static void protocolVersionMismatch(java.io.DataInputStream is) throws java.io.IOException
Private API - A protocol version mismatch is detected by checking the three next bytes if a frame type of (int)'A' is read from an input stream. If the next three bytes are 'M', 'Q' and 'P', then it's likely the broker is trying to tell us we are speaking the wrong AMQP protocol version.- Throws:
MalformedFrameException
- if an AMQP protocol version mismatch is detectedMalformedFrameException
- if a corrupt AMQP protocol identifier is readjava.io.IOException
-
writeTo
public void writeTo(java.io.DataOutputStream os) throws java.io.IOException
Public API - writes this Frame to the given DataOutputStream- Throws:
java.io.IOException
-
size
public int size()
-
getPayload
public byte[] getPayload()
Public API - retrieves the frame payload
-
getInputStream
public java.io.DataInputStream getInputStream()
Public API - retrieves a new DataInputStream streaming over the payload
-
getOutputStream
public java.io.DataOutputStream getOutputStream()
Public API - retrieves a fresh DataOutputStream streaming into the accumulator
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
tableSize
public static long tableSize(java.util.Map<java.lang.String,java.lang.Object> table) throws java.io.UnsupportedEncodingException
Computes the AMQP wire-protocol length of protocol-encoded table entries.- Throws:
java.io.UnsupportedEncodingException
-
fieldValueSize
private static long fieldValueSize(java.lang.Object value) throws java.io.UnsupportedEncodingException
Computes the AMQP wire-protocol length of a protocol-encoded field-value.- Throws:
java.io.UnsupportedEncodingException
-
arraySize
public static long arraySize(java.util.List<?> values) throws java.io.UnsupportedEncodingException
Computes the AMQP 0-9-1 wire-protocol length of an encoded field-array of type List- Throws:
java.io.UnsupportedEncodingException
-
arraySize
public static long arraySize(java.lang.Object[] values) throws java.io.UnsupportedEncodingException
Computes the AMQP wire-protocol length of an encoded field-array of type Object[]- Throws:
java.io.UnsupportedEncodingException
-
longStrSize
private static int longStrSize(java.lang.String str) throws java.io.UnsupportedEncodingException
Computes the AMQP wire-protocol length of a protocol-encoded long string.- Throws:
java.io.UnsupportedEncodingException
-
shortStrSize
private static int shortStrSize(java.lang.String str) throws java.io.UnsupportedEncodingException
Computes the AMQP wire-protocol length of a protocol-encoded short string.- Throws:
java.io.UnsupportedEncodingException
-
-