public void TLUintHydration() { var buffer4 = BitConverter.GetBytes(4); var buffer544 = BitConverter.GetBytes(544); int pos = 0; var int4 = new TLUint(buffer4, ref pos); pos = 0; var int544 = new TLUint(buffer544, ref pos); Assert.AreEqual(4U, int4.Value); Assert.AreEqual(544U, int544.Value); using (var stream = new MemoryStream()) { stream.Write(buffer4, 0, 4); stream.Write(buffer544, 0, 4); stream.Position = 0; pos = 0; var streamInt4 = new TLUint(stream, ref pos); var streamInt544 = new TLUint(stream, ref pos); Assert.AreEqual(4U, streamInt4.Value); Assert.AreEqual(544U, streamInt544.Value); } }
/// <summary> /// When called on a byte array, this method will read in the TLInt signature /// of the stream, and throw an exception if it doesn't match the expected /// signature. This will advance the position. /// </summary> /// <param name="input">The stream to operate on</param> /// <param name="position">The position in the stream to start reading at</param> /// <param name="signature">The signature to check for</param> public static void ThrowIfIncorrectSignature(this Stream input, ref int position, uint signature) { uint localSig = new TLUint(input, ref position).Value; if (localSig != signature) { throw new InvalidDataException(); } }