-
-
Save fzankl/7d2d82ad2df4eb277d00450b6564fd8f to your computer and use it in GitHub Desktop.
Send and receive a protobuf in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using Google.Protobuf; | |
namespace GrpcSamples | |
{ | |
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
var foo = new Foo | |
{ | |
Id = 1, | |
Description = "FooMessage" | |
}; | |
// Write to any stream | |
var stream = new MemoryStream(); | |
foo.WriteTo(stream); | |
stream.Seek(0, SeekOrigin.Begin); | |
// Create Foo object from any stream | |
var parsedFoo = Foo.Parser.ParseFrom(stream); | |
Console.WriteLine($"Foo: Id {parsedFoo.Id} - {parsedFoo.Description}"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment