コード例 #1
0
 void Write(DatabaseCompat db, ref ProtoWriter.State state)
 {
     try
     {
         var watch = Stopwatch.StartNew();
         state.SerializeRoot(db);
         state.Close();
         watch.Stop();
         Log?.WriteLine($"Serialized: {watch.ElapsedMilliseconds}ms");
     }
     catch
     {
         state.Abandon();
         throw;
     }
 }
コード例 #2
0
        public static byte[] CreateProtoWriterBuffer()
        {
            using (MemoryStream writeStream = new MemoryStream())
            {
                ProtoWriter.State protoWriter = ProtoWriter.State.Create(writeStream, null, null);

                var student = Helper.FillObject <Student>();
                WriteValue(1, student.Id, protoWriter); //adds field number followed by value in protowrite stream.
                WriteValue(2, student.Name, protoWriter);
                WriteValue(3, student.AdmissionDate, protoWriter);
                WriteValue(4, student.Age, protoWriter);

                student = Helper.FillObject <Student>();
                WriteValue(1, student.Id, protoWriter);
                WriteValue(2, student.Name, protoWriter);
                WriteValue(3, student.AdmissionDate, protoWriter);
                WriteValue(4, student.Age, protoWriter);

                protoWriter.Close();     //Close ProtoWriter when done with writing all the data.

                return(writeStream.ToArray());
            }
        }