Ejemplo n.º 1
0
        public void WriteEmpty(SignalingAttribute attr)
        {
            serializer.SetBufferLength(0);

            serializer.Write((byte)attr);
            serializer.Write((ushort)0);

            attributeTypes.Add(attr);
            attributeBytes.Add(serializer.ToArray());
        }
Ejemplo n.º 2
0
        public object Get(SignalingAttribute attr)
        {
            if (!response.ContainsKey(attr))
            {
                return(null);
            }
            object value = response[attr];

            return(value);
        }
Ejemplo n.º 3
0
        public void WriteUInt(SignalingAttribute attr, uint value)
        {
            serializer.SetBufferLength(0);

            serializer.Write((byte)attr);
            serializer.Write((ushort)4);
            serializer.Write(value);

            attributeTypes.Add(attr);
            attributeBytes.Add(serializer.ToArray());
        }
Ejemplo n.º 4
0
        public void WriteBytes(SignalingAttribute attr, byte[] bytes)
        {
            serializer.SetBufferLength(0);
            serializer.Write((byte)attr);
            serializer.Write((ushort)bytes.Length);
            serializer.Write(bytes);

            //pad to multiple of 4
            PadTo32Bits(bytes.Length, serializer);

            attributeTypes.Add(attr);
            attributeBytes.Add(serializer.ToArray());
        }
Ejemplo n.º 5
0
        public void WriteBytes(SignalingAttribute attr, byte[] bytes)
        {
            serializer.SetBufferLength(0);
            serializer.Write((byte)attr);
            serializer.Write((ushort)bytes.Length);
            serializer.Write(bytes);

            //pad to multiple of 4
            PadTo32Bits(bytes.Length, serializer);

            Console.WriteLine("Attribute: " + Enum.GetName(typeof(SignalingAttribute), attr) + " = " + NetworkSerializer.ByteArrayToHexString((byte[])bytes));
            response.Add(attr, bytes);
            attributeTypes.Add(attr);
            attributeBytes.Add(serializer.ToArray());
        }
Ejemplo n.º 6
0
        public void WriteString(SignalingAttribute attr, string text)
        {
            serializer.SetBufferLength(0);

            int len = Encoding.UTF8.GetByteCount(text);

            serializer.Write((byte)attr);
            serializer.Write(text, len);

            //pad to multiple of 4
            PadTo32Bits(len, serializer);

            attributeTypes.Add(attr);
            attributeBytes.Add(serializer.ToArray());
        }
Ejemplo n.º 7
0
        private void LogAttribute(int index)
        {
            SignalingAttribute attr     = attributeTypes[index];
            string             valueStr = "";

            if (response.ContainsKey(attr))
            {
                object value = response[attr];

                if (value is string v)
                {
                    valueStr = v;
                }
                else if (value is byte[] b)
                {
                    valueStr = NetworkSerializer.ByteArrayToHexString(b);
                }
                else
                {
                    valueStr = value.ToString();
                }
            }
        }
Ejemplo n.º 8
0
        public void ReadAttribute()
        {
            Console.WriteLine("ReadAttribute");
            while (serializer.bytePos < serializer.byteLength)
            {
                SignalingAttribute attrType = (SignalingAttribute)serializer.ReadByte();
                attributeTypes.Add(attrType);

                switch (attrType)
                {
                case SignalingAttribute.RoomAddress:
                case SignalingAttribute.PeerAddress:
                    response.Add(attrType, ReadPeerAddress());
                    break;

                case SignalingAttribute.RoomName:
                case SignalingAttribute.RoomDescription:
                case SignalingAttribute.RoomTag:
                    response.Add(attrType, ReadString());
                    break;

                /*case SignalingAttribute.Room:
                 *  response.Add(attrType, ReadRoom());
                 *  break;*/
                default:
                    ushort attrLen = serializer.ReadUShort();
                    byte[] bytes   = serializer.ReadBytes(attrLen);
                    response.Add(attrType, bytes);
                    while (((attrLen++) % 4) != 0)
                    {
                        serializer.ReadByte();
                    }
                    break;
                }
            }
        }
Ejemplo n.º 9
0
        public void ReadAttribute()
        {
            List <IPEndPoint> roomAddressList     = new List <IPEndPoint>();
            List <string>     roomNameList        = new List <string>();
            List <string>     roomDescriptionList = new List <string>();
            List <Room>       roomList            = new List <Room>();
            string            name    = "";
            string            des     = "";
            IPEndPoint        address = null;
            int roomFieldCount        = 0;

            while (serializer.bytePos < serializer.byteLength)
            {
                SignalingAttribute attrType = (SignalingAttribute)serializer.ReadByte();
                attributeTypes.Add(attrType);

                switch (attrType)
                {
                case SignalingAttribute.PeerAddress:
                    response.Add(attrType, ReadPeerAddress());
                    break;

                case SignalingAttribute.RoomAddress:
                    //roomAddressList.Add(ReadPeerAddress());
                    roomFieldCount++;
                    address = ReadPeerAddress();
                    break;

                case SignalingAttribute.RoomName:
                    //roomNameList.Add(serializer.ReadString());
                    name = ReadString();
                    roomFieldCount++;
                    break;

                case SignalingAttribute.RoomDescription:
                    //roomDescriptionList.Add(serializer.ReadString());
                    des = ReadString();
                    roomFieldCount++;
                    break;

                case SignalingAttribute.Failed:
                    response.Add(attrType, false);
                    break;

                case SignalingAttribute.Success:
                    response.Add(attrType, true);
                    break;

                default:
                    ushort attrLen = serializer.ReadUShort();
                    byte[] bytes   = serializer.ReadBytes(attrLen);
                    response.Add(attrType, bytes);
                    while (((attrLen++) % 4) != 0)
                    {
                        serializer.ReadByte();
                    }
                    break;
                }
                if (roomFieldCount == 3)
                {
                    roomList.Add(new Room("", address, des, name));
                    roomFieldCount = 0;
                }
            }
            if (roomList.Count > 0)
            {
                response.Add(SignalingAttribute.Room, roomList);
            }
        }