Skip to content

D-Programming-Deimos/Nanopb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Nanopb

Nanopb - protocol buffers with small code size - http://koti.kapsi.fi/jpa/nanopb/

Nanopb is an ANSI-C library for encoding and decoding messages in Google's Protocol Buffers format with minimal requirements for RAM and code space. It is primarily suitable for 32-bit microcontrollers.

Notes and Differences from C version

  • Currently, you MUST link with a version of Nanopb that was either NOT compiled by GCC, or if it was compiled with GCC, then with either __GNUC__ undefined or __attribute__((packed)) disabled. Otherwise, the C side will use packed structs while the D side uses non-packed structs, and things will not work correctly.

  • In the C version, PB_MAX_REQUIRED_FIELDS can be overridden from either the command line, or by changing it directly in the C header. D does not support setting values from the command line, so it can ONLY be changed by directly modifying the D import module.

  • Remember that D's enum values require using the enum's type name. So if, for example, your C code used PB_LTYPE_VARINT, then in D you must say pb_type_t.PB_LTYPE_VARINT.

  • Remember that any callbacks you provide to Nanopb must be extern(C).

  • The headers you generate with Nanopb's generator tool still must be translated into D import modules. This Deimos project cannot provide them for you because they are specific to YOUR protobuf messages. Only bindings for the common Nanopb headers (pb.h, pb_encode.h and pb_decode.h) are, and can be, provided.

  • The macros UNUSED and STATIC_ASSERT are not included as they are not needed in D.

  • The macros pb_arraysize, pb_delta, pb_delta_end, and PB_LAST_FIELD are not currently included. But that should be ok since they appear to only be intended for use by the non-header C code generated by Nanopb's generator tool.

  • The macro PB_RETURN_ERROR was changed to a CTFE function which returns a string to be mixed-in.

  • Note that if you compile the C side with DMC, you'll need to change line #193 in pb.h like this:

From:
#define pb_membersize(st, m) (sizeof ((st*)0)->m)
To:
#define pb_membersize(st, m) (sizeof (((st*)0)->m))

About

Nanopb - protocol buffers with small code size - http://koti.kapsi.fi/jpa/nanopb/

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published