public static Frame Decode(ByteBuffer buffer, bool fullBody = true) { Frame frame = new Frame(); frame.RawBuffer = buffer.Array; // Header frame.size = (int)AmqpBitConverter.ReadUInt(buffer); frame.dataOffset = AmqpBitConverter.ReadUByte(buffer); frame.Type = (FrameType)AmqpBitConverter.ReadUByte(buffer); frame.Channel = AmqpBitConverter.ReadUShort(buffer); // skip extended header buffer.Complete(frame.dataOffset * 4 - Frame.HeaderSize); // Command if (buffer.Length > 0) { frame.Command = (Performative)AmqpCodec.CreateAmqpDescribed(buffer); if (fullBody) { frame.Command.DecodeValue(buffer); } } return(frame); }
private void DecodeHeader(ByteBuffer buffer) { this.Size = (int)AmqpBitConverter.ReadUInt(buffer); this.DataOffset = AmqpBitConverter.ReadUByte(buffer); this.Type = (FrameType)AmqpBitConverter.ReadUByte(buffer); this.Channel = AmqpBitConverter.ReadUShort(buffer); buffer.Complete(this.DataOffset * 4 - 8); }
public static ushort?Decode(ByteBuffer buffer, FormatCode formatCode) { if (formatCode == 0 && (formatCode = AmqpEncoding.ReadFormatCode(buffer)) == FormatCode.Null) { return(null); } return(AmqpBitConverter.ReadUShort(buffer)); }
void DecodeHeader(ByteBuffer buffer) { this.Size = (int)AmqpBitConverter.ReadUInt(buffer); this.DataOffset = AmqpBitConverter.ReadUByte(buffer); this.Type = (FrameType)AmqpBitConverter.ReadUByte(buffer); this.Channel = AmqpBitConverter.ReadUShort(buffer); // skip extended header buffer.Complete(this.DataOffset * 4 - Frame.HeaderSize); }
public static ushort ReadUShort(ByteBuffer buffer, byte formatCode) { if (formatCode == FormatCode.UShort) { return(AmqpBitConverter.ReadUShort(buffer)); } else { throw DecodeException(formatCode, buffer.Offset); } }
public static AmqpFrame DecodeFrame(ByteBuffer buffer, out ushort channelNumber) { #if DEBUG byte[] debugFrameBuffer = new byte[buffer.LengthAvailableToRead]; Buffer.BlockCopy(buffer.Buffer, buffer.ReadOffset, debugFrameBuffer, 0, buffer.LengthAvailableToRead); #endif int frameStartOffset = buffer.ReadOffset; // frame header uint frameSize = AmqpBitConverter.ReadUInt(buffer); byte dataOffset = AmqpBitConverter.ReadUByte(buffer); byte frameType = AmqpBitConverter.ReadUByte(buffer); channelNumber = AmqpBitConverter.ReadUShort(buffer); // out param if (dataOffset < 2) { throw new AmqpException(ErrorCode.FramingError, $"DOFF must be >= 2. Value is {dataOffset.ToHex()}"); } // data offset is always counted in 4-byte words. header total length is 8 bytes int bodyStartOffset = 4 * dataOffset; // forward the reader the number of bytes needed to reach the frame body buffer.CompleteRead((bodyStartOffset - 8)); if (frameSize == bodyStartOffset) { // empty frame body return(null); } // we're expecting a described list... var formatCode = DecodeFormatCode(buffer); if (formatCode != FormatCode.Described) { throw new AmqpException(ErrorCode.FramingError, $"Expected Format Code = {FormatCode.Described.ToHex()} but was {formatCode.ToHex()}"); } try { // decode return((AmqpFrame)DecodeDescribedType(buffer, formatCode)); } catch (Exception) { #if DEBUG TraceSource.FromClass().Debug(Environment.NewLine + debugFrameBuffer.ToHex()); #endif throw; } }
bool OnFrame(Stream stream, ByteBuffer buffer) { buffer.Complete(1); byte type = AmqpBitConverter.ReadUByte(buffer); ushort channel = AmqpBitConverter.ReadUShort(buffer); DescribedList command = (DescribedList)Encoder.ReadDescribed(buffer, Encoder.ReadFormatCode(buffer)); Amqp.Message message = null; if (command.Descriptor.Code == FrameCodes.TRANSFER) { message = Amqp.Message.Decode(buffer); } return(testAmqpPeer.OnFrame(stream, channel, command, message)); }
public static void Decode(ByteBuffer buffer, out ushort channel, out DescribedList command) { AmqpBitConverter.ReadUInt(buffer); AmqpBitConverter.ReadUByte(buffer); AmqpBitConverter.ReadUByte(buffer); channel = AmqpBitConverter.ReadUShort(buffer); if (buffer.Length > 0) { command = (DescribedList)Codec.Decode(buffer); } else { command = null; } }
public void TestMethod_AmqpBitConverter() { ByteBuffer buffer = new ByteBuffer(128, true); AmqpBitConverter.WriteByte(buffer, 0x22); AmqpBitConverter.WriteByte(buffer, -0x22); AmqpBitConverter.WriteUByte(buffer, 0x22); AmqpBitConverter.WriteUByte(buffer, 0xB2); AmqpBitConverter.WriteShort(buffer, 0x22B7); AmqpBitConverter.WriteShort(buffer, -0x22B7); AmqpBitConverter.WriteUShort(buffer, 0x22B7); AmqpBitConverter.WriteUShort(buffer, 0xC2B7); AmqpBitConverter.WriteInt(buffer, 0x340da287); AmqpBitConverter.WriteInt(buffer, -0x340da287); AmqpBitConverter.WriteUInt(buffer, 0x340da287); AmqpBitConverter.WriteUInt(buffer, 0xF40da287); AmqpBitConverter.WriteLong(buffer, 0x5d00BB9A340da287); AmqpBitConverter.WriteLong(buffer, -0x5d00BB9A340da287); AmqpBitConverter.WriteULong(buffer, 0x5d00BB9A340da287); AmqpBitConverter.WriteULong(buffer, 0xad00BB9A340da287); AmqpBitConverter.WriteFloat(buffer, 12344.4434F); AmqpBitConverter.WriteFloat(buffer, -12344.4434F); AmqpBitConverter.WriteDouble(buffer, 39432123244.44352334); AmqpBitConverter.WriteDouble(buffer, -39432123244.44352334); Guid uuid = Guid.NewGuid(); AmqpBitConverter.WriteUuid(buffer, uuid); sbyte b = AmqpBitConverter.ReadByte(buffer); sbyte b2 = AmqpBitConverter.ReadByte(buffer); byte ub = AmqpBitConverter.ReadUByte(buffer); byte ub2 = AmqpBitConverter.ReadUByte(buffer); short s = AmqpBitConverter.ReadShort(buffer); short s2 = AmqpBitConverter.ReadShort(buffer); ushort us = AmqpBitConverter.ReadUShort(buffer); ushort us2 = AmqpBitConverter.ReadUShort(buffer); int i = AmqpBitConverter.ReadInt(buffer); int i2 = AmqpBitConverter.ReadInt(buffer); uint ui = AmqpBitConverter.ReadUInt(buffer); uint ui2 = AmqpBitConverter.ReadUInt(buffer); long l = AmqpBitConverter.ReadLong(buffer); long l2 = AmqpBitConverter.ReadLong(buffer); ulong ul = AmqpBitConverter.ReadULong(buffer); ulong ul2 = AmqpBitConverter.ReadULong(buffer); float f = AmqpBitConverter.ReadFloat(buffer); float f2 = AmqpBitConverter.ReadFloat(buffer); double d = AmqpBitConverter.ReadDouble(buffer); double d2 = AmqpBitConverter.ReadDouble(buffer); Guid uuid2 = AmqpBitConverter.ReadUuid(buffer); }
bool OnFrame(Stream stream, ByteBuffer buffer) { buffer.Complete(1); byte type = AmqpBitConverter.ReadUByte(buffer); ushort channel = AmqpBitConverter.ReadUShort(buffer); buffer.Complete(1); ulong code = Encoder.ReadULong(buffer, Encoder.ReadFormatCode(buffer)); List fields = Encoder.ReadList(buffer, Encoder.ReadFormatCode(buffer)); switch (code) { case 0x41ul: // sasl-init if (this.HandleTestPoint(TestPoint.SaslInit, stream, channel, fields) == TestOutcome.Continue) { FRM(stream, 0x44ul, 1, 0, (byte)0); } return(false); case 0x10ul: // open if (this.HandleTestPoint(TestPoint.Open, stream, channel, fields) == TestOutcome.Continue) { FRM(stream, 0x10UL, 0, 0, "TestListener"); } break; case 0x11ul: // begin if (this.HandleTestPoint(TestPoint.Begin, stream, channel, fields) == TestOutcome.Continue) { FRM(stream, 0x11UL, 0, channel, channel, 0u, 100u, 100u, 8u); } break; case 0x12ul: // attach if (this.HandleTestPoint(TestPoint.Attach, stream, channel, fields) == TestOutcome.Continue) { bool role = !(bool)fields[2]; FRM(stream, 0x12UL, 0, channel, fields[0], fields[1], role, fields[3], fields[4], new Source(), new Target()); if (role) { FRM(stream, 0x13UL, 0, channel, 0u, 100u, 0u, 100u, fields[1], 0u, 1000u); } } break; case 0x13ul: // flow if (this.HandleTestPoint(TestPoint.Flow, stream, channel, fields) == TestOutcome.Continue) { } break; case 0x14ul: // transfer if (this.HandleTestPoint(TestPoint.Transfer, stream, channel, fields) == TestOutcome.Continue) { FRM(stream, 0x15UL, 0, channel, true, fields[1], null, true, new Accepted()); } break; case 0x15ul: // disposition if (this.HandleTestPoint(TestPoint.Disposition, stream, channel, fields) == TestOutcome.Continue) { } break; case 0x16ul: // dettach if (this.HandleTestPoint(TestPoint.Detach, stream, channel, fields) == TestOutcome.Continue) { FRM(stream, 0x16UL, 0, channel, fields[0], true); } break; case 0x17ul: // end if (this.HandleTestPoint(TestPoint.End, stream, channel, fields) == TestOutcome.Continue) { FRM(stream, 0x17UL, 0, channel); } break; case 0x18ul: // close if (this.HandleTestPoint(TestPoint.Close, stream, channel, fields) == TestOutcome.Continue) { FRM(stream, 0x18UL, 0, channel); } return(false); default: break; } return(true); }