Ejemplo n.º 1
0
        public void Serialize_WhenFrameReqPqSerialized_ThenExpectedBytesReturned()
        {
            // arrange
            TLFrame <ReqPq> reqPq = new TLFrame <ReqPq>
            {
                AuthKey       = 0,
                MessageId     = 0,
                MessageLength = 20,
                Content       = new ReqPq
                {
                    Nonce = new byte[]
                    {
                        0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
                        0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10
                    }
                }
            };

            byte[] expectedBytes =
            {
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x14, 0x00, 0x00, 0x00,
                0x78, 0x97, 0x46, 0x60,
                0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
                0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10
            };

            // act
            byte[] result = _testee.Serialize(reqPq, null).ToArray();

            // assert
            result.ShouldBeEquivalentTo(expectedBytes);
        }
Ejemplo n.º 2
0
        public string Serialize(object parameter)
        {
            if (parameter == null)
            {
                return(null);
            }

            if (parameter is TLObject obj)
            {
                var buffer = TLObjectSerializer.Serialize(obj);
                var array  = buffer.ToArray();

                return(BitConverter.ToString(array).Replace("-", string.Empty));
            }

            return(SerializationService.Json.Serialize(parameter));
        }
Ejemplo n.º 3
0
        public static void SaveWithTempFile <T>(string fileName, T data) where T : TLObject
        {
            string text = fileName + ".temp";
            //using (var file = File.Open(GetFileName(text), FileMode.Create))
            //{
            //    using (var to = new TLBinaryWriter(file))
            //    {
            //        data.Write(to);
            //    }

            //}
            var buffer = TLObjectSerializer.Serialize(data);

            File.WriteAllBytes(GetFileName(text), buffer.ToArray());

            File.Copy(GetFileName(text), GetFileName(fileName), true);
        }