Example #1
0
        protected string readString(ushort pos, string p, int len = int.MaxValue)
        {
            PacketElement el = new PacketElement
            {
                name  = p,
                start = pos,
                type  = "string"
            };
            ushort        start  = pos;
            StringBuilder result = new StringBuilder();

            for (int i = start; i < len; i += 2)
            {
                char c = Convert.ToChar(BitConverter.ToUInt16(data, i));
                if (c == '\0')
                {
                    break;
                }
                else
                {
                    result.Append(c);
                }
            }
            el.value = result.ToString();
            this[p]  = el;
            return((string)el.value);
        }
Example #2
0
        protected sbyte readSByte(ushort pos, string p)
        {
            PacketElement el = new PacketElement
            {
                name  = p,
                start = pos,
                value = (sbyte)data[pos],
                type  = "sbyte"
            };

            this[p] = el;
            return((sbyte)el.value);
        }
Example #3
0
        protected char readChar(ushort pos, string p)
        {
            PacketElement el = new PacketElement
            {
                name  = p,
                start = pos,
                value = BitConverter.ToChar(data, pos),
                type  = "char"
            };

            this[p] = el;
            return((char)el.value);
        }
Example #4
0
        protected double readDouble(ushort pos, string p)
        {
            PacketElement el = new PacketElement
            {
                name  = p,
                start = pos,
                value = BitConverter.ToDouble(data, pos),
                type  = "double"
            };

            this[p] = el;
            return((double)el.value);
        }
Example #5
0
        protected float readSingle(ushort pos, string p)
        {
            PacketElement el = new PacketElement
            {
                name  = p,
                start = pos,
                value = BitConverter.ToSingle(data, pos),
                type  = "float"
            };

            this[p] = el;
            return((float)el.value);
        }
Example #6
0
        protected long readInt64(ushort pos, string p)
        {
            PacketElement el = new PacketElement
            {
                name  = p,
                start = pos,
                value = BitConverter.ToInt64(data, pos),
                type  = "long"
            };

            this[p] = el;
            return((long)el.value);
        }
Example #7
0
        protected int readInt32(ushort pos, string p)
        {
            PacketElement el = new PacketElement
            {
                name  = p,
                start = pos,
                value = BitConverter.ToInt32(data, pos),
                type  = "int"
            };

            this[p] = el;
            return((int)el.value);
        }
Example #8
0
        protected ushort readUInt16(ushort pos, string p)
        {
            PacketElement el = new PacketElement
            {
                name  = p,
                start = pos,
                value = BitConverter.ToUInt16(data, pos),
                type  = "ushort"
            };

            this[p] = el;
            return((ushort)el.value);
        }
Example #9
0
        protected System.Collections.BitArray readBitArray(ushort pos, string p)
        {
            PacketElement el = new PacketElement
            {
                name  = p,
                start = pos,
                value = new System.Collections.BitArray(new byte[1] {
                    data[pos]
                }),
                type = "bitarray"
            };

            this[p] = el;
            return((System.Collections.BitArray)el.value);
        }
Example #10
0
        protected string readHex(ushort pos, string p, int lenght)
        {
            PacketElement el = new PacketElement
            {
                name  = p,
                start = pos,
                type  = "hex"
            };
            StringBuilder result = new StringBuilder();

            for (int i = 0; i < lenght; i++)
            {
                result.AppendFormat("{0:X2}", data[i]);
            }
            el.value = result.ToString();
            this[p]  = el;
            return((string)el.value);
        }
Example #11
0
        protected bool readBoolean(ushort pos, string p, byte s = 0)
        {
            if (s > 7)
            {
                return(false);
            }
            var temp = new System.Collections.BitArray(new byte[1] {
                data[pos]
            });
            PacketElement el = new PacketElement
            {
                name  = p,
                start = pos,
                value = temp[s],
                shift = s,
                type  = "boolean"
            };

            this[p] = el;
            return((bool)el.value);
        }