Exemplo n.º 1
0
        public void FloorSerializeMin()
        {
            var encoded = LightWeight.Serialize(new One()
            {
                U8  = 5,
                U16 = 5,
                U32 = 5,
                U64 = 5,
                S8  = 5,
                S16 = 5,
                S32 = 5,
                S64 = 5
            });

            Assert.Equal(new Byte[] {
                0x09,  // HEADER Length=8
                0x00,  // [U8]=5
                0x00,  // [U16]=5
                0x00,  // [U32]=5
                0x00,  // [U64]=5
                0x00,  // [S8]=5
                0x00,  // [S16]=5
                0x00,  // [S32]=5
                0x00,  // [S64]=5
            }.ToHexString(), encoded.ToHexString());
        }
Exemplo n.º 2
0
        public void FloorSerializeMinPlus1()
        {
            var encoded = LightWeight.Serialize(new One()
            {
                U8  = 6,
                U16 = 6,
                U32 = 6,
                U64 = 6,
                S8  = 6,
                S16 = 6,
                S32 = 6,
                S64 = 6
            });

            Assert.Equal(new Byte[] {
                0x09,  // HEADER Length=8
                0x01,  // [U8]=6
                0x01,  // [U16]=6
                0x01,  // [U32]=6
                0x01,  // [U64]=6
                0x01,  // [S8]=6  TODO: need to check this value is correct
                0x02,  // [S16]=6
                0x02,  // [S32]=6
                0x02,  // [S64]=6
            }.ToHexString(), encoded.ToHexString());
        }
Exemplo n.º 3
0
        public void DictionarySerializeNested()
        {
            var serialized = LightWeight.Serialize(new Dictionary <UInt32, Dictionary <UInt32, String> > {
                {
                    1, new Dictionary <UInt32, String> {
                        { 2, "cake" },
                        { 3, "food" }
                    }
                }, {
                    2, new Dictionary <UInt32, String> {
                        { 4, "fork" },
                        { 5, "food" }
                    }
                }
            });

            Assert.Equal(new Byte[] {
                0x03,                                             // HEADER Count=2
                0x01,                                             // 1=U
                0x03,                                             //     HEADER Count=2
                0x02,                                             //     2=
                0x05, (Byte)'c', (Byte)'a', (Byte)'k', (Byte)'e', // cake
                0x03,                                             //     3=
                0x05, (Byte)'f', (Byte)'o', (Byte)'o', (Byte)'d', // food
                0x02,                                             // 2=
                0x03,                                             //     HEADER Count=2
                0x04,                                             //     4=
                0x05, (Byte)'f', (Byte)'o', (Byte)'r', (Byte)'k', // fork
                0x05,                                             //     5=
                0x05, (Byte)'f', (Byte)'o', (Byte)'o', (Byte)'d', // food
            }.ToHexString(), serialized.ToHexString());
        }
Exemplo n.º 4
0
        public void ClassSerializeNull()
        {
            var encoded = LightWeight.Serialize <One>(null);

            Assert.Equal(new Byte[] {
                0x00  // HEADER NULL
            }, encoded);
        }
Exemplo n.º 5
0
        public void ListSerializeNull()
        {
            var encoded = LightWeight.Serialize <List <Int32> >(null);

            Assert.Equal(new Byte[] {
                0x00 // HEADER Null
            }, encoded);
        }
Exemplo n.º 6
0
        public void ArraySerializeNull1()
        {
            var encoded = LightWeight.Serialize <Boolean[]>(null);

            Assert.Equal(new Byte[] {
                0x00 // HEADER NULL
            }, encoded);
        }
Exemplo n.º 7
0
        public void ArraySerializeEmpty()
        {
            var encoded = LightWeight.Serialize(new Int32[] { });

            Assert.Equal(new Byte[] {
                0x01 // HEADER Count=0
            }, encoded);
        }
Exemplo n.º 8
0
        public void ListSerializeEmpty()
        {
            var encoded = LightWeight.Serialize(new List <Int32>());

            Assert.Equal(new Byte[] {
                0x01 // HEADER Count=0
            }, encoded);
        }
Exemplo n.º 9
0
        public void DictionarySerializeEmpty()
        {
            var encoded = LightWeight.Serialize(new Dictionary <Int32, String>());

            Assert.Equal(new Byte[] {
                0x01 // HEADER Count=0
            }, encoded);
        }
Exemplo n.º 10
0
        public void DictionarySerializeNull()
        {
            var encoded = LightWeight.Serialize <Dictionary <Int32, String> >(null);

            Assert.Equal(new Byte[] {
                0x00 // HEADER NULL
            }, encoded);
        }
Exemplo n.º 11
0
        public void ArraySerializeNull2()
        {
            var encoded = LightWeight.Serialize(new ArrayNullClass());

            Assert.Equal(new Byte[] {
                0x02, // HEADER Length=1
                0x00  //     HEADER NULL
            }, encoded);
        }
Exemplo n.º 12
0
 public void FloorSerializeUnsupported()
 {
     Assert.Throws <UnsupportedDataTypeException>(() =>
     {
         LightWeight.Serialize(new Unsupported()
         {
             ValueString = "asdf"
         });
     });
 }
Exemplo n.º 13
0
        public void ArraySerializeSInt32()
        {
            var serialized = LightWeight.Serialize(new UInt32[] { 1, 2, 1000 });

            Assert.Equal(new Byte[] {
                0x04,      // HEADER Count=3
                0x01,      // [0]=1
                0x02,      // [1]=2
                0xE8, 0x06 // [2]=1000
            }, serialized);
        }
