public async Task Send_Heartbeat() { var buffer = await socket.GetWriteBuffer().ConfigureAwait(false); try { if (socket.HeartbeatNeeded) { WritePayload(); } await buffer.FlushAsync().ConfigureAwait(false); } finally { socket.ReleaseWriteBuffer(true); } void WritePayload() { var writer = new CustomBufferWriter <PipeWriter>(buffer); writer.Write(FrameType.Heartbeat); writer.Write(connectionChannelNumber); writer.Write((uint)0); writer.Write(FrameEnd); writer.Commit(); } }
public async Task Send_Close(ushort replyCode = ConnectionReplyCode.Success, string replyText = "Goodbye", ushort failingClass = 0, ushort failingMethod = 0) { var buffer = await socket.GetWriteBuffer().ConfigureAwait(false); try { WritePayload(); await buffer.FlushAsync().ConfigureAwait(false); } finally { socket.ReleaseWriteBuffer(); } void WritePayload() { var writer = new CustomBufferWriter <PipeWriter>(buffer); var payloadSizeHeader = writer.WriteFrameHeader(FrameType.Method, connectionChannelNumber); writer.Write(Method.Connection.Close); writer.Write(replyCode); writer.WriteShortString(replyText); writer.Write(failingClass); writer.Write(failingMethod); writer.Commit(); BinaryPrimitives.WriteUInt32BigEndian(payloadSizeHeader, (uint)writer.BytesCommitted - FrameHeaderSize); writer.Write(FrameEnd); writer.Commit(); } }
public async Task Send_CloseOk() { var buffer = await socket.GetWriteBuffer().ConfigureAwait(false); try { WritePayload(); await buffer.FlushAsync().ConfigureAwait(false); } finally { socket.ReleaseWriteBuffer(); } void WritePayload() { var writer = new CustomBufferWriter <PipeWriter>(buffer); var payloadSizeHeader = writer.WriteFrameHeader(FrameType.Method, connectionChannelNumber); writer.Write(Method.Connection.CloseOk); writer.Commit(); BinaryPrimitives.WriteUInt32BigEndian(payloadSizeHeader, (uint)writer.BytesCommitted - FrameHeaderSize); writer.Write(FrameEnd); writer.Commit(); } }
public async Task Send_Qos(uint prefetchSize, ushort prefetchCount, bool global) { var buffer = await socket.GetWriteBuffer().ConfigureAwait(false); try { WritePayload(); await buffer.FlushAsync().ConfigureAwait(false); } finally { socket.ReleaseWriteBuffer(); } void WritePayload() { var writer = new CustomBufferWriter <PipeWriter>(buffer); var payloadSizeHeader = writer.WriteFrameHeader(FrameType.Method, channelNumber); writer.Write(Method.Basic.Qos); writer.Write(prefetchSize); writer.Write(prefetchCount); writer.WriteBits(global); writer.Commit(); BinaryPrimitives.WriteUInt32BigEndian(payloadSizeHeader, (uint)writer.BytesCommitted - FrameHeaderSize); writer.Write(FrameEnd); writer.Commit(); } }
public async Task Send_Cancel(string consumerTag) { var buffer = await socket.GetWriteBuffer().ConfigureAwait(false); try { WritePayload(); await buffer.FlushAsync().ConfigureAwait(false); } finally { socket.ReleaseWriteBuffer(); } void WritePayload() { var writer = new CustomBufferWriter <PipeWriter>(buffer); var payloadSizeHeader = writer.WriteFrameHeader(FrameType.Method, channelNumber); writer.Write(Method.Basic.Cancel); writer.WriteShortString(consumerTag); writer.WriteBits(); writer.Commit(); BinaryPrimitives.WriteUInt32BigEndian(payloadSizeHeader, (uint)writer.BytesCommitted - FrameHeaderSize); writer.Write(FrameEnd); writer.Commit(); } }
public async Task Send_Ack(ulong deliveryTag, bool multiple) { var buffer = await socket.GetWriteBuffer().ConfigureAwait(false); try { WritePayload(); await buffer.FlushAsync().ConfigureAwait(false); } finally { socket.ReleaseWriteBuffer(); } void WritePayload() { var writer = new CustomBufferWriter <PipeWriter>(buffer); var payloadSizeHeader = writer.WriteFrameHeader(FrameType.Method, channelNumber); writer.Write(Method.Basic.Ack); writer.Write(deliveryTag); writer.WriteBits(multiple); writer.Commit(); BinaryPrimitives.WriteUInt32BigEndian(payloadSizeHeader, (uint)writer.BytesCommitted - FrameHeaderSize); writer.Write(FrameEnd); writer.Commit(); } }
public async Task Send_Delete(string exchange, bool onlyIfUnused) { var buffer = await socket.GetWriteBuffer().ConfigureAwait(false); try { WritePayload(); await buffer.FlushAsync().ConfigureAwait(false); } finally { socket.ReleaseWriteBuffer(); } void WritePayload() { var writer = new CustomBufferWriter <PipeWriter>(buffer); var payloadSizeHeader = writer.WriteFrameHeader(FrameType.Method, channelNumber); writer.Write(Method.Exchange.Delete); writer.Write(Reserved); writer.Write(Reserved); writer.WriteShortString(exchange); writer.WriteBits(onlyIfUnused); writer.Commit(); BinaryPrimitives.WriteUInt32BigEndian(payloadSizeHeader, (uint)writer.BytesCommitted - FrameHeaderSize); writer.Write(FrameEnd); writer.Commit(); } }
public async Task Send_Declare(string queueName, bool passive, bool durable, bool exclusive, bool autoDelete, Dictionary <string, object> arguments) { var buffer = await socket.GetWriteBuffer().ConfigureAwait(false); try { WritePayload(); await buffer.FlushAsync().ConfigureAwait(false); } finally { socket.ReleaseWriteBuffer(); } void WritePayload() { var writer = new CustomBufferWriter <PipeWriter>(buffer); var payloadSizeHeader = writer.WriteFrameHeader(FrameType.Method, channelNumber); writer.Write(Method.Queue.Declare); writer.Write(Reserved); writer.Write(Reserved); writer.WriteShortString(queueName); writer.WriteBits(passive, durable, exclusive, autoDelete); writer.WriteTable(arguments); writer.Commit(); BinaryPrimitives.WriteUInt32BigEndian(payloadSizeHeader, (uint)writer.BytesCommitted - FrameHeaderSize); writer.Write(FrameEnd); writer.Commit(); } }
public async Task Send_Publish(string exchange, string routingKey, bool mandatory, MessageProperties properties, Memory <byte> bodyBytes) { var buffer = await socket.GetWriteBuffer().ConfigureAwait(false); try { WritePayload(); await buffer.FlushAsync().ConfigureAwait(false); } finally { socket.ReleaseWriteBuffer(); } void WritePayload() { var writer = new CustomBufferWriter <PipeWriter>(buffer); var payloadSizeHeader = writer.WriteFrameHeader(FrameType.Method, channelNumber); writer.Write(Method.Basic.Publish); writer.Write(Reserved); writer.Write(Reserved); writer.WriteShortString(exchange); writer.WriteShortString(routingKey); writer.WriteBits(mandatory); writer.Commit(); BinaryPrimitives.WriteUInt32BigEndian(payloadSizeHeader, (uint)writer.BytesCommitted - FrameHeaderSize); writer.Write(FrameEnd); var body = bodyBytes.Span; WriteContentHeaderFrame(ref writer, properties, (ulong)body.Length); var framesToWrite = body.Length > 0; while (framesToWrite) { Span <byte> frame; if (body.Length > maxContentBodySize) { frame = body.Slice(0, (int)maxContentBodySize); body = body.Slice((int)maxContentBodySize); } else { frame = body; framesToWrite = false; } WriteContentBodyFrame(ref writer, frame); } writer.Commit(); } }
private void WriteContentBodyFrame(ref CustomBufferWriter <PipeWriter> writer, Span <byte> body) { var payloadSizeHeader = writer.WriteFrameHeader(FrameType.ContentBody, channelNumber); writer.Commit(); var bytesWrittenBefore = (uint)writer.BytesCommitted; writer.Write(body); writer.Commit(); BinaryPrimitives.WriteUInt32BigEndian(payloadSizeHeader, (uint)writer.BytesCommitted - bytesWrittenBefore); writer.Write(FrameEnd); }
private void WriteContentHeaderFrame(ref CustomBufferWriter <PipeWriter> writer, MessageProperties properties, ulong length) { var payloadSizeHeader = writer.WriteFrameHeader(FrameType.ContentHeader, channelNumber); writer.Commit(); var bytesWrittenBefore = (uint)writer.BytesCommitted; writer.Write(ClassId.Basic); writer.Write(Reserved); writer.Write(Reserved); writer.Write(length); writer.WriteBasicProperties(properties); writer.Commit(); BinaryPrimitives.WriteUInt32BigEndian(payloadSizeHeader, (uint)writer.BytesCommitted - bytesWrittenBefore); writer.Write(FrameEnd); }
public async Task Send_StartOk(string connectionName, string userName, string password, string mechanism = "PLAIN", string locale = "en_US") { var buffer = await socket.GetWriteBuffer().ConfigureAwait(false); try { WritePayload(); await buffer.FlushAsync().ConfigureAwait(false); } finally { socket.ReleaseWriteBuffer(); } void WritePayload() { var writer = new CustomBufferWriter <PipeWriter>(buffer); var payloadSizeHeader = writer.WriteFrameHeader(FrameType.Method, connectionChannelNumber); writer.Write(Method.Connection.StartOk); var clientProperties = new Dictionary <string, object> { { "product", "Angora.PrototypeClient" }, { "capabilities", capabilities }, { "connection_name", connectionName } }; writer.WriteTable(clientProperties); writer.WriteShortString(mechanism); writer.WriteLongString($"\0{userName}\0{password}"); //response writer.WriteShortString(locale); writer.Commit(); BinaryPrimitives.WriteUInt32BigEndian(payloadSizeHeader, (uint)writer.BytesCommitted - FrameHeaderSize); writer.Write(FrameEnd); writer.Commit(); } }
public async Task Send_ProtocolHeader() { var buffer = await socket.GetWriteBuffer().ConfigureAwait(false); try { WritePayload(); await buffer.FlushAsync().ConfigureAwait(false); } finally { socket.ReleaseWriteBuffer(); } void WritePayload() { var writer = new CustomBufferWriter <PipeWriter>(buffer); writer.Write(protocolHeader); writer.Commit(); } }
public async Task Send_Bind(string source, string destination, string routingKey, Dictionary <string, object> arguments) { var buffer = await socket.GetWriteBuffer().ConfigureAwait(false); try { WritePayload(); await buffer.FlushAsync().ConfigureAwait(false); } finally { socket.ReleaseWriteBuffer(); } void WritePayload() { var writer = new CustomBufferWriter <PipeWriter>(buffer); var payloadSizeHeader = writer.WriteFrameHeader(FrameType.Method, channelNumber); writer.Write(Method.Exchange.Bind); writer.Write(Reserved); writer.Write(Reserved); writer.WriteShortString(source); writer.WriteShortString(destination); writer.WriteShortString(routingKey); writer.WriteBits(); writer.WriteTable(arguments); writer.Commit(); BinaryPrimitives.WriteUInt32BigEndian(payloadSizeHeader, (uint)writer.BytesCommitted - FrameHeaderSize); writer.Write(FrameEnd); writer.Commit(); } }