示例#1
0
        public static ImmutableArray <byte> EncodeAsImmutable(BaseLibrary record)
        {
            var writer = BebopWriter.Create();

            __EncodeInto(record, ref writer);
            return(writer.ToImmutableArray());
        }
示例#2
0
        public StringReadWrite()
        {
            var input = BebopWriter.Create();

            input.WriteString(TestString);
            _testBuffer = input.ToArray();
        }
示例#3
0
        public ImmutableArray <byte> EncodeAsImmutable()
        {
            var writer = BebopWriter.Create();

            __EncodeInto(this, ref writer);
            return(writer.ToImmutableArray());
        }
示例#4
0
        public byte[] Encode()
        {
            var writer = BebopWriter.Create();

            __EncodeInto(this, ref writer);
            return(writer.ToArray());
        }
示例#5
0
        public static byte[] Encode(BaseLibrary record)
        {
            var writer = BebopWriter.Create();

            __EncodeInto(record, ref writer);
            return(writer.ToArray());
        }
示例#6
0
 internal static void __EncodeInto(BaseLibrary record, ref BebopWriter writer)
 {
     writer.WriteUInt32(unchecked ((uint)record.Songs.Count));
     foreach (var kv0 in record.Songs)
     {
         writer.WriteGuid(kv0.Key);
         Bebop.Codegen.Song.__EncodeInto(kv0.Value, ref writer);
     }
 }
示例#7
0
        public void WriteBuffer()
        {
            var input = BebopWriter.Create();

            input.WriteByte(0);
            input.WriteInt16(1000);
            input.WriteInt32(2000);
            input.WriteString(TestString);
            input.WriteGuid(_testGuid);
        }
示例#8
0
        public BufferReadWrite()
        {
            _testGuid = Guid.Parse("02281d74-a708-4f64-8a5c-699100654587");
            var input = BebopWriter.Create();

            input.WriteByte(0);
            input.WriteInt16(1000);
            input.WriteInt32(2000);
            input.WriteString(TestString);
            input.WriteGuid(_testGuid);
            _testBuffer = input.ToArray();
        }
示例#9
0
        public void Write()
        {
            var input = BebopWriter.Create();

            input.WriteString(TestString);
        }
示例#10
0
文件: UnitTest1.cs 项目: shana/bebop
        public void WriteRead()
        {
            var          testBytes   = new byte[] { 0x1, 0x2, 0x3 };
            var          testFloats  = new float[] { float.MinValue, float.MaxValue };
            var          testDoubles = new double[] { double.MinValue, double.MaxValue };
            var          testGuid    = Guid.Parse("81c6987b-48b7-495f-ad01-ec20cc5f5be1");
            const string testString  = @"Hello 明 World!😊";
            var          testDate    = DateTime.UtcNow;

            var input = BebopWriter.Create();

            input.WriteByte(false);
            input.WriteByte(byte.MaxValue);
            input.WriteUInt16(ushort.MaxValue);
            input.WriteInt16(short.MaxValue);
            input.WriteUInt32(uint.MaxValue);
            input.WriteInt32(int.MaxValue);
            input.WriteUInt64(ulong.MaxValue);
            input.WriteInt64(long.MaxValue);
            input.WriteFloat32(float.MaxValue);
            input.WriteFloat64(double.MaxValue);
            input.WriteFloat32S(testFloats);
            input.WriteFloat64S(testDoubles);
            input.WriteString(testString);
            input.WriteGuid(testGuid);
            input.WriteDate(testDate);
            input.WriteBytes(testBytes);
            input.WriteEnum(TestEnum.Ok);


            var output = BebopReader.From(input.ToImmutableArray());

            // test byte
            Assert.AreEqual(0, output.ReadByte());
            Assert.AreEqual(byte.MaxValue, output.ReadByte());
            // test short
            Assert.AreEqual(ushort.MaxValue, output.ReadUInt16());
            Assert.AreEqual(short.MaxValue, output.ReadInt16());
            // test int
            Assert.AreEqual(uint.MaxValue, output.ReadUInt32());
            Assert.AreEqual(int.MaxValue, output.ReadInt32());
            // test long
            Assert.AreEqual(ulong.MaxValue, output.ReadUInt64());
            Assert.AreEqual(long.MaxValue, output.ReadInt64());
            // test float / double
            Assert.AreEqual(float.MaxValue, output.ReadFloat32());
            Assert.AreEqual(double.MaxValue, output.ReadFloat64());
            // test float array
            var floatArrayLength = output.ReadUInt32();

            Assert.AreEqual(testFloats.Length, floatArrayLength);
            var parsedFloats = new float[floatArrayLength];

            for (int i = 0; i < floatArrayLength; i++)
            {
                parsedFloats[i] = output.ReadFloat32();
            }
            CollectionAssert.AreEqual(testFloats, parsedFloats);
            // test double array
            var doubleArrayLength = output.ReadUInt32();

            Assert.AreEqual(testDoubles.Length, doubleArrayLength);
            var parsedDoubles = new double[doubleArrayLength];

            for (int i = 0; i < doubleArrayLength; i++)
            {
                parsedDoubles[i] = output.ReadFloat64();
            }
            CollectionAssert.AreEqual(testDoubles, parsedDoubles);
            // test string
            Assert.AreEqual(testString, output.ReadString());
            // test guid
            Assert.AreEqual(testGuid, output.ReadGuid());
            // test date
            Assert.AreEqual(testDate, output.ReadDate());
            // test byte array
            CollectionAssert.AreEqual(testBytes, output.ReadBytes());
            // test enum
            Assert.AreEqual(TestEnum.Ok, output.ReadEnum <TestEnum>());

            Assert.Pass();
        }