Exemplo n.º 14
0
        public void ArraySerializeBoolean()
        {
            var serialized = LightWeight.Serialize(new[] { true, true, false });

            Assert.Equal(new Byte[] {
                0x04, // HEADER Length=3
                0x01, // [0]=true
                0x01, // [1]=true,
                0x00  // [2]=false
            }, serialized);
        }
Exemplo n.º 15
0
        public void ArraySerializeString()
        {
            var serialized = LightWeight.Serialize(new[] { "a", "bc", "def", "", null });

            Assert.Equal(new Byte[] {
                0x06,                                  // HEADER Length=5
                0x02, (Byte)'a',                       // [0]=a
                0x03, (Byte)'b', (Byte)'c',            // [1]=bc
                0x04, (Byte)'d', (Byte)'e', (Byte)'f', // [2]=def
                0x01,                                  // [3]=
                0x00                                   // [4]=NULL
            }, serialized);
        }
Exemplo n.º 16
0
        public void ClassSerializeEmpty()
        {
            var encoded = LightWeight.Serialize(new NoIndexs
            {
                A = 1,
                B = 9,
                C = 1000
            });

            Assert.Equal(new Byte[] {
                0x01  // HEADER Length=0
            }, encoded);
        }
Exemplo n.º 17
0
        public void ListSerializeInt32()
        {
            var encoded = LightWeight.Serialize(new List <UInt32> {
                1, 2, 1000
            });

            Assert.Equal(new Byte[] {
                0x04,      // HEADER Count=3
                0x01,      // [0]=1,
                0x02,      // [1]=2,
                0xE8, 0x06 // [2]=1000
            }, encoded);
        }
Exemplo n.º 18
0
        public void DictionarySerializeUInt32String()
        {
            var encoded = LightWeight.Serialize(new Dictionary <UInt32, String>()
            {
                { 1, "a" },
                { 2, "b" }
            });

            Assert.Equal(new Byte[] {
                0x03,            // HEADER Count=2
                0x01,            // 1=
                0x02, (Byte)'a', // "a"
                0x02,            // 2=
                0x02, (Byte)'b'  // "b"
            }, encoded);
        }
Exemplo n.º 19
0
        public void ClassSerializeBasic()
        {
            var encoded = LightWeight.Serialize(new One
            {
                A = 1,
                B = 9,
                C = 1000
            });

            Assert.Equal(new Byte[] {
                0x05,       // HEADER Length=4
                0x09,       // [A]=9
                0x01,       // [B]=1
                0xE8, 0x06, // [C]=1000
            }, encoded);
        }
Exemplo n.º 20
0
        public void ClassSerializeNested()
        {
            var encoded = LightWeight.Serialize(new Two
            {
                Y = "test",
                Z = new One
                {
                    A = 1,
                    B = 9,
                    C = 1000
                }
            });

            Assert.Equal(new Byte[] {
                11,                                            // HEADER Length=10
                5, (Byte)'t', (Byte)'e', (Byte)'s', (Byte)'t', // [A]=test
                5,                                             //     HEADER Length=4
                0x09,                                          //     [A]=9
                0x01,                                          //     [B]=1
                0xE8, 0x06                                     // [C]=1000
            }, encoded);
        }
Exemplo n.º 21
0
 public void SingleSerializeMin()
 {
     Assert.Equal(BitConverter.GetBytes(Single.MinValue), LightWeight.Serialize(Single.MinValue));
 }
Exemplo n.º 22
0
 public void UInt32SerializeEnum()
 {
     Assert.Equal(UnsignedVlq.Encode((UInt32)TestEnum.B), LightWeight.Serialize(TestEnum.B));
 }
Exemplo n.º 23
0
 public void UInt32SerializeMax()
 {
     Assert.Equal(UnsignedVlq.Encode(UInt32.MaxValue), LightWeight.Serialize(UInt32.MaxValue));
 }
Exemplo n.º 24
0
 public void SInt64SerializeEnum()
 {
     Assert.Equal(SignedVlq.Encode((Int64)TestEnum.B), LightWeight.Serialize(TestEnum.B));
 }
Exemplo n.º 25
0
 public void SInt64SerializeMax()
 {
     Assert.Equal(SignedVlq.Encode(SignedVlq.MaxValue), LightWeight.Serialize(SignedVlq.MaxValue));
 }
Exemplo n.º 26
0
 public void SInt64SerializeZero()
 {
     Assert.Equal(SignedVlq.Encode(0), LightWeight.Serialize(0));
 }
Exemplo n.º 27
0
 public void BooleanSerializeTrue()
 {
     Assert.Equal(UnsignedVlq.Encode(1), LightWeight.Serialize(true));
 }
Exemplo n.º 28
0
 public void BooleanSerializeFalse()
 {
     Assert.Equal(UnsignedVlq.Encode(0), LightWeight.Serialize(false));
 }
Exemplo n.º 29
0
 public void SInt16SerializeMin()
 {
     Assert.Equal(SignedVlq.Encode(Int16.MinValue), LightWeight.Serialize(Int16.MinValue));
 }
Exemplo n.º 30
0
 public void UInt64SerializeMin()
 {
     Assert.Equal(UnsignedVlq.Encode(UnsignedVlq.MinValue), LightWeight.Serialize(UnsignedVlq.MinValue));
 }