Пример #1
0
        public static CacheSyncMsg CreateStoreMsg(Guid sender, string key, object data, IDictionary <string, object> parameters)
        {
            var msg = new CacheSyncMsg()
            {
                CacheKey = key,
                Action   = CacheAction.Store,
                Sender   = sender
            };

            msg.Options.Add("Parameters", parameters);

            if (data != null)
            {
                var dataType = data.GetType().AssemblyQualifiedName;
                msg.Options.Add("DataType", dataType);
                var dataStr = Convert.ToBase64String(BitSerializer.Serialize(data));
                msg.Options.Add("Data", dataStr);
            }
            else
            {
                msg.Options.Add("Data", string.Empty);
            }

            return(msg);
        }
Пример #2
0
 public byte[] Serialize(object Entity, DynamicBuffer buffer, Dictionary <object, BufferPtr> referenceMaping)
 {
     byte[] result = bitSerializer.Serialize(Entity);
     if (buffer.CurrentPoint == 0)
     {
         buffer.Alloc(result.Count()).Set(result);
     }
     return(result);
 }
        public void Precalculated()
        {
            byte[] output = new byte[_DataSerializationSize];
            BitSerializer <Struct3> .Serialize(output, _Data);

            Struct3 value;

            BitSerializer <Struct3> .Deserialize(output, out value);
        }
        public void OnTheFly()
        {
            byte[] output = new byte[_DataSerializationSize];
            BitSerializer.Serialize(output, _Data);

            Struct3 value;

            BitSerializer.Deserialize(output, out value);
        }
Пример #5
0
        private void CheckSerializers <T>(
            T value,
            T expectedDeserializeValue,
            int expectedSerializeSize,
            int?reportedSerializeSize,
            CalculateSizeFunc <T> calculateSizeFunc,
            SerializeFunc <T> serializeFunc,
            DeserializeFunc <T> deserializeFunc
            ) where
        T : struct
        {
            if (reportedSerializeSize != null)
            {
                Assert.Equal(expectedSerializeSize, reportedSerializeSize);
            }

            Assert.Equal(expectedSerializeSize, calculateSizeFunc(value));

            byte[]      output1    = new byte[expectedSerializeSize];
            Span <byte> outputItr1 = BitSerializer.Serialize(output1, value);

            Assert.Equal(0, outputItr1.Length);

            byte[]      output2    = new byte[expectedSerializeSize];
            Span <byte> outputItr2 = BitSerializer <T> .Serialize(output2, value);

            Assert.Equal(0, outputItr2.Length);

            byte[]      output3    = new byte[expectedSerializeSize];
            Span <byte> outputItr3 = serializeFunc(output3, value);

            Assert.Equal(0, outputItr3.Length);

            Assert.Equal(output1, output2);
            Assert.Equal(output1, output3);

            T value1;
            ReadOnlySpan <byte> inputItr1 = BitSerializer.Deserialize(output1, out value1);

            Assert.Equal(0, inputItr1.Length);

            T value2;
            ReadOnlySpan <byte> inputItr2 = BitSerializer <T> .Deserialize(output2, out value2);

            Assert.Equal(0, inputItr2.Length);

            T value3;
            ReadOnlySpan <byte> inputItr3 = deserializeFunc(output3, out value3);

            Assert.Equal(0, inputItr3.Length);

            expectedDeserializeValue.ShouldCompare(value1);
            expectedDeserializeValue.ShouldCompare(value2);
            expectedDeserializeValue.ShouldCompare(value3);
        }
Пример #6
0
        public void SerializeTest()
        {
            var src = new LevelOne()
            {
                Dim1 = "Val",
                Dim4 = Convert.ToDateTime("2000-01-01 01:02:03.789"),
                Dim5 = new LevelTwo()
                {
                    Dim1 = new List <string>()
                    {
                        "Val1", "Val2"
                    },
                    Dim2 = new int[] { 1, 10, 100, 1000 },
                    Dim3 = new Dictionary <string, object>(),
                    Dim4 = new LevelThree()
                    {
                        Dim1 = typeof(LevelTwo),
                        Dim2 = 2000,
                        Dim3 = Guid.NewGuid(),
                        Dim4 = Convert.FromBase64String("VmFs"),
                        Dim5 = 20,
                        Dim6 = LevelEnum.Enum2
                    }
                }
            };

            var bytes = BitSerializer.Serialize(src);

            var obj  = BitSerializer.Deserialize(typeof(LevelOne).AssemblyQualifiedName, bytes);
            var dest = (LevelOne)obj;

            Assert.Equal(src.Dim1, dest.Dim1);
            Assert.Equal(src.Dim4, dest.Dim4);
            Assert.Equal(111, LevelOne.Dim7);
            Assert.Equal(src.Dim10, dest.Dim10);
            Assert.Equal(src.Dim5.Dim1, dest.Dim5.Dim1);
            Assert.Equal(src.Dim5.Dim2, dest.Dim5.Dim2);
            Assert.Equal(src.Dim5.Dim3, dest.Dim5.Dim3);
            Assert.Equal(src.Dim5.Dim4.Dim1, dest.Dim5.Dim4.Dim1);
            Assert.Equal(10000, dest.Dim5.Dim4.Dim2);
            Assert.Equal(src.Dim5.Dim4.Dim3, dest.Dim5.Dim4.Dim3);
            Assert.Equal(src.Dim5.Dim4.Dim4, dest.Dim5.Dim4.Dim4);
            Assert.Equal(src.Dim5.Dim4.Dim5, dest.Dim5.Dim4.Dim5);
            Assert.Equal(src.Dim5.Dim4.Dim6, dest.Dim5.Dim4.Dim6);
        }