Пример #1
0
        public async ValueTask Read(PrimitiveReader primitiveReader, CancellationToken cancellationToken)
        {
            BoolValue = await primitiveReader.ReadBool(cancellationToken);

            ByteValue = await primitiveReader.ReadByte(cancellationToken);

            SByteValue = await primitiveReader.ReadSByte(cancellationToken);

            ShortValue = await primitiveReader.ReadInt16(cancellationToken);

            UShortValue = await primitiveReader.ReadUInt16(cancellationToken);

            IntValue = await primitiveReader.ReadInt32(cancellationToken);

            UIntValue = await primitiveReader.ReadUInt32(cancellationToken);

            LongValue = await primitiveReader.ReadInt64(cancellationToken);

            ULongValue = await primitiveReader.ReadUInt64(cancellationToken);

            FloatValue = await primitiveReader.ReadSingle(cancellationToken);

            DoubleValue = await primitiveReader.ReadDouble(cancellationToken);

            StringValue = await primitiveReader.ReadString(cancellationToken);

            deserializationCounter++;
        }
Пример #2
0
        public override void Load(PrimitiveReader reader)
        {
            var present = reader.ReadBoolean();

            if (present)
            {
                Placeholder = reader.ReadString();
            }
        }
Пример #3
0
        public void TestingStrings(string init, Encoding encoding)
        {
            ResetBois();

            PrimitiveWriter.WriteValue(Writer, init, encoding);
            ResetStream();

            var final = PrimitiveReader.ReadString(Reader, encoding);

            final.Should().Be(init);
        }
Пример #4
0
        public void Load(PrimitiveReader reader)
        {
            Id = reader.ReadUInt64();
            Message = reader.ReadString();
            SourceId = reader.ReadInt32();
            ThreadId = reader.ReadInt32();
            Time = new DateTime(reader.ReadInt64());
            numericLogLevel = reader.ReadInt32();

            if(ThreadId == -1)
            {
                ThreadId = null;
            }
        }
Пример #5
0
        public void ShouldWriteAndReadStrings(
            [Values(1, 100, 10000)]
            int numberOfStrings,
            [Values(true, false)]
            bool withLongStrings)
        {
            const int maxLength             = 100;
            const int longStringLength      = 8000;
            const int longStringProbability = 10;

            var random  = Helpers.Random;
            var strings = new string[numberOfStrings];

            for (var i = 0; i < strings.Length; i++)
            {
                int length;
                if (withLongStrings && random.Next() % longStringProbability == 0)
                {
                    length = longStringLength;
                }
                else
                {
                    length = random.Next(maxLength);
                }
                strings[i] = Helpers.GetRandomString(length);
            }

            var stream = new MemoryStream();

            using (var writer = new PrimitiveWriter(stream))
            {
                for (var i = 0; i < strings.Length; i++)
                {
                    writer.Write(strings[i]);
                }
            }
            var position = stream.Position;

            stream.Seek(0, SeekOrigin.Begin);

            using (var reader = new PrimitiveReader(stream))
            {
                for (var i = 0; i < strings.Length; i++)
                {
                    Assert.AreEqual(strings[i], reader.ReadString());
                }
            }
            Assert.AreEqual(position, stream.Position, StreamCorruptedMessage);
        }
        public void ShouldWriteAndReadStrings(
			[Values(1, 100, 10000)]
			int numberOfStrings,
			[Values(true, false)]
			bool withLongStrings)
        {
            const int maxLength = 100;
            const int longStringLength = 8000;
            const int longStringProbability = 10;

            var random = Helpers.Random;
            var strings = new string[numberOfStrings];
            for(var i = 0; i < strings.Length; i++)
            {
                int length;
                if(withLongStrings && random.Next()%longStringProbability == 0)
                {
                    length  = longStringLength;
                }
                else
                {
                    length = random.Next(maxLength);
                }
                strings[i] = Helpers.GetRandomString(length);
            }

            var stream = new MemoryStream();
            using(var writer = new PrimitiveWriter(stream))
            {
                for(var i = 0; i < strings.Length; i++)
                {
                    writer.Write(strings[i]);
                }
            }
            var position = stream.Position;
            stream.Seek(0, SeekOrigin.Begin);

            using(var reader = new PrimitiveReader(stream))
            {
                for(var i = 0; i < strings.Length; i++)
                {
                    Assert.AreEqual(strings[i], reader.ReadString());
                }
            }
            Assert.AreEqual(position, stream.Position, StreamCorruptedMessage);
        }
 public async ValueTask Read(PrimitiveReader primitiveReader, CancellationToken cancellationToken) => result = await primitiveReader.ReadString(cancellationToken);