/// <summary> /// Create object from segment in byte array /// </summary> public Root FromBytes(byte[] bytes, ref int index) { // Read Number Number = GeneratorByteConverter.ToInt32(bytes, ref index); // Read Price Price = GeneratorByteConverter.ToDouble(bytes, ref index); // Read Description Description = GeneratorByteConverter.GetString(bytes, ref index); // Read PartialsList var partialslistLength = GeneratorByteConverter.ToUInt16(bytes, ref index); var tempPartialsList = new List <Partial>(partialslistLength); for (var i = 0; i < partialslistLength; i++) { var value = new Partial().FromBytes(bytes, ref index); tempPartialsList.Add(value); } PartialsList = tempPartialsList; // Read PartialsArray var partialsarrayLength = GeneratorByteConverter.ToUInt16(bytes, ref index); var tempPartialsArray = new Partial[partialsarrayLength]; for (var i = 0; i < partialsarrayLength; i++) { var value = new Partial().FromBytes(bytes, ref index); tempPartialsArray[i] = value; } PartialsArray = tempPartialsArray; // Read SmallNumber SmallNumber = GeneratorByteConverter.ToUInt16(bytes, ref index); return(this); }
/// <summary> /// Create object from segment in byte array /// </summary> public Partial FromBytes(byte[] bytes, ref int index) { // Read Id Id = GeneratorByteConverter.ToInt64(bytes, ref index); // Read Price Price = GeneratorByteConverter.ToSingle(bytes, ref index); // Read Name Name = GeneratorByteConverter.GetString(bytes, ref index); // Read DecimalNumbers var decimalnumbersLength = GeneratorByteConverter.ToUInt16(bytes, ref index); var tempDecimalNumbers = new List <double>(decimalnumbersLength); for (var i = 0; i < decimalnumbersLength; i++) { var value = GeneratorByteConverter.ToDouble(bytes, ref index); tempDecimalNumbers.Add(value); } DecimalNumbers = tempDecimalNumbers; // Read SomeNumbers var somenumbersLength = GeneratorByteConverter.ToUInt16(bytes, ref index); var tempSomeNumbers = new List <ulong>(somenumbersLength); for (var i = 0; i < somenumbersLength; i++) { var value = GeneratorByteConverter.ToUInt64(bytes, ref index); tempSomeNumbers.Add(value); } SomeNumbers = tempSomeNumbers; return(this); }
/// <summary> /// Create object from segment in byte array /// </summary> public SmallNumeric FromBytes(byte[] bytes, ref int index) { // Read Index Index = GeneratorByteConverter.ToUInt16(bytes, ref index); // Read Value Value = GeneratorByteConverter.ToInt32(bytes, ref index); return(this); }
/// <summary> /// Convert object to bytes within object tree /// </summary> public byte[] ToBytes(byte[] bytes, ref int index) { if (index + Size > bytes.Length) { throw new ArgumentOutOfRangeException("index", "Object does not fit in array"); } // Convert Index GeneratorByteConverter.Include(Index, bytes, ref index); // Convert Value GeneratorByteConverter.Include(Value, bytes, ref index); return(bytes); }
/// <summary> /// Convert object to bytes within object tree /// </summary> public byte[] ToBytes(byte[] bytes, ref int index) { if (index + Size > bytes.Length) { throw new ArgumentOutOfRangeException("index", "Object does not fit in array"); } // Convert Number GeneratorByteConverter.Include(Number, bytes, ref index); // Convert Price GeneratorByteConverter.Include(Price, bytes, ref index); // Convert Description GeneratorByteConverter.Include(Description, bytes, ref index); // Convert PartialsList // Two bytes length information for each dimension GeneratorByteConverter.Include((ushort)(PartialsList == null ? 0 : PartialsList.Count), bytes, ref index); if (PartialsList != null) { for (var i = 0; i < PartialsList.Count; i++) { var value = PartialsList[i]; value.ToBytes(bytes, ref index); } } // Convert PartialsArray // Two bytes length information for each dimension GeneratorByteConverter.Include((ushort)(PartialsArray == null ? 0 : PartialsArray.Length), bytes, ref index); if (PartialsArray != null) { for (var i = 0; i < PartialsArray.Length; i++) { var value = PartialsArray[i]; value.ToBytes(bytes, ref index); } } // Convert SmallNumber GeneratorByteConverter.Include(SmallNumber, bytes, ref index); return(bytes); }
/// <summary> /// Convert object to bytes within object tree /// </summary> public byte[] ToBytes(byte[] bytes, ref int index) { if (index + Size > bytes.Length) { throw new ArgumentOutOfRangeException("index", "Object does not fit in array"); } // Convert Id GeneratorByteConverter.Include(Id, bytes, ref index); // Convert Price GeneratorByteConverter.Include(Price, bytes, ref index); // Convert Name GeneratorByteConverter.Include(Name, bytes, ref index); // Convert DecimalNumbers // Two bytes length information for each dimension GeneratorByteConverter.Include((ushort)(DecimalNumbers == null ? 0 : DecimalNumbers.Count), bytes, ref index); if (DecimalNumbers != null) { for (var i = 0; i < DecimalNumbers.Count; i++) { var value = DecimalNumbers[i]; GeneratorByteConverter.Include(value, bytes, ref index); } } // Convert SomeNumbers // Two bytes length information for each dimension GeneratorByteConverter.Include((ushort)(SomeNumbers == null ? 0 : SomeNumbers.Count()), bytes, ref index); if (SomeNumbers != null) { foreach (var value in SomeNumbers) { GeneratorByteConverter.Include(value, bytes, ref index); } } return(bytes); }