Example #1
0
        /// <summary>
        /// Turns the current Helper into a serialized byte array
        /// </summary>
        public byte[] Serialize()
        {
            using (var memory = new MemoryStream())
                using (var writer = new BinaryWriter(memory))
                {
                    if (AuthInfo == null)
                    {
                        BoolUtil.Serialize(false, writer);
                    }
                    else
                    {
                        BoolUtil.Serialize(true, writer);

                        if (AuthInfo.AuthKey == null)
                        {
                            BoolUtil.Serialize(false, writer);
                        }
                        else
                        {
                            BoolUtil.Serialize(true, writer);
                            BytesUtil.Serialize(AuthInfo.AuthKey.Key, writer);
                        }

                        IntegerUtil.Serialize(AuthInfo.TimeOffset, writer);
                    }

                    return(memory.ToArray());
                }
        }
Example #2
0
        /// <summary>
        /// Turns the current session into a serialized byte array
        /// </summary>
        public byte[] Serialize()
        {
            using var memory = new MemoryStream();
            using var writer = new BinaryWriter(memory);

            if (Helper == null)
            {
                BoolUtil.Serialize(false, writer);
            }
            else
            {
                BoolUtil.Serialize(true, writer);
                BytesUtil.Serialize(Helper.Serialize(), writer);
            }

            if (TLUser == null)
            {
                BoolUtil.Serialize(false, writer);
            }
            else
            {
                BoolUtil.Serialize(true, writer);
                TLUser.Serialize(writer);
            }

            IntegerUtil.Serialize(SessionExpires, writer);

            if (DataCenter == null)
            {
                BoolUtil.Serialize(false, writer);
            }
            else
            {
                BoolUtil.Serialize(true, writer);
                BytesUtil.Serialize(DataCenter.Serialize(), writer);
            }

            BytesUtil.Serialize(KnownPeers.Serialize(), writer);

            return(memory.ToArray());
        }