예제 #1
0
 public void Serialize(IBinarySerializer serializer)
 {
     serializer.Write((int)Action);
     serializer.Write(Key);
     serializer.Write(Data);
     serializer.Write(Source);
 }
예제 #2
0
 public void Serialize(IBinarySerializer serializer)
 {
     serializer.Write(A);
     serializer.Write(B);
     serializer.Write(Version);
     serializer.Write(Connected ? 1 : 0);
 }
 public static void WriteList <T>(this IBinarySerializer serializer, ICollection <T> list) where T : IBinarySerializable
 {
     serializer.Write(list.Count);
     foreach (var item in list)
     {
         serializer.Write(item);
     }
 }
 public static void WriteList <T>(this IBinarySerializer serializer, ICollection <T> list, Action <IBinarySerializer, T> serializeFunc)
 {
     serializer.Write(list.Count);
     foreach (var item in list)
     {
         serializeFunc(serializer, item);
     }
 }
 public static void SerializeCollection <TValue>(this IBinarySerializer binarySerializer,
                                                 ICollection <TValue> collection, Action <TValue> onItemSerialize)
 {
     binarySerializer.Write(collection.Count);
     foreach (var value in collection)
     {
         onItemSerialize(value);
     }
 }
        public void Test_Writing_An_Object()
        {
            string value = "value";
            IReadOnlyList <uint> offsets = new List <uint> {
                1, 2, 3
            };

            treeWriter(binaryWriter, value, rootNode).Returns(offsets);

            serializer.Write(binaryWriter, value);

            Received.InOrder(() =>
            {
                treeWriter(binaryWriter, value, rootNode);
                footerAligner(binaryWriter);
                offsets.ForEach(binaryWriter.WriteUInt32);
                binaryWriter.WriteInt32(offsets.Count);
                binaryWriter.WriteUInt32(TreeBinarySerializer <object> .FOOTER_MAGIC_NUMBER);
            });
        }
예제 #7
0
        public void Test_Writing_With_A_BinarySerializer_Directly_To_A_Stream()
        {
            string value = nameof(value);

            WithDummyStream(stream =>
            {
                binarySerializer.Write(stream, value);

                binarySerializer.Received().Write(Arg.Do <IBinaryWriter>(binaryReader =>
                {
                    binaryReader.Should().BeOfType <BinaryWriterWrapper>();

                    typeof(BinaryWriterWrapper)
                    .GetField("realReader", BindingFlags.Instance | BindingFlags.NonPublic)
                    .GetValue(binaryReader)
                    .Should()
                    .BeSameAs(stream);
                }), value);
            });
        }
예제 #8
0
        public void Serialize(IBinarySerializer binarySerializer, Action <TKey> keySerializer,
                              Action <TValue> valueSerializer)
        {
            var indexCopy = _index.ToArray();

            binarySerializer.Write(indexCopy.Length);
            foreach (var value in indexCopy)
            {
                keySerializer(value.Key);
                valueSerializer(value.Value);
            }
        }
예제 #9
0
        public void Test_Writing_With_A_Null_BinarySerializer_Directly_To_A_Stream()
        {
            IBinarySerializer <string> binarySerializer = null;

            WithDummyStream(stream =>
            {
                Action action = () => binarySerializer.Write(stream, string.Empty);

                action.Should()
                .ThrowArgumentNullException("binarySerializer");
            });
        }
예제 #10
0
        public void Test_Writing_BKD_File_Successfully(SerializationTestCaseData <BKD> testCaseData)
        {
            byte[] expected = File.ReadAllBytes(testCaseData.TestFilePath);

            using (var stream = new MemoryStream())
            {
                var writer = Writer.ForStream(stream);

                serializer.Write(writer, testCaseData.Expected);

                stream.ToArray()
                .Should()
                .Equal(expected);
            }
        }
예제 #11
0
 public override void Serialize(IBinarySerializer serializer)
 {
     serializer.Write(ExecutorId);
     serializer.Write(ApiKey);
 }
예제 #12
0
 public void Serialize(IBinarySerializer serializer)
 {
     serializer.Write(ExecutorId);
     serializer.Write(ExecutorApiKey);
 }
예제 #13
0
 public void Serialize(IBinarySerializer serializer)
 {
     serializer.Write(Endpoint.Address.GetAddressBytes());
     serializer.Write(Endpoint.Port);
 }
예제 #14
0
 public void Serialize(IBinarySerializer serializer)
 {
     serializer.Write(Limit);
 }
예제 #15
0
 public void Serialize(IBinarySerializer serializer)
 {
     serializer.WriteList(Links);
     serializer.Write(SuggestDisconnect ? 1 : 0);
 }
예제 #16
0
 public void Serialize(IBinarySerializer serializer)
 {
     serializer.Write(Destination);
     serializer.Write(Data);
 }
 public override void Serialize(IBinarySerializer serializer)
 {
     serializer.Write(CommandName);
     serializer.Write(ApiKey);
 }
예제 #18
0
 public void Serialize(IBinarySerializer serializer)
 {
     serializer.Write(Name);
     serializer.SerializeCollection(Admins, serializer.Write);
 }