Exemple #1
0
        public void TLIntHydration()
        {
            var buffer4 = BitConverter.GetBytes(4);
            var buffer544 = BitConverter.GetBytes(544);

            int pos = 0;
            var int4 = new TLInt(buffer4, ref pos);
            pos = 0;
            var int544 = new TLInt(buffer544, ref pos);

            Assert.AreEqual(4, int4.Value);
            Assert.AreEqual(544, 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 TLInt(stream, ref pos);
                var streamInt544 = new TLInt(stream, ref pos);

                Assert.AreEqual(4, streamInt4.Value);
                Assert.AreEqual(544, streamInt544.Value);
            }
        }
Exemple #2
0
 /// <summary>
 /// Given a signature to check for, this method will read in the TLint signature
 /// of the stream at the provided index and check if it matches. This does not
 /// 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>
 /// <returns>Whether or not the signature was found</returns>
 public static bool IsSignatureValid(this Stream input, int position, int signature)
 {
     int localSig = new TLInt(input, ref position).Value;
     input.Position -= 4; // Move the stream position back to its starting location
     return localSig == signature;
 }
Exemple #3
0
 /// <summary>
 /// Given a signature to check for, this method will read in the TLint signature
 /// of the buffer at the provided index and check if it matches. This does not
 /// advance the position.
 /// </summary>
 /// <param name="bytes">The buffer to operate on</param>
 /// <param name="position">The position in the buffer to start reading at</param>
 /// <param name="signature">The signature to check for</param>
 /// <returns>Whether or not the signature was found</returns>
 public static bool IsSignatureValid(this byte[] bytes, int position, int signature)
 {
     int localSig = new TLInt(bytes, ref position).Value;
     return localSig == signature;
 }
Exemple #4
0
        private void parse(ref int position, byte[] buffer = null, Stream input = null)
        {
            if (buffer == null && input == null) throw new InvalidDataException();

            switch (this.SIGNATURE)
            {
                case Signature.InputPeerEmpty:
                case Signature.InputPeerSelf:
                    break;

                case Signature.InputPeerForeign:
                    UserID = buffer == null ? new TLInt(input, ref position) : new TLInt(buffer, ref position);
                    AccessHash = buffer == null ? new TLLong(input, ref position) : new TLLong(buffer, ref position);
                    break;

                case Signature.InputPeerContact:
                    UserID = buffer == null ? new TLInt(input, ref position) : new TLInt(buffer, ref position);
                    break;

                case Signature.InputPeerChat:
                    ChatID = buffer == null ? new TLInt(input, ref position) : new TLInt(buffer, ref position);
                    break;
            }
        }