Ejemplo n.º 1
0
        private FPData CommonPeekHead(byte[] bytes)
        {
            if (bytes.Length == 12)
            {
                FPData data = this._pkg.PeekHead(bytes);

                if (!this.CheckHead(data))
                {
                    return(null);
                }

                if (this._pkg.IsOneWay(data))
                {
                    data.SetPkgLen(12 + data.GetSS() + data.GetPsize());
                }

                if (this._pkg.IsTwoWay(data))
                {
                    data.SetPkgLen(16 + data.GetSS() + data.GetPsize());
                }

                if (this._pkg.IsAnswer(data))
                {
                    data.SetPkgLen(16 + data.GetPsize());
                }

                data.Bytes = this._pkg.GetByteArrayRange(bytes, 0, bytes.Length - 1);
                return(data);
            }

            return(null);
        }
Ejemplo n.º 2
0
        private byte[] EnCodeTwoway(FPData data)
        {
            System.Text.ASCIIEncoding encoder = new System.Text.ASCIIEncoding();
            MemoryStream ms = this.BuildHeader(data, 16 + data.GetSS() + data.GetPsize());

            ms.WriteByte((byte)data.GetSS());

            byte[] psizeBytes = BitConverter.GetBytes(data.GetPsize());
            ms.Write(psizeBytes, 0, psizeBytes.Length);

            byte[] seqBytes = BitConverter.GetBytes(data.GetSeq());
            ms.Write(seqBytes, 0, seqBytes.Length);

            byte[] methodBytes = encoder.GetBytes(data.GetMethod());
            ms.Write(methodBytes, 0, methodBytes.Length);

            byte[] payloadBytes = null;

            if (this.IsJson(data))
            {
                payloadBytes = encoder.GetBytes(data.JsonPayload());
            }

            if (this.IsMsgPack(data))
            {
                payloadBytes = data.MsgpackPayload();
            }

            ms.Write(payloadBytes, 0, payloadBytes.Length);

            return(this.StreamToBytes(ms));
        }
Ejemplo n.º 3
0
        private byte[] EnCodeOneway(FPData data)
        {
            if (data != null)
            {
                System.Text.ASCIIEncoding encoder = new System.Text.ASCIIEncoding();
                MemoryStream ms = this.BuildHeader(data, 12 + data.GetSS() + data.GetPsize());
                ms.WriteByte((byte)data.GetSS());
                byte[] psizeBytes = BitConverter.GetBytes(data.GetPsize());
                ms.Write(psizeBytes, 0, psizeBytes.Length);
                string method      = (data.GetMethod() != null) ? data.GetMethod() : "";
                byte[] methodBytes = encoder.GetBytes(method);
                ms.Write(methodBytes, 0, methodBytes.Length);
                byte[] payloadBytes = null;

                if (this.IsJson(data))
                {
                    string json = (data.JsonPayload() != null) ? data.JsonPayload() : "";
                    payloadBytes = encoder.GetBytes(json);
                }

                if (this.IsMsgPack(data))
                {
                    payloadBytes = data.MsgpackPayload();
                }

                if (payloadBytes != null)
                {
                    ms.Write(payloadBytes, 0, payloadBytes.Length);
                }

                return(this.StreamToBytes(ms));
            }

            return(null);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        private bool DeCodeTwoWay(byte[] bytes, FPData data)
        {
            if (bytes.Length != 4 + data.GetSS() + data.GetPsize())
            {
                return(false);
            }

            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)));
            }

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

            return(true);
        }