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);
        }
    }
}

1 comment:

  1. This is very interesting, You are a very skilled blogger.
    I have joined your feed and look forward to seeking more of your fantastic
    post. Also, I have shared your website in my
    social networks!

    ReplyDelete