public static void WritePacket(RdmPacket packet, RdmBinaryWriter data, bool onlyContent) { if (!onlyContent) { packet.WriteHeader(data); } packet.WriteData(data); if (!onlyContent) { packet.Header.WriteLength(data); } }
public void WriteData(RdmBinaryWriter data) { //Save position so we can write length later. messageLengthPosition = data.BaseStream.Position; data.Write(MessageLength); data.Write(DestinationId); data.Write(SourceId); data.Write(TransactionNumber); data.Write(PortOrResponseType); data.Write(MessageCount); data.WriteNetwork(SubDevice); data.Write((byte)Command); data.WriteNetwork((short)ParameterId); //Save position so we can write length later. dataLengthPosition = data.BaseStream.Position; data.Write(ParameterDataLength); }
public void WriteLength(RdmBinaryWriter data) { if (messageLengthPosition < 0 || dataLengthPosition <= 0) { throw new InvalidOperationException("Packet data has not been written yet. You can not write the length until the body is written."); } MessageLength = (byte)(data.BaseStream.Position - messageLengthPosition + 2); ParameterDataLength = (byte)((data.BaseStream.Position - 1) - dataLengthPosition); //Write Message Length data.BaseStream.Seek(messageLengthPosition, System.IO.SeekOrigin.Begin); data.Write(MessageLength); //Write Parameter Data Length data.BaseStream.Seek(dataLengthPosition, System.IO.SeekOrigin.Begin); data.Write(ParameterDataLength); //Move back to end of stream. data.BaseStream.Seek(0, System.IO.SeekOrigin.End); }
protected abstract void WriteData(RdmBinaryWriter data);
protected void WriteHeader(RdmBinaryWriter data) { Header.WriteData(data); }
public static void WritePacket(RdmPacket packet, RdmBinaryWriter data) { WritePacket(packet, data, false); }