Esempio n. 1
0
        public SDPacket?ReadPacket(byte[] rawData)
        {
            if (rawData == null)
            {
                return(null);
            }
            if (rawData.Length < 20)
            {
                return(null);
            }
            uint dataLen = BitConverter.ToUInt16(rawData, 16);

            if (rawData.Length < 20 + dataLen)
            {
                return(null);
            }

            SDPacket packet = new SDPacket();

            packet.Data = new byte[dataLen];

            packet.PacketID  = BitConverter.ToUInt16(rawData, 0);
            packet.ServiceID = BitConverter.ToUInt16(rawData, 4);
            packet.Flags     = (SDFlags)BitConverter.ToUInt16(rawData, 8);
            packet.StateID   = BitConverter.ToUInt16(rawData, 12);
            packet.Length    = dataLen;
            Array.Copy(rawData, 20, packet.Data, 0, packet.Length);

            return(packet);
        }
Esempio n. 2
0
 public SDPacket DeriveNewPacket(SDPacket packet)
 {
     SDPacket newPacket = new SDPacket();
     newPacket.PacketID = packet.PacketID;
     newPacket.ServiceID = packet.ServiceID;
     return newPacket;
 }
Esempio n. 3
0
        public SDPacket DeriveNewPacket(SDPacket packet)
        {
            SDPacket newPacket = new SDPacket();

            newPacket.PacketID  = packet.PacketID;
            newPacket.ServiceID = packet.ServiceID;
            return(newPacket);
        }
Esempio n. 4
0
 public byte[] GetBytes(SDPacket packet)
 {
     byte[] data = new byte[20 + packet.Length];
     Array.Copy(BitConverter.GetBytes(packet.PacketID), 0, data, 0, 4);
     Array.Copy(BitConverter.GetBytes(packet.ServiceID), 0, data, 4, 4);
     Array.Copy(BitConverter.GetBytes((uint)packet.Flags), 0, data, 8, 4);
     Array.Copy(BitConverter.GetBytes(packet.StateID), 0, data, 12, 4);
     Array.Copy(BitConverter.GetBytes(packet.Length), 0, data, 16, 4);
     Array.Copy(packet.Data, 0, data, 20, packet.Length);
     return data;
 }
Esempio n. 5
0
 public byte[] GetBytes(SDPacket packet)
 {
     byte[] data = new byte[20 + packet.Length];
     Array.Copy(BitConverter.GetBytes(packet.PacketID), 0, data, 0, 4);
     Array.Copy(BitConverter.GetBytes(packet.ServiceID), 0, data, 4, 4);
     Array.Copy(BitConverter.GetBytes((uint)packet.Flags), 0, data, 8, 4);
     Array.Copy(BitConverter.GetBytes(packet.StateID), 0, data, 12, 4);
     Array.Copy(BitConverter.GetBytes(packet.Length), 0, data, 16, 4);
     Array.Copy(packet.Data, 0, data, 20, packet.Length);
     return(data);
 }
Esempio n. 6
0
        public SDPacket NewPacket(byte[] data, uint serviceID, int stateID, SDFlags flags)
        {
            SDPacket packet = new SDPacket();

            packet.PacketID  = 0;
            packet.ServiceID = serviceID;
            packet.Flags     = flags;
            packet.StateID   = stateID;
            if (data != null)
            {
                packet.Length = (uint)data.Length;
                packet.Data   = data;
            }
            return(packet);
        }
Esempio n. 7
0
        public SDPacket? ReadPacket(byte[] rawData)
        {
            if (rawData == null) return null;
            if (rawData.Length < 20) return null;
            uint dataLen = BitConverter.ToUInt16(rawData, 16);
            if (rawData.Length < 20 + dataLen) return null;

            SDPacket packet = new SDPacket();
            packet.Data = new byte[dataLen];

            packet.PacketID = BitConverter.ToUInt16(rawData, 0);
            packet.ServiceID = BitConverter.ToUInt16(rawData, 4);
            packet.Flags = (SDFlags)BitConverter.ToUInt16(rawData, 8);
            packet.StateID = BitConverter.ToUInt16(rawData, 12);
            packet.Length = dataLen;
            Array.Copy(rawData, 20, packet.Data, 0, packet.Length);

            return packet;
        }
Esempio n. 8
0
 public SDPacket NewPacket(byte[] data, uint serviceID, int stateID, SDFlags flags)
 {
     SDPacket packet = new SDPacket();
     packet.PacketID = 0;
     packet.ServiceID = serviceID;
     packet.Flags = flags;
     packet.StateID = stateID;
     if (data != null)
     {
         packet.Length = (uint)data.Length;
         packet.Data = data;
     }
     return packet;
 }