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