public long ReadHeader(XmlReader reader, BrokeredMessage brokeredMessage, SerializationTarget serializationTarget) { byte[] numArray; long num; List <ArraySegment <byte> > arraySegments = new List <ArraySegment <byte> >(); long length = (long)0; if (serializationTarget == SerializationTarget.Communication) { reader.ReadStartElement(); } do { numArray = AmqpMessageEncoder.ReadBytes(reader, 512); length = length + (long)((int)numArray.Length); arraySegments.Add(new ArraySegment <byte>(numArray, 0, (int)numArray.Length)); }while ((int)numArray.Length >= 512); if (serializationTarget == SerializationTarget.Communication) { reader.ReadEndElement(); } using (BufferListStream bufferListStream = new BufferListStream(arraySegments.ToArray())) { using (AmqpMessage amqpMessage = AmqpMessage.CreateAmqpStreamMessageHeader(bufferListStream)) { amqpMessage.Deserialize(SectionFlag.NonBody); brokeredMessage.MessageId = "nil"; AmqpMessageEncoder.UpdateBrokeredMessageHeaderAndProperties(amqpMessage, brokeredMessage, serializationTarget); brokeredMessage.RawHeaderStream = amqpMessage.GetNonBodySectionsStream(); num = length; } } return(num); }
public static BrokeredMessage BrokerGetMessage(AmqpMessage amqpMessage, bool shouldOptimizeForPassthrough) { BrokeredMessage brokeredMessage; if (!shouldOptimizeForPassthrough) { amqpMessage.Deserialize(SectionFlag.All); brokeredMessage = new BrokeredMessage(amqpMessage.GetNonBodySectionsStream(), true, amqpMessage.GetBodySectionStream(), true, BrokeredMessageFormat.Amqp); } else { amqpMessage.Deserialize(SectionFlag.Header | SectionFlag.DeliveryAnnotations | SectionFlag.MessageAnnotations | SectionFlag.Properties | SectionFlag.ApplicationProperties); brokeredMessage = new BrokeredMessage(null, false, amqpMessage.ToStream(), true, BrokeredMessageFormat.PassthroughAmqp); } if (amqpMessage.RawByteBuffers != null) { brokeredMessage.AttachDisposables(amqpMessage.RawByteBuffers.GetClones()); } MessageConverter.UpdateBrokeredMessageHeaderAndProperties(amqpMessage, brokeredMessage); return(brokeredMessage); }