Google Protocol Buffers tools.
Project description
About
Google Protocol Buffers tools in Python 3.6+.
C source code generator.
Only supports proto3.
Known limitations:
Imports and recursive messages are not yet supported.
Options, services (gRPC) and maps are ignored.
The C type char must be 8 bits.
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;
}
Generate C source code from the proto-file.
$ pbtools generate_c_source examples/hello_world/hello_world.proto
Successfully created pbtools.[hc] and hello_world.[hc].
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 pbtools_message_base_t base;
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 <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) {
return (1);
}
foo_p->bar = 78;
size = hello_world_foo_encode(foo_p, &encoded[0], sizeof(encoded));
if (size < 0) {
return (2);
}
printf("Successfully encoded Foo into %d bytes.\n", size);
/* Decode. */
foo_p = hello_world_foo_new(&workspace[0], sizeof(workspace));
if (foo_p == NULL) {
return (3);
}
size = hello_world_foo_decode(foo_p, &encoded[0], size);
if (size < 0) {
return (4);
}
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 created pbtools.[hc] and address_book.[hc].
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pbtools-0.9.0.tar.gz.
File metadata
- Download URL: pbtools-0.9.0.tar.gz
- Upload date:
- Size: 89.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.9.1 pkginfo/1.4.1 requests/2.18.1 setuptools/38.5.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/2.7.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
049cab9104c709e2ad43e4002947dee747a0e2c26bef02837ec5856bbd48e8b4
|
|
| MD5 |
b752b7f4dc56a4e73bc0fa1d3b4d77f3
|
|
| BLAKE2b-256 |
919864b13d3866ab52524e14b0e5d7c88e3838adb17163e14a009d20fb86c892
|
File details
Details for the file pbtools-0.9.0-py2.py3-none-any.whl.
File metadata
- Download URL: pbtools-0.9.0-py2.py3-none-any.whl
- Upload date:
- Size: 25.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.9.1 pkginfo/1.4.1 requests/2.18.1 setuptools/38.5.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/2.7.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9b6f2cc58b165bc5d4d1df8083cf4128fb1b517563cb0184b1a55bc7bac4bc6
|
|
| MD5 |
089c9b7ac99617a1217b926ab2d147bf
|
|
| BLAKE2b-256 |
ed140344e7d9751123ee3d609fafdc32bd4796308e4474c14fd78525c752022f
|