Exemplo n.º 1
0
        private IAWObject UnrollDictionary(Hashtable dict)
        {
            IAWObject   iSFSObject = AWObject.NewInstance();
            IEnumerator enumerator = dict.Keys.GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    string        text           = (string)enumerator.Current;
                    AWDataWrapper sFSDataWrapper = this.WrapField(dict[text]);
                    if (sFSDataWrapper == null)
                    {
                        throw new AWCodecError(string.Concat(new object[]
                        {
                            "Cannot serialize field of dictionary with key: ",
                            text,
                            ", ",
                            dict[text],
                            " -- unsupported type!"
                        }));
                    }
                    iSFSObject.Put(text, sFSDataWrapper);
                }
            }
            finally
            {
                IDisposable disposable;
                if ((disposable = (enumerator as IDisposable)) != null)
                {
                    disposable.Dispose();
                }
            }
            return(iSFSObject);
        }
Exemplo n.º 2
0
        public IAWObject Cs2Sfs(object csObj)
        {
            IAWObject iSFSObject = AWObject.NewInstance();

            this.ConvertCsObj(csObj, iSFSObject);
            return(iSFSObject);
        }
Exemplo n.º 3
0
 public BaseRequest(int id)
 {
     this.sfso             = AWObject.NewInstance();
     this.targetController = 0;
     this.isEncrypted      = false;
     this.id = id;
 }
Exemplo n.º 4
0
 public BaseRequest(RequestType tp)
 {
     this.sfso             = AWObject.NewInstance();
     this.targetController = 0;
     this.isEncrypted      = false;
     this.id = (int)tp;
 }
Exemplo n.º 5
0
        private IAWObject PrepareTCPPacket(IMessage message)
        {
            IAWObject iSFSObject = new AWObject();

            iSFSObject.PutByte(AWProtocolCodec.CONTROLLER_ID, Convert.ToByte(message.TargetController));
            iSFSObject.PutShort(AWProtocolCodec.ACTION_ID, Convert.ToInt16(message.Id));
            iSFSObject.PutSFSObject(AWProtocolCodec.PARAM_ID, message.Content);
            return(iSFSObject);
        }
Exemplo n.º 6
0
        private void ConvertCsObj(object csObj, IAWObject sfsObj)
        {
            Type   type     = csObj.GetType();
            string fullName = type.FullName;

            if (!(csObj is SerializableAWType))
            {
                throw new AWCodecError(string.Concat(new object[]
                {
                    "Cannot serialize object: ",
                    csObj,
                    ", type: ",
                    fullName,
                    " -- It doesn't implement the SerializableAWType interface"
                }));
            }
            IAWArray iSFSArray = AWArray.NewInstance();

            sfsObj.PutUtfString(DefaultAWDataSerializer.CLASS_MARKER_KEY, fullName);
            sfsObj.PutSFSArray(DefaultAWDataSerializer.CLASS_FIELDS_KEY, iSFSArray);
            FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
            FieldInfo[] array  = fields;
            for (int i = 0; i < array.Length; i++)
            {
                FieldInfo     fieldInfo      = array[i];
                string        name           = fieldInfo.Name;
                object        value          = fieldInfo.GetValue(csObj);
                IAWObject     iSFSObject     = AWObject.NewInstance();
                AWDataWrapper sFSDataWrapper = this.WrapField(value);
                if (sFSDataWrapper == null)
                {
                    throw new AWCodecError(string.Concat(new object[]
                    {
                        "Cannot serialize field of object: ",
                        csObj,
                        ", field: ",
                        name,
                        ", type: ",
                        fieldInfo.GetType().Name,
                        " -- unsupported type!"
                    }));
                }
                iSFSObject.PutUtfString(DefaultAWDataSerializer.FIELD_NAME_KEY, name);
                iSFSObject.Put(DefaultAWDataSerializer.FIELD_VALUE_KEY, sFSDataWrapper);
                iSFSArray.AddSFSObject(iSFSObject);
            }
        }
Exemplo n.º 7
0
        private IAWObject DecodeSFSObject(ByteArray buffer)
        {
            AWObject sFSObject = AWObject.NewInstance();
            byte     b         = buffer.ReadByte();

            if (b != Convert.ToByte(18))
            {
                throw new AWCodecError(string.Concat(new object[]
                {
                    "Invalid AWDataType. Expected: ",
                    AWDataType.SFS_OBJECT,
                    ", found: ",
                    b
                }));
            }
            int num = (int)buffer.ReadShort();

            if (num < 0)
            {
                throw new AWCodecError("Can't decode AWObject. Size is negative: " + num);
            }
            try
            {
                for (int i = 0; i < num; i++)
                {
                    string        text           = buffer.ReadUTF();
                    AWDataWrapper sFSDataWrapper = this.DecodeObject(buffer);
                    if (sFSDataWrapper == null)
                    {
                        throw new AWCodecError("Could not decode value for AWObject with key: " + text);
                    }
                    sFSObject.Put(text, sFSDataWrapper);
                }
            }
            catch (AWCodecError sFSCodecError)
            {
                throw sFSCodecError;
            }
            return(sFSObject);
        }
Exemplo n.º 8
0
        public void OnPacketRead(ByteArray packet)
        {
            IAWObject requestObject = AWObject.NewFromBinaryData(packet);

            this.DispatchRequest(requestObject);
        }