All Projects → msoucy → dproto

msoucy / dproto

Licence: BSL-1.0 license
D Protocol Buffer mixins to create structures at compile time

Programming Languages

d
599 projects

Projects that are alternatives of or similar to dproto

Evans
Evans: more expressive universal gRPC client
Stars: ✭ 2,710 (+7642.86%)
Mutual labels:  protocol-buffers
Mu Haskell
Mu (μ) is a purely functional framework for building micro services.
Stars: ✭ 215 (+514.29%)
Mutual labels:  protocol-buffers
protocol-buffers
Haskell protocol-buffers package
Stars: ✭ 75 (+114.29%)
Mutual labels:  protocol-buffers
Protozero
Minimalist protocol buffer decoder and encoder in C++
Stars: ✭ 177 (+405.71%)
Mutual labels:  protocol-buffers
Nanopb
Protocol Buffers with small code size
Stars: ✭ 2,668 (+7522.86%)
Mutual labels:  protocol-buffers
Protoman
Postman for protobuf APIs
Stars: ✭ 241 (+588.57%)
Mutual labels:  protocol-buffers
Protofuzz
Google Protocol Buffers message generator
Stars: ✭ 171 (+388.57%)
Mutual labels:  protocol-buffers
scod
A nice documentation generator based on ddox.
Stars: ✭ 32 (-8.57%)
Mutual labels:  dub
Rules protobuf
Bazel rules for building protocol buffers and gRPC services (java, c++, go, ...)
Stars: ✭ 206 (+488.57%)
Mutual labels:  protocol-buffers
protobluff
A modular Protocol Buffers implementation for C
Stars: ✭ 66 (+88.57%)
Mutual labels:  protocol-buffers
Go Grpc Examples
This repo contains examples and implementations of different types of GRPC services and APIs using Golang.
Stars: ✭ 180 (+414.29%)
Mutual labels:  protocol-buffers
Protobuf Dynamic
Protocol Buffers Dynamic Schema - create protobuf schemas programmatically
Stars: ✭ 186 (+431.43%)
Mutual labels:  protocol-buffers
rules proto grpc
Bazel rules for building Protobuf and gRPC code and libraries from proto_library targets
Stars: ✭ 201 (+474.29%)
Mutual labels:  protocol-buffers
Protoc Jar Maven Plugin
Protocol Buffers protobuf maven plugin - based on protoc-jar multi-platform executable protoc JAR
Stars: ✭ 177 (+405.71%)
Mutual labels:  protocol-buffers
vscode-buf
Visual Studio Code integration for Buf.
Stars: ✭ 40 (+14.29%)
Mutual labels:  protocol-buffers
Buf
A new way of working with Protocol Buffers.
Stars: ✭ 3,328 (+9408.57%)
Mutual labels:  protocol-buffers
Protoc Gen Lint
A plug-in for Google's Protocol Buffers (protobufs) compiler to lint .proto files for style violations.
Stars: ✭ 221 (+531.43%)
Mutual labels:  protocol-buffers
nakama-common
The runtime framework for Nakama server.
Stars: ✭ 31 (-11.43%)
Mutual labels:  protocol-buffers
parquet-flinktacular
How to use Parquet in Flink
Stars: ✭ 29 (-17.14%)
Mutual labels:  protocol-buffers
j2cl-protobuf
Protocol Buffers implementation for J2CL
Stars: ✭ 23 (-34.29%)
Mutual labels:  protocol-buffers

D Protocol Buffers


Build Status Coverage Status DUB DUB license

Protocol buffers are a language-agnostic way of specifying message structures to allow communication and serialization.

dproto is designed to enable mixing protocol buffer files into your D code at compile time.

Inspiration and a good portion of the original parser is adapted from square/protoparser


Options

dproto supports altering behavior via protobuf options:

Option Meaning Example Default
dproto_reserved_fmt The format for renaming reserved D keywords as fields. "%s_" will convert version to version_ "%s_"

Examples

Further info

Examples can be found in import/dproto/dproto.d and in examples/.

Simple Example

import std.stdio;
import dproto.dproto;

mixin ProtocolBufferFromString!"
	message Person {
	  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;
	}
";


int main()
{
	Person person;
	person.name = "John Doe";
	person.id = 1234;
	person.email = "[email protected]";

	ubyte[] serializedObject = person.serialize();

	Person person2 = Person(serializedObject);
	writeln("Name: ", person2.name);
	writeln("E-mail: ", person2.email);
	return 0;
}

More Complex Example

import dproto.dproto;

mixin ProtocolBufferFromString!"
	enum PhoneType {
	  MOBILE = 0;
	  HOME = 0;
	  WORK = 2;
	}

	message Person {
	  required string name = 1;
	  required int32 id = 2;
	  optional string email = 3;

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

	  repeated PhoneNumber phone = 4;
	}

	message AddressBook {
	  repeated Person person = 1;
	}
";


int main()
{
	Person t;
	t.name = "Max Musterman";
	t.id = 3;
	t.email = "[email protected]";

	Person.PhoneNumber pn1;
	pn1.number = "0123456789";
	pn1.type = PhoneType.WORK;

	Person.PhoneNumber pn2;
	pn2.number = "0123456789";

	t.phone = [pn1, pn2];
	AddressBook addressbook;
	addressbook.person ~= t;
	addressbook.person ~= t;

	ubyte[] serializedObject = addressbook.serialize();

	AddressBook addressbook2 = AddressBook(serializedObject);
	assert(addressbook2.person.length == 2);
	foreach(t2; addressbook2.person)
	{
		assert(t2.name == "Max Musterman");
		assert(t2.id == 3);
		assert(t2.email == "[email protected]");
		assert(t2.email !is null);
		assert(t2.phone[0].number == "0123456789");
		assert(t2.phone[0].type == PhoneType.WORK);
		assert(t2.phone[1].number == "0123456789");
		assert(t2.phone[1].type == PhoneType.HOME);
		assert(t2.phone[1].type == PhoneType.MOBILE);
		assert(t2.phone.length == 2);
	}
	version(DigitalMars)
	{
		assert(addressbook2.person[0] == addressbook.person[1]);
	}
	return 0;
}

Services

Generate interfaces for service definitions.

import dproto.dproto;

mixin ProtocolBufferInterface!"
	message ServiceRequest {
		string request = 1;
	}
	message ServiceResponse {
		string response = 1;
	}
	service TestService {
		rpc TestMethod (ServiceRequest) returns (ServiceResponse);
	}
";

class ServiceImplementation : TestService {
	ServiceResponse TestMethod(ServiceRequest input) {
		ServiceResponse output;
		output.response = "received: " ~ input.request;
		return output;
	}
}
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].