digideskio / protobuf-c

Automatically exported from code.google.com/p/protobuf-c
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

cannot get regth size form double message #64

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I write a .proto like this:
//  pcoper.proto
//
message OperData{       
      required int32      fid        = 1;
      required int32      tid        = 2;
      required int64      value      = 3;
      required int32      type       = 4;
      optional string     time       = 5;
}

message UserOper{
      required int64     userid      = 1;
      required string    version     = 2;
      required int32     platform    = 3;
      repeated OperData  operlist    = 4;
}

my code:

#include    <stdio.h>
#include    <stdlib.h>

#include    "pcoper.pb-c.h"

int
main ( int argc, char *argv[] ) {

    OperData operdata[1];
    oper_data__init(&(operdata[0]));

    UserOper *useroper;
    useroper = malloc(sizeof(UserOper));
    user_oper__init(useroper);

    operdata[0].fid = 1;
    operdata[0].tid = 2;
    operdata[0].value = 5;
    operdata[0].time = "20110512123432";

    useroper->userid = 123;
    useroper->version = "4.3.1234";
    useroper->platform = 0;
    useroper->operlist = &operdata;
    size_t operdata_size = oper_data__get_packed_size(operdata);

    size_t useroper_size = user_oper__get_packed_size(useroper);
    printf(":%d\n", useroper_size);
    char *useroper_buf = malloc(sizeof(char) * useroper_size);
    size_t useroper_pack_size = user_oper__pack(useroper, useroper_buf);

    return 0;
}

Makefile:
gcc -o test test.c pcoper.pb-c.c -lprototbuf-c -g -Wall 

I print message UserOper length by user_oper__get_packed_size(useroper) 
function, the size less than oper_data__get_packed_size(operdata).
But use test.proto is allrigth.

Original issue reported on code.google.com by bj.yuey...@gmail.com on 11 Jun 2011 at 7:04

GoogleCodeExporter commented 8 years ago
sorry, I miss n_pkglist = 1;
No problem now

Original comment by bj.yuey...@gmail.com on 13 Jun 2011 at 5:25

GoogleCodeExporter commented 8 years ago
issue resolved by reporter

Original comment by lahike...@gmail.com on 14 Jun 2011 at 1:19