示例#1
0
        public static RdmPacket ReadPacket(RdmBinaryReader data)
        {
            RdmPacket rdmPacket = null;

            RdmHeader header = new RdmHeader();

            header.ReadData(data);

            rdmPacket = RdmPacket.Create(header);
            if (rdmPacket != null)
            {
                rdmPacket.ReadData(data);
                return(rdmPacket);
            }
            else
            {
                rdmPacket = RdmPacket.Create(header, typeof(RdmRawPacket)) as RdmRawPacket;
                if (rdmPacket != null)
                {
                    rdmPacket.ReadData(data);
                    return(rdmPacket);
                }
            }

            throw new UnknownRdmPacketException(header);
        }
示例#2
0
        public static RdmPacket ReadPacket(RdmCommands command, RdmParameters parameterId, RdmBinaryReader contentData)
        {
            RdmPacket rdmPacket = null;

            RdmHeader header = new RdmHeader();

            header.Command     = command;
            header.ParameterId = parameterId;

            rdmPacket = RdmPacket.Create(header);
            if (rdmPacket != null)
            {
                rdmPacket.ReadData(contentData);
                return(rdmPacket);
            }
            else
            {
                rdmPacket = RdmPacket.Create(header, typeof(RdmRawPacket)) as RdmRawPacket;
                if (rdmPacket != null)
                {
                    rdmPacket.ReadData(contentData);
                    return(rdmPacket);
                }
            }

            throw new UnknownRdmPacketException(header);
        }
示例#3
0
        public static RdmPacket Create(RdmHeader header, Type packetType)
        {
            RdmPacket packet = (RdmPacket)Activator.CreateInstance(packetType);

            packet.Header = header;
            return(packet);
        }
示例#4
0
        public static void WritePacket(RdmPacket packet, RdmBinaryWriter data, bool onlyContent)
        {
            if (!onlyContent)
            {
                packet.WriteHeader(data);
            }

            packet.WriteData(data);

            if (!onlyContent)
            {
                packet.Header.WriteLength(data);
            }
        }
示例#5
0
        public static RdmRawPacket ReadPacketRaw(RdmBinaryReader data)
        {
            RdmHeader header = new RdmHeader();

            header.ReadData(data);

            RdmRawPacket rdmPacket = RdmPacket.Create(header, typeof(RdmRawPacket)) as RdmRawPacket;

            if (rdmPacket != null)
            {
                rdmPacket.ReadData(data);
            }

            return(rdmPacket);
        }
示例#6
0
        public static bool TryReadPacket(RdmBinaryReader data, out RdmPacket rdmPacket)
        {
            RdmHeader header = new RdmHeader();

            header.ReadData(data);

            rdmPacket = RdmPacket.Create(header);
            if (rdmPacket != null)
            {
                rdmPacket.ReadData(data);
                return(true);
            }

            return(false);
        }
示例#7
0
        public static RdmPacket BuildErrorResponse(RdmHeader header)
        {
            if (header.PortOrResponseType != 0)
            {
                switch ((RdmResponseTypes)header.PortOrResponseType)
                {
                case RdmResponseTypes.AckTimer:
                    return(RdmPacket.Create(header, typeof(RdmAckTimer)));

                case RdmResponseTypes.NackReason:
                    return(RdmPacket.Create(header, typeof(RdmNack)));
                }
            }

            return(null);
        }
示例#8
0
        public static RdmPacket Build(RdmHeader header)
        {
            if (IsErrorResponse(header))
            {
                //Error Response Packets
                return(BuildErrorResponse(header));
            }
            else
            {
                Type packetType;
                if (packetStore.TryGetValue(new PacketKey(header.Command, header.ParameterId), out packetType))
                {
                    return(RdmPacket.Create(header, packetType));
                }
            }

            return(null);
        }
示例#9
0
 public static void WritePacket(RdmPacket packet, RdmBinaryWriter data)
 {
     WritePacket(packet, data, false);
 }