Пример #1
0
        public void TestRoundTripPrimitives()
        {
            var stream = new MemoryStream();
            var writer = new ObjectWriter(stream);

            writer.WriteBoolean(true);
            writer.WriteBoolean(false);
            writer.WriteByte(Byte.MaxValue);
            writer.WriteSByte(SByte.MaxValue);
            writer.WriteInt16(Int16.MaxValue);
            writer.WriteInt32(Int32.MaxValue);
            writer.WriteInt32(Byte.MaxValue);
            writer.WriteInt32(Int16.MaxValue);
            writer.WriteInt64(Int64.MaxValue);
            writer.WriteUInt16(UInt16.MaxValue);
            writer.WriteUInt32(UInt32.MaxValue);
            writer.WriteUInt64(UInt64.MaxValue);
            writer.WriteDecimal(Decimal.MaxValue);
            writer.WriteDouble(Double.MaxValue);
            writer.WriteSingle(Single.MaxValue);
            writer.WriteChar('X');
            writer.WriteString("YYY");
            writer.WriteCompressedUInt(Byte.MaxValue >> 2);   // 6 bits
            writer.WriteCompressedUInt(UInt16.MaxValue >> 2); // 14 bits
            writer.WriteCompressedUInt(UInt32.MaxValue >> 2); // 30 bits
            var dt = DateTime.Now;

            writer.WriteDateTime(dt);
            writer.Dispose();

            stream.Position = 0;
            var reader = new ObjectReader(stream);

            Assert.Equal(true, reader.ReadBoolean());
            Assert.Equal(false, reader.ReadBoolean());
            Assert.Equal(Byte.MaxValue, reader.ReadByte());
            Assert.Equal(SByte.MaxValue, reader.ReadSByte());
            Assert.Equal(Int16.MaxValue, reader.ReadInt16());
            Assert.Equal(Int32.MaxValue, reader.ReadInt32());
            Assert.Equal(Byte.MaxValue, reader.ReadInt32());
            Assert.Equal(Int16.MaxValue, reader.ReadInt32());
            Assert.Equal(Int64.MaxValue, reader.ReadInt64());
            Assert.Equal(UInt16.MaxValue, reader.ReadUInt16());
            Assert.Equal(UInt32.MaxValue, reader.ReadUInt32());
            Assert.Equal(UInt64.MaxValue, reader.ReadUInt64());
            Assert.Equal(Decimal.MaxValue, reader.ReadDecimal());
            Assert.Equal(Double.MaxValue, reader.ReadDouble());
            Assert.Equal(Single.MaxValue, reader.ReadSingle());
            Assert.Equal('X', reader.ReadChar());
            Assert.Equal("YYY", reader.ReadString());
            Assert.Equal((UInt32)(Byte.MaxValue >> 2), reader.ReadCompressedUInt());
            Assert.Equal((UInt32)(UInt16.MaxValue >> 2), reader.ReadCompressedUInt());
            Assert.Equal(UInt32.MaxValue >> 2, reader.ReadCompressedUInt());
            Assert.Equal(dt, reader.ReadDateTime());
            reader.Dispose();
        }
Пример #2
0
        public void Unpack(ObjectReader reader)
        {
            n      = reader.ReadInt32();
            branch = (Link)reader.ReadObject();
            card   = branch.Count;
            int nDims = ((Page.pageSize - ObjectHeader.Sizeof - 12) / card - 4) / 16;

            double[] coords = new double[nDims * 2];
            b = new RectangleRn[card];
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < nDims; j++)
                {
                    coords[j]         = reader.ReadDouble();
                    coords[j + nDims] = reader.ReadDouble();
                }
                b[i] = new RectangleRn(coords);
            }
        }
 private static void TestReadingPrimitiveAPIs(ObjectReader reader)
 {
     Assert.Equal(true, reader.ReadBoolean());
     Assert.Equal(false, reader.ReadBoolean());
     Assert.Equal(Byte.MaxValue, reader.ReadByte());
     Assert.Equal(SByte.MaxValue, reader.ReadSByte());
     Assert.Equal(Int16.MaxValue, reader.ReadInt16());
     Assert.Equal(Int32.MaxValue, reader.ReadInt32());
     Assert.Equal(Byte.MaxValue, reader.ReadInt32());
     Assert.Equal(Int16.MaxValue, reader.ReadInt32());
     Assert.Equal(Int64.MaxValue, reader.ReadInt64());
     Assert.Equal(UInt16.MaxValue, reader.ReadUInt16());
     Assert.Equal(UInt32.MaxValue, reader.ReadUInt32());
     Assert.Equal(UInt64.MaxValue, reader.ReadUInt64());
     Assert.Equal(Decimal.MaxValue, reader.ReadDecimal());
     Assert.Equal(Double.MaxValue, reader.ReadDouble());
     Assert.Equal(Single.MaxValue, reader.ReadSingle());
     Assert.Equal('X', reader.ReadChar());
     Assert.Equal("YYY", reader.ReadString());
     Assert.Equal("\uD800\uDC00", reader.ReadString()); // valid surrogate pair
     Assert.Equal("\uDC00\uD800", reader.ReadString()); // invalid surrogate pair
     Assert.Equal("\uD800", reader.ReadString());       // incomplete surrogate pair
 }
Пример #4
0
 public void Unpack(ObjectReader reader)
 {
     rect = new RectangleR2(reader.ReadDouble(), reader.ReadDouble(), reader.ReadDouble(), reader.ReadDouble());
     body = reader.ReadBytes(reader.ReadInt32());
 }