Friday, December 9, 2016

Convert protobuf to base64

using System;
using p = Google.Protobuf;

namespace TestProtobuf
{
    class MainClass
    {
        public static void Main(string[] args)
        {


            var c = new Person 
            {
                FirstName = "Anders", LastName = "Hejlsberg"
            };


            int n = c.CalculateSize();
            var ba = new byte[n];

            var os = new p.CodedOutputStream(ba);

            c.WriteTo(os);

            var s = Convert.ToBase64String(ba);

            Console.WriteLine(s);
        }
    }
}