shiyilei / protobuf-c

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

optional missing in sub-message #90

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. In a protofile

message CVsMessage {
  required uint32 Command = 1;
  optional uint32 sequence = 2;
  optional uint32 total = 3;
}

message CVsMsgComponentWithAssts {
    message CVsComponentItem {

        required uint32 id = 1;
        optional string string1 = 2;
        optional string string2 = 3;
        required int32 perms = 4;
    }

  required CVsMessage hdr = 1;

  required uint32 id = 2;
  required string name = 3;
  optional string desc = 4;

    repeated CVsComponentItem assets = 5;
}

2. compile it
3.

What is the expected output? What do you see instead?
/* --- messages --- */

struct  _VsMessage__CVsMessage
{
  ProtobufCMessage base;
  uint32_t command;
  protobuf_c_boolean has_sequence;
  uint32_t sequence;
  protobuf_c_boolean has_total;
  uint32_t total;
};
#define VS_MESSAGE__CVS_MESSAGE__INIT \
 { PROTOBUF_C_MESSAGE_INIT (&vs_message__cvs_message__descriptor) \
    , 0, 0,0, 0,0 }

****VSMessage is OK *****

struct  _VsMessage__CVsMsgComponentWithAssts__CVsComponentItem
{
  ProtobufCMessage base;
  uint32_t id;
  char *string1;
  protobuf_c_boolean has_string2;
  char  *string2;
  int32_t perms;
};
#define VS_MESSAGE__CVS_MSG_COMPONENT_WITH_ASSTS__CVS_COMPONENT_ITEM__INIT \
 { PROTOBUF_C_MESSAGE_INIT (&vs_message__cvs_msg_component_with_assts__cvs_component_item__descriptor) \
    , 0, NULL, 0,0, 0 }

**** CVsComponentItem is ok *****

struct  _VsMessage__CVsMsgComponentWithAssts
{
  ProtobufCMessage base;
  VsMessage__CVsMessage *hdr;
  uint32_t id;
  char *name;
  char *desc;
  size_t n_assets;
  VsMessage__CVsMsgComponentWithAssts__CVsComponentItem **assets;
};
#define VS_MESSAGE__CVS_MSG_COMPONENT_WITH_ASSTS__INIT \
 { PROTOBUF_C_MESSAGE_INIT (&vs_message__cvs_msg_component_with_assts__descriptor) \
    , NULL, 0, NULL, NULL, 0,NULL }

***** desc isn't marked as optional *****

What version of the product are you using? On what operating system?
latest, x86

Please provide any additional information below.

Original issue reported on code.google.com by gbeauche...@gmail.com on 3 Oct 2012 at 12:23

GoogleCodeExporter commented 8 years ago
According to the documentation:

       Notice:
          there is no has_ flag for optional submessages -- if the pointer is non-NULL, then we assume that it is a value.

Original comment by mich...@hinespot.com on 29 Dec 2012 at 3:39