static void WriteSection(ByteBuffer buffer, AmqpDescribed section, ByteBuffer source) { if (section != null) { if (source != null) { AmqpBitConverter.WriteBytes(buffer, source.Buffer, section.Offset, section.Length); } else { AmqpMessage.EncodeSection(buffer, section); } } }
protected override void Initialize(SectionFlag desiredSections, bool force = false) { if (this.buffer != null && !force) { return; } int size = this.source == null ? 1024 : this.source.Length; ByteBuffer buffer = new ByteBuffer(size, true); AmqpMessage.EncodeSection(buffer, this.header); AmqpMessage.EncodeSection(buffer, this.deliveryAnnotations); AmqpMessage.EncodeSection(buffer, this.messageAnnotations); if (this.deepCopy) { AmqpMessage.EncodeSection(buffer, this.properties); AmqpMessage.EncodeSection(buffer, this.applicationProperties); } else { WriteSection(buffer, this.properties, this.source); WriteSection(buffer, this.applicationProperties, this.source); } if (this.source != null && this.bodyOffset >= 0) { AmqpBitConverter.WriteBytes(buffer, this.source.Buffer, this.bodyOffset, this.bodyLength); } else { this.EncodeBody(buffer); } AmqpMessage.EncodeSection(buffer, this.footer); this.buffer?.Dispose(); this.buffer = buffer; this.messageSize = buffer.Length; }