示例#1
0
        private void PushService(FPData quest)
        {
            lock (self_locker) {
                FPClient self = this;
                this._psr.Service(quest, (payload, exception) => {
                    FPData data = new FPData();
                    data.SetFlag(quest.GetFlag());
                    data.SetMtype(0x2);
                    data.SetSeq(quest.GetSeq());
                    data.SetSS(exception ? 1 : 0);

                    if (quest.GetFlag() == 0)
                    {
                        data.SetPayload(Convert.ToString(payload));
                    }

                    if (quest.GetFlag() == 1)
                    {
                        data.SetPayload((byte[])payload);
                    }

                    self.SendQuest(data);
                });
            }
        }
        private bool DeCodeAnswer(byte[] bytes, FPData data)
        {
            if (bytes.Length != 4 + data.GetPsize())
            {
                return(false);
            }

            data.SetSeq((int)BitConverter.ToUInt32(this.GetByteArrayRange(bytes, 0, 3), 0));

            if (this.IsJson(data))
            {
                data.SetPayload(this.GetString(this.GetByteArrayRange(bytes, 4, bytes.Length - 1)));
            }

            if (this.IsMsgPack(data))
            {
                data.SetPayload(this.GetByteArrayRange(bytes, 4, bytes.Length - 1));
            }

            return(true);
        }
        private bool DeCodeOneWay(byte[] bytes, FPData data)
        {
            if (bytes.Length != data.GetSS() + data.GetPsize())
            {
                return(false);
            }

            data.SetMethod(this.GetString(this.GetByteArrayRange(bytes, 0, data.GetSS() - 1)));

            if (this.IsJson(data))
            {
                data.SetPayload(this.GetString(this.GetByteArrayRange(bytes, data.GetSS(), bytes.Length - 1)));
            }

            if (this.IsMsgPack(data))
            {
                data.SetPayload(this.GetByteArrayRange(bytes, data.GetSS(), bytes.Length - 1));
            }

            return(true);
        }
        private bool DeCodeTwoWay(byte[] bytes, FPData data)
        {
            if (bytes != null && (bytes.Length == 4 + data.GetSS() + data.GetPsize()))
            {
                data.SetSeq((int)BitConverter.ToUInt32(this.GetByteArrayRange(bytes, 0, 3), 0));
                data.SetMethod(this.GetString(this.GetByteArrayRange(bytes, 4, data.GetSS() + 4 - 1)));

                if (this.IsJson(data))
                {
                    data.SetPayload(this.GetString(this.GetByteArrayRange(bytes, 4 + data.GetSS(), bytes.Length - 1)));
                    return(true);
                }

                if (this.IsMsgPack(data))
                {
                    data.SetPayload(this.GetByteArrayRange(bytes, 4 + data.GetSS(), bytes.Length - 1));
                    return(true);
                }
            }

            return(false);
        }