/// <summary> /// Append another Data object to this array /// </summary> /// <param name="data">The object do append</param> /// <returns>Return itself</returns> public DataArray AddData(Data data) { if (Format != data.Format) { throw new FormatException("Data element must match the DataArray format: '" + data.Format + "' was given, '" + Format + "' was expected"); } Buffer.Append(data.Buffer); Length++; return(this); }
/// <summary> /// Append something to the Data object /// </summary> /// <param name="u">An unsigned integer</param> /// <returns>Return itself</returns> public Data AddUint(ulong u) { // Validates the input if (u >= Data.MAX_UINT_8_B) { throw new ArgumentOutOfRangeException("Expected a value lower than 2^56"); } // First byte if (u < Data.MAX_UINT_1_B) { Buffer.Append((byte)(Data.OFFSET_1_B + (u & Data.MASK_7_B))); u = 0; } else if (u < Data.MAX_UINT_2_B) { Buffer.Append((byte)(Data.OFFSET_2_B + (u & Data.MASK_6_B))); u >>= 6; } else if (u < Data.MAX_UINT_3_B) { Buffer.Append((byte)(Data.OFFSET_3_B + (u & Data.MASK_5_B))); u >>= 5; } else if (u < Data.MAX_UINT_4_B) { Buffer.Append((byte)(Data.OFFSET_4_B + (u & Data.MASK_4_B))); u >>= 4; } else if (u < Data.MAX_UINT_5_B) { Buffer.Append((byte)(Data.OFFSET_5_B + (u & Data.MASK_3_B))); u >>= 3; } else if (u < Data.MAX_UINT_6_B) { Buffer.Append((byte)(Data.OFFSET_6_B + (u & Data.MASK_2_B))); u >>= 2; } else if (u < Data.MAX_UINT_7_B) { Buffer.Append((byte)(Data.OFFSET_7_B + (u & Data.MASK_1_B))); u >>= 1; } else { Buffer.Append(Data.OFFSET_8_B); } // Other bytes while (u != 0) { Buffer.Append((byte)u); u >>= 8; } Format += "u"; return(this); }