All Projects → SilentOrbit → Protobuf

SilentOrbit / Protobuf

Licence: apache-2.0
C# code generator for reading and writing the protocol buffers format

Projects that are alternatives of or similar to Protobuf

Pbf
A low-level, lightweight protocol buffers implementation in JavaScript.
Stars: ✭ 618 (+137.69%)
Mutual labels:  protocol-buffers, serialization
Noproto
Flexible, Fast & Compact Serialization with RPC
Stars: ✭ 138 (-46.92%)
Mutual labels:  protocol-buffers, serialization
Protobuf Nim
Protobuf implementation in pure Nim that leverages the power of the macro system to not depend on any external tools
Stars: ✭ 90 (-65.38%)
Mutual labels:  protocol-buffers, serialization
Protobuf
Protocol Buffers - Google's data interchange format
Stars: ✭ 52,305 (+20017.31%)
Mutual labels:  protocol-buffers, serialization
protobuf-d
Protocol Buffers Compiler Plugin and Support Library for D
Stars: ✭ 32 (-87.69%)
Mutual labels:  serialization, protocol-buffers
Protobuf Inspector
🕵️ Tool to reverse-engineer Protocol Buffers with unknown definition
Stars: ✭ 513 (+97.31%)
Mutual labels:  protocol-buffers, serialization
Protobuf Java Format
Provide serialization and de-serialization of different formats based on Google’s protobuf Message. Enables overriding the default (byte array) output to text based formats such as XML, JSON and HTML.
Stars: ✭ 134 (-48.46%)
Mutual labels:  protocol-buffers, serialization
Protobuf
A pure Elixir implementation of Google Protobuf
Stars: ✭ 442 (+70%)
Mutual labels:  protocol-buffers, serialization
protoc-plugin
A protoc compiler plugin for Clojure applications
Stars: ✭ 28 (-89.23%)
Mutual labels:  serialization, protocol-buffers
kafka-protobuf-serde
Serializer/Deserializer for Kafka to serialize/deserialize Protocol Buffers messages
Stars: ✭ 52 (-80%)
Mutual labels:  serialization, protocol-buffers
elm-protobuf
protobuf plugin for elm
Stars: ✭ 93 (-64.23%)
Mutual labels:  serialization, protocol-buffers
nimpb
Protocol Buffers for Nim
Stars: ✭ 29 (-88.85%)
Mutual labels:  serialization, protocol-buffers
javascript-serialization-benchmark
Comparison and benchmark of JavaScript serialization libraries (Protocol Buffer, Avro, BSON, etc.)
Stars: ✭ 54 (-79.23%)
Mutual labels:  serialization, protocol-buffers
ocaml-pb-plugin
A protoc plugin for generating OCaml code from protobuf (.proto) files.
Stars: ✭ 18 (-93.08%)
Mutual labels:  serialization, protocol-buffers
ppx deriving protobuf
A Protocol Buffers codec generator for OCaml
Stars: ✭ 76 (-70.77%)
Mutual labels:  protocol-buffers
Simple-YAML
A Java API that provides an easy-to-use way to store data using the YAML format.
Stars: ✭ 68 (-73.85%)
Mutual labels:  serialization
knuckles
👊 High performance cached object serialization
Stars: ✭ 67 (-74.23%)
Mutual labels:  serialization
xplatform
every feature build up from scratch
Stars: ✭ 91 (-65%)
Mutual labels:  serialization
struct
pack and unpack binary data.
Stars: ✭ 42 (-83.85%)
Mutual labels:  serialization
AndTTT
🎲 Simple tic tac toe game for Android
Stars: ✭ 15 (-94.23%)
Mutual labels:  protocol-buffers

Protocol Buffers C# Code Generator

https://silentorbit.com/protobuf/

C# code generator for serialization into Googles Protocol Buffers wire format.

Parses a .proto file and generates C# source files with classes for every message as well as code for reading and writing them to the Protocol Buffers binary format.

Download

Get the precompiled binaries here.

Get the source using git:

git clone https://github.com/hultqvist/ProtoBuf.git --recursive

Don't use the "download zip" feature on github as it won't include submodules such as CommandLine

Basic Features

  • CodeGenerator - transform a .proto specification directly into complete c# code.
  • Generated code is relatively easy to debug(only hope you wont have too)
  • Generated code does not use reflection, works after code obfuscation.

Advanced Features

These features are local to this project. They affect how you will work with the generated code. It does not affect the final wire format. Any other Protocol Buffers implementation should be able to communicate using the same .proto specification.

For the latest features, see Test/csharpgen.proto

These local features are implemented in the Test project.

Message options:

  • access - set the acces of the generated class to internal rather than public.
  • triggers - have the class methods BeforeSerialize and AfterDeserialize called accordingly.
  • preserveunknown - keep all unknown fields during deserialization to be written back when serializing the class.
  • external - generate serialization code for a class we don't have control over, such as one from a third party DLL.
  • imported - utilize already generated code in the current generated messages.
  • type - default: class, but you can make the serializer work with struct or interfaces.

Field options:

  • access - default: public, can be any, even private if generating a local class(default)
  • codetype - set an int64 field type to "DateTime" or "TimeSpan", the serializer will do the conversion for you.
  • generate - if set to false(default: true), the field/property is expected to be defined elsewhere in the project rather than the generated code.
  • readonly - make the message field a c# readonly field rather than a property.

Example

This is a part of the Test/Example.proto:

package ExampleNamespace;

message Person {
  option namespace = "Personal";
  
  required string name = 1;
  required int32 id = 2;
  optional string email = 3;

  enum PhoneType {
    MOBILE = 0;
    HOME = 1;
    WORK = 2;
  }

  message PhoneNumber {
    required string number = 1;
    optional PhoneType type = 2 [default = HOME];
  }

  repeated PhoneNumber phone = 4;
}

When compiled it you will have the following class to work with.

public partial class Person
{
	public enum PhoneType
	{
		MOBILE = 0,
		HOME = 1,
		WORK = 2,
	}

	public string Name { get; set; }
	public int Id { get; set; }
	public string Email { get; set; }
	public List<Personal.Person.PhoneNumber> Phone { get; set; }


	public partial class PhoneNumber
	{
		public string Number { get; set; }
		public Personal.Person.PhoneType Type { get; set; }
	}
}

Writing this to a stream:

Person person = new Person();
...
Person.Serialize(stream, person);

Reading from a stream:

Person person2 = Person.Deserialize(stream);

Usage

CodeGenerator.exe Example.proto [output.cs]

If the optional output.cs parameter is omitted it will default to the basename of the .proto file. In this example it would be Example.cs

The output is three files.

  • Example.cs - Basic class declaration(based on .proto).
  • Example.Serializer.cs - Code for reading/writing the message.
  • ProtocolParser.cs - Functions for reading and writing the protobuf wire format, static, not related to the contents of your .proto.

If you generate code from multiple .proto files you must only include ProtocolParser.cs once in your project.

Direct Contact, FeedBack, Bugs

You can contact me using [email protected] .

Public issues can also be submitted to the GitHub project page.

Licence, Apache License version 2.0

All source code and generated code is licensed under the Apache License Version 2.0.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].