Google protocol buffers tools.
Project description
About
Google Protocol Buffers tools in Python 3.
C source code generator.
Only supports proto3.
Project homepage: https://github.com/eerimoq/pbtools
Documentation: http://pbtools.readthedocs.org/en/latest
Installation
pip install pbtools
Example usage
C source code
In this example we use the simple proto-file hello_world.proto.
syntax = "proto3";
package hello_world;
message Foo {
int32 bar = 1;
}
Next we generate C source code from the proto-file.
$ pbtools generate_c_source examples/hello_world/hello_world.proto
Successfully generated hello_world.h and hello_world.c.
See hello_world.h and hello_world.c for the contents of the generated files.
We’ll use the generated types and functions below.
struct hello_world_foo_t {
struct hello_world_heap_t *heap_p;
int32_t bar;
};
struct hello_world_foo_t *hello_world_foo_new(
void *workspace_p,
size_t size);
int hello_world_foo_encode(
struct hello_world_foo_t *self_p,
void *encoded_p,
size_t size);
int hello_world_foo_decode(
struct hello_world_foo_t *self_p,
const uint8_t *encoded_p,
size_t size);
Encode and decode the Foo-message.
#include <string.h>
#include <stdio.h>
#include "hello_world.h"
int main(int argc, const char *argv[])
{
int size;
uint8_t workspace[64];
uint8_t encoded[16];
struct hello_world_foo_t *foo_p;
/* Encode. */
foo_p = hello_world_foo_new(&workspace[0], sizeof(workspace));
if (foo_p != NULL) {
foo_p->bar = 78;
size = hello_world_foo_encode(foo_p, &encoded[0], sizeof(encoded));
if (size >= 0) {
printf("Successfully encoded Foo into %d bytes.\n", size);
}
}
/* Decode. */
foo_p = hello_world_foo_new(&workspace[0], sizeof(workspace));
if (foo_p != NULL) {
size = hello_world_foo_decode(foo_p, &encoded[0], sizeof(encoded));
if (size >= 0) {
printf("Successfully decoded %d bytes into Foo.\n", size);
printf("Foo.bar: %d\n", foo_p->bar);
}
}
return (0);
}
See hello_world for all files used in this example.
Command line tool
The generate C source subcommand
Below is an example of how to generate C source code from a proto-file.
$ pbtools generate_c_source examples/address_book/address_book.proto
Successfully generated address_book.h and address_book.c.
See address_book.h and address_book.c for the contents of the generated files.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pbtools-0.2.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | afb4ce3f081756054d93ef78261d6a85f9c4fd85197aa426eccab74854fda17c |
|
MD5 | a98dd7c9f6fabfe477510f2fcfe67e12 |
|
BLAKE2b-256 | 9d1ae89100a5f10a7c27265dcfe6cfe69e24532df02eff432e88d64f06716dbf |