예제 #1
0
 static void StoreMultipleObjectInaFile()
 {
     using (var outputStream = new BinaryWriter(File.Create("data.dat")))
     {
         outputStream.Write(0); //indicates number of demands in the file.
         for (int i = 0; i < 10; i++)
         {
             FlatBufferBuilder fbb = new FlatBufferBuilder(1024);
             var scalarTypeOffset  = Helper.BuildScalarType(fbb);
             fbb.Finish(scalarTypeOffset.Value);
             byte[] serializedData = fbb.SizedByteArray();
             outputStream.Write(serializedData.Length);
             outputStream.Write(serializedData);
         }
         outputStream.Seek(0, SeekOrigin.Begin);
         outputStream.Write(10); //replaces the value written at the top which indicates the number of demands.
     }
     using (var ipStream = new BinaryReader(File.OpenRead("data.dat")))
     {
         var count = ipStream.ReadInt32();
         for (int i = 0; i < count; i++)
         {
             var size        = ipStream.ReadInt32();
             var bytes       = ipStream.ReadBytes(size);
             var byteBuf     = new ByteBuffer(bytes);
             var dScalarType = ScalarType.GetRootAsScalarType(byteBuf);
         }
     }
 }
예제 #2
0
        static void AssertScalarType()
        {
            //initial buffer size
            FlatBufferBuilder fbb = new FlatBufferBuilder(1024);
            var scalarTypeOffset  = Helper.BuildScalarType(fbb);

            fbb.Finish(scalarTypeOffset.Value);

            byte[] serializedData = fbb.SizedByteArray();
            var    buffer         = new ByteBuffer(serializedData);
            var    dScalarType    = ScalarType.GetRootAsScalarType(buffer);

            Assert.IsTrue(dScalarType.BoolType);
        }