Skip to content
A protocol buffers library for C
Find file
New pull request
Pull request Compare This branch is 152 commits behind cloudwu:master.
Fetching latest commit...
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


PBC is a google protocol buffers library for C without code generation.

Quick Example

package tutorial;

message Person {
  required string name = 1;
  required int32 id = 2;        // Unique ID number for this person.
  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;
struct pbc_rmessage * m = pbc_rmessage_new(env, "tutorial.Person", slice);
printf("name = %s\n", pbc_rmessage_string(m , "name" , 0 , NULL));
printf("id = %d\n", pbc_rmessage_integer(m , "id" , 0 , NULL));
printf("email = %s\n", pbc_rmessage_string(m , "email" , 0 , NULL));

int phone_n = pbc_rmessage_size(m, "phone");
int i;

for (i=0;i<phone_n;i++) {
    struct pbc_rmessage * p = pbc_rmessage_message(m , "phone", i);
    printf("\tnumber[%d] = %s\n",i,pbc_rmessage_string(p , "number", i ,NULL));
    printf("\ttype[%d] = %s\n",i,pbc_rmessage_string(p, "type", i, NULL));


Message API

You can use wmessage for encoding , and rmessage for decoding.

See test/addressbook.c for detail.

Pattern API

If you need higher performance , you can use pbc_pattern_xxx api .

See test/pattern.c for detail.

pattern api is faster, and less memory used, and you can access data from native C struct .


PBC support extension with a simple way . It add prefix to the extension field name.


Not supported


With message API , you can use both string and integer as the enum type , and with pattern api it must be integer.

Question ?

Something went wrong with that request. Please try again.