public void TransmitAsSingleFrame(int channelNumber, Connection connection) { var frame = new Frame(Constants.FrameMethod, channelNumber); NetworkBinaryWriter writer = frame.GetWriter(); writer.Write((ushort)Method.ProtocolClassId); writer.Write((ushort)Method.ProtocolMethodId); var argWriter = new MethodArgumentWriter(writer); Method.WriteArgumentsTo(argWriter); argWriter.Flush(); connection.WriteFrame(frame); }
public void Transmit(int channelNumber, Connection connection) { var frame = new Frame(Constants.FrameMethod, channelNumber); NetworkBinaryWriter writer = frame.GetWriter(); writer.Write((ushort)Method.ProtocolClassId); writer.Write((ushort)Method.ProtocolMethodId); var argWriter = new MethodArgumentWriter(writer); Method.WriteArgumentsTo(argWriter); argWriter.Flush(); connection.WriteFrame(frame); if (Method.HasContent) { byte[] body = Body; frame = new Frame(Constants.FrameHeader, channelNumber); writer = frame.GetWriter(); writer.Write((ushort)Header.ProtocolClassId); Header.WriteTo(writer, (ulong)body.Length); connection.WriteFrame(frame); var frameMax = (int)Math.Min(int.MaxValue, connection.FrameMax); int bodyPayloadMax = (frameMax == 0) ? body.Length : frameMax - EmptyFrameSize; for (int offset = 0; offset < body.Length; offset += bodyPayloadMax) { int remaining = body.Length - offset; frame = new Frame(Constants.FrameBody, channelNumber); writer = frame.GetWriter(); writer.Write(body, offset, (remaining < bodyPayloadMax) ? remaining : bodyPayloadMax); connection.WriteFrame(frame); } } }