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()); }
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); }
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()); }
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); }
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); }
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); }
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); } }
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)); }
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))); }
public void SInt64DeserializeEnum() { Assert.Equal(TestEnum.B, LightWeight.Deserialize <TestEnum>(SignedVlq.Encode((Int64)TestEnum.B).ToArray())); }
public void SInt64DeserializeMax() { Assert.Equal(SignedVlq.MaxValue, LightWeight.Deserialize <Int64>(SignedVlq.Encode(SignedVlq.MaxValue).ToArray())); }
public void SInt64Deserialize10() { Assert.Equal((Int64)10, LightWeight.Deserialize <Int64>(SignedVlq.Encode(10).ToArray())); }
public void SInt64SerializeEnum() { Assert.Equal(SignedVlq.Encode((Int64)TestEnum.B), LightWeight.Serialize(TestEnum.B)); }
public void SInt64SerializeMax() { Assert.Equal(SignedVlq.Encode(SignedVlq.MaxValue), LightWeight.Serialize(SignedVlq.MaxValue)); }
public void SInt64SerializeZero() { Assert.Equal(SignedVlq.Encode(0), LightWeight.Serialize(0)); }
public Delegate GenerateEncoder(Type type, Func <Type, Delegate> recurse) { return(new Func <Int16, EncodeBuffer>(value => { return new EncodeBuffer(SignedVlq.Encode(value)); })); }
public void SInt16DeserializeZero() { Assert.Equal((Int16)0, LightWeight.Deserialize <Int16>(SignedVlq.Encode(0).ToArray())); }
public void SInt16DeserializeMin() { Assert.Equal(Int16.MinValue, LightWeight.Deserialize <Int16>(SignedVlq.Encode(Int16.MinValue).ToArray())); }
public void SInt16SerializeMin() { Assert.Equal(SignedVlq.Encode(Int16.MinValue), LightWeight.Serialize(Int16.MinValue)); }
public void SignedVlqEncodeDecode32() { var encoded = SignedVlq.Encode(Int32.MaxValue).ToArray(); Assert.Equal(Int32.MaxValue, SignedVlq.Decode(encoded)); }
public void SignedVlqEncodeDecodeA() { var encoded = SignedVlq.Encode(SignedVlq.MaxValue - Int32.MaxValue ^ 16).ToArray(); Assert.Equal(SignedVlq.MaxValue - Int32.MaxValue ^ 16, SignedVlq.Decode(encoded)); }