All Projects → squidfunk → protobluff

squidfunk / protobluff

Licence: MIT license
A modular Protocol Buffers implementation for C

Programming Languages

c
50402 projects - #5 most used programming language
C++
36643 projects - #6 most used programming language
Makefile
30231 projects
M4
1887 projects
CSS
56736 projects
shell
77523 projects
GDB
78 projects

Projects that are alternatives of or similar to protobluff

Api
Minimal, extremely fast, lightweight Ruby framework for HTTP APIs
Stars: ✭ 252 (+281.82%)
Mutual labels:  lightweight
arrow
An interpreted programming language
Stars: ✭ 21 (-68.18%)
Mutual labels:  lightweight
jpopup
Simple lightweight (<2kB) javascript popup modal plugin
Stars: ✭ 27 (-59.09%)
Mutual labels:  lightweight
Pareto.js
An extremely small, intuitive and fast functional utility library for JavaScript
Stars: ✭ 254 (+284.85%)
Mutual labels:  lightweight
hugoblog
Hugoblog is responsive, simple, and clean that would fit for your personal blog based on Hugo Theme Static Site Generator (SSG)
Stars: ✭ 48 (-27.27%)
Mutual labels:  lightweight
Lucid-Browser
Source code for Lucid browser on Play Store
Stars: ✭ 103 (+56.06%)
Mutual labels:  lightweight
Pine
A modern, native macOS markdown editor
Stars: ✭ 2,818 (+4169.7%)
Mutual labels:  lightweight
Vodka
simple and tiny PHP flat-file site engine
Stars: ✭ 19 (-71.21%)
Mutual labels:  lightweight
string-combinations
A simple, low-memory footprint function to generate all string combinations from a series of characters.
Stars: ✭ 25 (-62.12%)
Mutual labels:  lightweight
rules proto grpc
Bazel rules for building Protobuf and gRPC code and libraries from proto_library targets
Stars: ✭ 201 (+204.55%)
Mutual labels:  protocol-buffers
Moveto
A lightweight scroll animation javascript library without any dependency
Stars: ✭ 2,746 (+4060.61%)
Mutual labels:  lightweight
ThreadPool2
Lightweight, Generic, Pure C++11 ThreadPool
Stars: ✭ 28 (-57.58%)
Mutual labels:  lightweight
rh
Resource Harvester - a tool to gather low-level system data and make it easy to use programmatically
Stars: ✭ 18 (-72.73%)
Mutual labels:  lightweight
Yalla
YallaJS, ES6 Templating Engine.
Stars: ✭ 253 (+283.33%)
Mutual labels:  lightweight
wui
Collection of GUI widgets for the web
Stars: ✭ 44 (-33.33%)
Mutual labels:  lightweight
Yay Evil Emacs
😈 A lightweight literate Emacs config with even better "better defaults". Shipped with a custom theme!
Stars: ✭ 250 (+278.79%)
Mutual labels:  lightweight
lightcookie
Node cookie parsing and serialization
Stars: ✭ 22 (-66.67%)
Mutual labels:  lightweight
j2cl-protobuf
Protocol Buffers implementation for J2CL
Stars: ✭ 23 (-65.15%)
Mutual labels:  protocol-buffers
MachineLearning
An easy neural network for Java!
Stars: ✭ 125 (+89.39%)
Mutual labels:  lightweight
ytmous
Anonymous Youtube Proxy
Stars: ✭ 60 (-9.09%)
Mutual labels:  lightweight

protobluff

Travis Codecov Gitter Release

protobluff is a modular Protocol Buffers implementation for C.

Theory of Operation

Protocol Buffers is a language-neutral, platform-neutral and extensible message format developed by Google for serializing structured data. It uses schema files to describe the structure of messages, which are in turn used to generate language-specific bindings to automatically handle the decoding and encoding for the developer. However, as messages can have a variable amount of repeated submessages and fields, decoding and encoding may involve a large number of scattered allocations which in turn is not very cache-friendly.

protobluff follows a different approach. It entirely skips the necessary decoding and encoding steps when reading or writing values from messages, as it directly operates on the encoded data. New values can be incrementally read or written, memory management is centralized and handled by the underlying journal. If no alterations that change the size of the underlying journal are expected, the journal can be used in zero-copy mode, omitting all dynamic allocations.

Installation

Building from source

protobluff is built using Autotools and can be linked as a static or shared library. It has no runtime dependencies and is fully self-contained, except for the code generator which depends on the original Protocol Buffers library and is necessary to generate bindings from .proto schema files. If the original library is not available, the generator is not built. The following commands build and install the protobluff library and code generator:

./autogen.sh &&
./configure &&
make &&
make test &&
make install

