コード例 #1
0
        public void process(byte[] bytes)
        {
            if (bytes.Length != 12)
            {
                return;
            }

            if (BitConverter.IsLittleEndian)
            {
                this.Quantity = BinaryQuotes.Reverse(BitConverter.ToUInt32(bytes, 0));
                this.Price    = BinaryQuotes.Reverse(BitConverter.ToUInt32(bytes, 4));
                this.Orders   = BinaryQuotes.Reverse(BitConverter.ToUInt32(bytes, 8));
            }
            else
            {
                this.Quantity = BitConverter.ToUInt32(bytes, 0);
                this.Price    = BitConverter.ToUInt32(bytes, 4);
                this.Orders   = BitConverter.ToUInt32(bytes, 8);
            }
        }
コード例 #2
0
        public static BinaryQuotes[] Parse(byte[] data)
        {
            if (data == null)
            {
                return(null);
            }

            if (data.Length < 2)
            {
                return(null);
            }

            short noOfPackets = BitConverter.ToInt16(data, 0);

            List <BinaryQuotes> list = new List <BinaryQuotes>();
            int position             = 2;

            while (true)
            {
                if (data.Length < position + 2)
                {
                    break;
                }

                ushort bytesLen = BitConverter.IsLittleEndian ? Reverse(BitConverter.ToUInt16(data, position)) : BitConverter.ToUInt16(data, position);
                position += 2;

                if (data.Length < position + bytesLen)
                {
                    break;
                }

                byte[] b = new byte[bytesLen];
                Array.Copy(data, position, b, 0, b.Length);


                BinaryQuotes quote = null;

                if (bytesLen == 8)
                {
                    quote = new Ltp();
                }
                else if (bytesLen == 32)
                {
                    quote = new Indices();
                }
                else if (bytesLen == 44)
                {
                    quote = new Level1();
                }
                else if (bytesLen == 184)
                {
                    quote = new Level2();
                }

                if (quote != null)
                {
                    quote.Processs(b);

                    list.Add(quote);
                }

                position += bytesLen;
            }

            if (list.Count == 0)
            {
                return(null);
            }

            return(list.ToArray());
        }