public HeaderOutboundFrame(int channel, ContentHeaderBase header, int bodyLength) : base(FrameType.FrameHeader, channel) { NetworkBinaryWriter writer = base.GetWriter(); writer.Write((ushort)header.ProtocolClassId); header.WriteTo(writer, (ulong)bodyLength); }
internal override int WritePayload(Memory <byte> memory) { // write protocol class id (2 bytes) NetworkOrderSerializer.WriteUInt16(memory, _header.ProtocolClassId); // write header (X bytes) int bytesWritten = _header.WriteTo(memory.Slice(2), (ulong)_bodyLength); return(2 + bytesWritten); }
public override void WritePayload(NetworkBinaryWriter writer) { var ms = new MemoryStream(); var nw = new NetworkBinaryWriter(ms); nw.Write(_header.ProtocolClassId); _header.WriteTo(nw, (ulong)_bodyLength); System.ArraySegment <byte> bufferSegment = ms.GetBufferSegment(); writer.Write((uint)bufferSegment.Count); writer.Write(bufferSegment.Array, bufferSegment.Offset, bufferSegment.Count); }
public void Transmit(int channelNumber, ConnectionBase connection) { Frame frame = new Frame(CommonFraming.Constants.FrameMethod, channelNumber); NetworkBinaryWriter writer = frame.GetWriter(); writer.Write((ushort)m_method.ProtocolClassId); writer.Write((ushort)m_method.ProtocolMethodId); MethodArgumentWriter argWriter = new MethodArgumentWriter(writer); m_method.WriteArgumentsTo(argWriter); argWriter.Flush(); connection.WriteFrame(frame); if (m_method.HasContent) { byte[] body = Body; frame = new Frame(CommonFraming.Constants.FrameHeader, channelNumber); writer = frame.GetWriter(); writer.Write((ushort)m_header.ProtocolClassId); m_header.WriteTo(writer, (ulong)body.Length); connection.WriteFrame(frame); int frameMax = (int)Math.Min(int.MaxValue, connection.FrameMax); int bodyPayloadMax = (frameMax == 0) ? body.Length : frameMax - EmptyContentBodyFrameSize; for (int offset = 0; offset < body.Length; offset += bodyPayloadMax) { int remaining = body.Length - offset; frame = new Frame(CommonFraming.Constants.FrameBody, channelNumber); writer = frame.GetWriter(); writer.Write(body, offset, (remaining < bodyPayloadMax) ? remaining : bodyPayloadMax); connection.WriteFrame(frame); } } }