protobluff should compile and run on all UNIX systems (including Linux and Mac OS) as it adheres to the C99 and C++98 standards and does not make use of any system-specific functionality.

After installing protobluff, the code generator can be used to generate bindings from .proto schema files to get started. See this section for more information.

Additional options

By default, protobluff is compiled aggressively optimized with -O3 and some further optimizations which make it nearly impossible to debug. If debugging is necessary, one should disable optimizations. Stripped compilation will remove all symbols that are not defined in the public header files, allowing further optimizations. Enabling the coverage report is only necessary to determine unit test coverage, and thus only needed during development.

./configure
  --disable-optimized # No optimizations (default: enabled)
  --enable-stripped   # Strip internal symbols (default: disabled)
  --enable-coverage   # Coverage report (default: disabled)

The tests can only be built if stripped compilation is not enabled, as no internal symbols would be visible to the unit tests.

Using the code generator

The code generator is tightly integrated with the protoc compiler toolchain included in the default Protocol Buffers distribution. Use the protoc command to invoke the protobluff code generator through the --protobluff_out flag, to generate and write the respective .pb.c and .pb.h files to a specific location:

protoc --protobluff_out=. *.proto

The .pb.h header files will contain the bindings, the .pb.c source files contain the descriptor definitions which are referenced by the bindings. Therefore, the source files must be compiled together with your project.

Using the generated bindings

Here's a usage example taken from the original description of the Google Protocol Buffers library and adapted to protobluff:

/* Create an empty journal to assemble a new person message */
pb_journal_t journal = pb_journal_create_empty();

/* Create a person message */
pb_message_t person = person_create(&journal);

/* Define the values we want to set */
pb_string_t name   = pb_string_init_from_chars("John Doe"),
            email  = pb_string_init_from_chars("[email protected]"),
            home   = pb_string_init_from_chars("+1-541-754-3010"),
            mobile = pb_string_init_from_chars("+1-541-293-8228");
int32_t     id     = 1234;

/* Set values on person message and check return codes */
pb_error_t error = PB_ERROR_NONE;
do {
  if ((error = person_put_name(&person, &name)) ||
      (error = person_put_id(&person, &id)) ||
      (error = person_put_email(&person, &email)))
    break;

  /* Set home number */
  pb_message_t phone1 = person_create_phone(&person);
  if (!(error = person_phonenumber_put_number(&phone1, &home)) &&
      !(error = person_phonenumber_put_type_home(&phone1))) {

    /* Set mobile number */
    pb_message_t phone2 = person_create_phone(&person);
    if (!(error = person_phonenumber_put_number(&phone2, &mobile)) &&
        !(error = person_phonenumber_put_type_mobile(&phone2))) {

      /* Dump the journal */
      pb_journal_dump(&journal);

      /* The encoded message can be accessed as follows */
      // const uint8_t *data = pb_journal_data(&journal);
      // const size_t   size = pb_journal_size(&journal);
    }
    person_phonenumber_destroy(&phone2);
  }
  person_phonenumber_destroy(&phone1);
} while (0);

/* Print error, if any */
if (error)
  fprintf(stderr, "ERROR: %s\n", pb_error_string(error));

/* Cleanup and invalidate */
person_destroy(&person);

/* Free all allocated memory and return */
pb_journal_destroy(&journal);
return error
  ? EXIT_FAILURE
  : EXIT_SUCCESS;

See the examples directory for more information.

Linking

Manually

For the generated bindings to function, your project must be linked against the protobluff runtime. The recommended way is to dynamically link the shared library. Therefore, the following compiler and linker flags must be obtained and added to your build toolchain:

pkg-config --cflags protobluff # Add output to compiler flags
pkg-config --libs   protobluff # Add output to linker flags

Autotools

If you're using Autotools, the PKG_CHECK_MODULES macro will take care of the heavy lifting. Adding the following line to your configure.ac file will place the compiler flags into the variable protobluff_CFLAGS and the linker flags into the variable protobluff_LDFLAGS:

PKG_CHECK_MODULES([protobluff], [protobluff])

Features

Already supported

  1. Message definitions
  2. Nested submessage definitions
  3. All scalar types
  4. Enumerations
  5. Strings and binaries
  6. Optional, required and repeated fields
  7. Imports
  8. Packages
  9. Extensions and nested extensions
  10. Deprecations for messages, fields, enums and enum values
  11. Packed fields
  12. Oneofs

Not (yet) supported

  1. proto3 support
  2. Services (using gRPC and/or ZMQ)
  3. Groups (unsure)

protobluff is basically compatible with proto3, as proto2 is binary compatible, but some special types like maps and the Any type need to be implemented.

License

Copyright (c) 2013-2020 Martin Donath

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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].