예제 #1
0
        public void SignedEncodeNullableMax()
        {
            var coder = new HeliumIntegerSigned(0, true, 1);

            coder.Prepare(typeof(Int32));
            var encoded = coder.Encode(SignedVlq.MaxValue - 1);

            Assert.Equal(SignedVlq.Encode(SignedVlq.MaxValue).ToHexString(), encoded.ToHexString());
        }
예제 #2
0
        public void SignedDecodeMax()
        {
            var coder = new HeliumIntegerSigned(0, false, 1);

            coder.Prepare(typeof(UInt64));
            var decoded = coder.Decode(new DecodeBuffer(SignedVlq.Encode(SignedVlq.MaxValue).ToArray()));

            Assert.Equal(UnsignedVlq.MaxValue, decoded);
        }
예제 #3
0
        public void SignedEncodeMin()
        {
            var coder = new HeliumIntegerSigned(0, false, 1);

            coder.Prepare(typeof(Int32));
            var encoded = coder.Encode(SignedVlq.MinValue);

            Assert.Equal(SignedVlq.Encode(SignedVlq.MinValue).ToHexString(), encoded.ToHexString());
        }
예제 #4
0
        public void SignedDecodeNullableNull()
        {
            var coder = new HeliumIntegerSigned(0, true);

            coder.Prepare(typeof(Int32));
            var decoded = coder.Decode(new DecodeBuffer(SignedVlq.Encode(0).ToArray()));

            Assert.Equal((Int32?)null, decoded);
        }
예제 #5
0
        public void SignedDecodeNullableMin()
        {
            var coder = new HeliumIntegerSigned(0, true, 1);

            coder.Prepare(typeof(UInt64));
            var decoded = coder.Decode(new DecodeBuffer(SignedVlq.Encode(SignedVlq.MinValue).ToArray()));

            Assert.Equal(UnsignedVlq.MinValue + 1, decoded);
        }
예제 #6
0
        public void SignedDecodeZero()
        {
            var coder = new HeliumIntegerSigned(0, false);

            coder.Prepare(typeof(Int32));
            var decoded = coder.Decode(new DecodeBuffer(SignedVlq.Encode(0).ToArray()));

            Assert.Equal((Int32)0, decoded);
        }
예제 #7
0
        public void SignedVlqNeg100To100()
        {
            for (var i = -100; i < 100; i++)
            {
                var encoded = SignedVlq.Encode(i).ToArray();
                var output  = SignedVlq.Decode(encoded);

                Assert.Equal(i, output);
            }
        }
예제 #8
0
        public override Object Decode(DecodeBuffer input)
        {
            var v = SignedVlq.Decode(input);

            if (IsNullable)
            {
                if (v == 0)
                {
                    return(null);
                }
                v--;
            }
            v *= Increment;

            return(Convert.ChangeType(v, UnderlyingType));
        }
예제 #9
0
        public override EncodeBuffer Encode(Object value)
        {
            if (value == null && IsNullable)
            {
                return(Precomputed.Zero);
            }

            var v = Convert.ToInt64(value);

            v /= Increment;
            if (IsNullable)
            {
                v++;
            }

            return(new EncodeBuffer(SignedVlq.Encode(v)));
        }
예제 #10
0
 public void SInt64DeserializeEnum()
 {
     Assert.Equal(TestEnum.B, LightWeight.Deserialize <TestEnum>(SignedVlq.Encode((Int64)TestEnum.B).ToArray()));
 }
예제 #11
0
 public void SInt64DeserializeMax()
 {
     Assert.Equal(SignedVlq.MaxValue, LightWeight.Deserialize <Int64>(SignedVlq.Encode(SignedVlq.MaxValue).ToArray()));
 }
예제 #12
0
 public void SInt64Deserialize10()
 {
     Assert.Equal((Int64)10, LightWeight.Deserialize <Int64>(SignedVlq.Encode(10).ToArray()));
 }
예제 #13
0
 public void SInt64SerializeEnum()
 {
     Assert.Equal(SignedVlq.Encode((Int64)TestEnum.B), LightWeight.Serialize(TestEnum.B));
 }
예제 #14
0
 public void SInt64SerializeMax()
 {
     Assert.Equal(SignedVlq.Encode(SignedVlq.MaxValue), LightWeight.Serialize(SignedVlq.MaxValue));
 }
예제 #15
0
 public void SInt64SerializeZero()
 {
     Assert.Equal(SignedVlq.Encode(0), LightWeight.Serialize(0));
 }
예제 #16
0
 public Delegate GenerateEncoder(Type type, Func <Type, Delegate> recurse)
 {
     return(new Func <Int16, EncodeBuffer>(value => { return new EncodeBuffer(SignedVlq.Encode(value)); }));
 }
예제 #17
0
 public void SInt16DeserializeZero()
 {
     Assert.Equal((Int16)0, LightWeight.Deserialize <Int16>(SignedVlq.Encode(0).ToArray()));
 }
예제 #18
0
 public void SInt16DeserializeMin()
 {
     Assert.Equal(Int16.MinValue, LightWeight.Deserialize <Int16>(SignedVlq.Encode(Int16.MinValue).ToArray()));
 }
예제 #19
0
 public void SInt16SerializeMin()
 {
     Assert.Equal(SignedVlq.Encode(Int16.MinValue), LightWeight.Serialize(Int16.MinValue));
 }
예제 #20
0
        public void SignedVlqEncodeDecode32()
        {
            var encoded = SignedVlq.Encode(Int32.MaxValue).ToArray();

            Assert.Equal(Int32.MaxValue, SignedVlq.Decode(encoded));
        }
예제 #21
0
        public void SignedVlqEncodeDecodeA()
        {
            var encoded = SignedVlq.Encode(SignedVlq.MaxValue - Int32.MaxValue ^ 16).ToArray();

            Assert.Equal(SignedVlq.MaxValue - Int32.MaxValue ^ 16, SignedVlq.Decode(encoded));
        }