Skip to content

Instantly share code, notes, and snippets.

@rambattu
Created August 9, 2019 20:59
Show Gist options
  • Save rambattu/7575ea0786d4f2d0843d2393d4e5c7c7 to your computer and use it in GitHub Desktop.
Save rambattu/7575ea0786d4f2d0843d2393d4e5c7c7 to your computer and use it in GitHub Desktop.
protobuf-c 1.3.1 issue with PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE

Software versions:

  • Protobuf - 3.6.1
  • Protobuf-c - 1.3.1

Commands ran:

$protoc --c_out=. enum_int_test.proto . 

$ gcc enum_int_test.c  
In file included from enum_int_test.pb-c.h:7:0,  
                 from enum_int_test.c:1:  
enum_int_test.pb-c.h:35:5: error: redeclaration of enumerator ‘_ENUM_INT_TEST__LABEL_IS_INT_SIZE’ . 
     PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(ENUM_INT_TEST__LABEL) 
     ^
enum_int_test.pb-c.h:26:5: note: previous definition of ‘_ENUM_INT_TEST__LABEL_IS_INT_SIZE’ was here
     PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(ENUM_INT_TEST__LABEL)
     ^
#include "enum_int_test.pb-c.h"
int main(){
return 0;
}
/* Generated by the protocol buffer compiler. DO NOT EDIT! */
/* Generated from: enum_int_test.proto */
/* Do not generate deprecated warnings for self */
#ifndef PROTOBUF_C__NO_DEPRECATED
#define PROTOBUF_C__NO_DEPRECATED
#endif
#include "enum_int_test.pb-c.h"
void enum_int_test__init
(EnumIntTest *message)
{
static const EnumIntTest init_value = ENUM_INT_TEST__INIT;
*message = init_value;
}
size_t enum_int_test__get_packed_size
(const EnumIntTest *message)
{
assert(message->base.descriptor == &enum_int_test__descriptor);
return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t enum_int_test__pack
(const EnumIntTest *message,
uint8_t *out)
{
assert(message->base.descriptor == &enum_int_test__descriptor);
return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t enum_int_test__pack_to_buffer
(const EnumIntTest *message,
ProtobufCBuffer *buffer)
{
assert(message->base.descriptor == &enum_int_test__descriptor);
return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
EnumIntTest *
enum_int_test__unpack
(ProtobufCAllocator *allocator,
size_t len,
const uint8_t *data)
{
return (EnumIntTest *)
protobuf_c_message_unpack (&enum_int_test__descriptor,
allocator, len, data);
}
void enum_int_test__free_unpacked
(EnumIntTest *message,
ProtobufCAllocator *allocator)
{
if(!message)
return;
assert(message->base.descriptor == &enum_int_test__descriptor);
protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
static const ProtobufCEnumValue enum_int_test__label__enum_values_by_number[2] =
{
{ "LABEL_1", "ENUM_INT_TEST__LABEL__LABEL_1", 0 },
{ "LABEL_2", "ENUM_INT_TEST__LABEL__LABEL_2", 1 },
};
static const ProtobufCIntRange enum_int_test__label__value_ranges[] = {
{0, 0},{0, 2}
};
static const ProtobufCEnumValueIndex enum_int_test__label__enum_values_by_name[2] =
{
{ "LABEL_1", 0 },
{ "LABEL_2", 1 },
};
const ProtobufCEnumDescriptor enum_int_test__label__descriptor =
{
PROTOBUF_C__ENUM_DESCRIPTOR_MAGIC,
"EnumIntTest.Label",
"Label",
"EnumIntTest__Label",
"",
2,
enum_int_test__label__enum_values_by_number,
2,
enum_int_test__label__enum_values_by_name,
1,
enum_int_test__label__value_ranges,
NULL,NULL,NULL,NULL /* reserved[1234] */
};
static const ProtobufCFieldDescriptor enum_int_test__field_descriptors[2] =
{
{
"label_label",
123,
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_ENUM,
offsetof(EnumIntTest, label_case),
offsetof(EnumIntTest, label_label),
&enum_int_test__label__descriptor,
NULL,
0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */
},
{
"label_uint64",
124,
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_UINT64,
offsetof(EnumIntTest, label_case),
offsetof(EnumIntTest, label_uint64),
NULL,
NULL,
0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */
},
};
static const unsigned enum_int_test__field_indices_by_name[] = {
0, /* field[0] = label_label */
1, /* field[1] = label_uint64 */
};
static const ProtobufCIntRange enum_int_test__number_ranges[1 + 1] =
{
{ 123, 0 },
{ 0, 2 }
};
const ProtobufCMessageDescriptor enum_int_test__descriptor =
{
PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
"EnumIntTest",
"EnumIntTest",
"EnumIntTest",
"",
sizeof(EnumIntTest),
2,
enum_int_test__field_descriptors,
enum_int_test__field_indices_by_name,
1, enum_int_test__number_ranges,
(ProtobufCMessageInit) enum_int_test__init,
NULL,NULL,NULL /* reserved[123] */
};
/* Generated by the protocol buffer compiler. DO NOT EDIT! */
/* Generated from: enum_int_test.proto */
#ifndef PROTOBUF_C_enum_5fint_5ftest_2eproto__INCLUDED
#define PROTOBUF_C_enum_5fint_5ftest_2eproto__INCLUDED
#include <protobuf-c/protobuf-c.h>
PROTOBUF_C__BEGIN_DECLS
#if PROTOBUF_C_VERSION_NUMBER < 1003000
# error This file was generated by a newer version of protoc-c which is incompatible with your libprotobuf-c headers. Please update your headers.
#elif 1003001 < PROTOBUF_C_MIN_COMPILER_VERSION
# error This file was generated by an older version of protoc-c which is incompatible with your libprotobuf-c headers. Please regenerate this file with a newer version of protoc-c.
#endif
typedef struct _EnumIntTest EnumIntTest;
/* --- enums --- */
typedef enum _EnumIntTest__Label {
ENUM_INT_TEST__LABEL__LABEL_1 = 0,
ENUM_INT_TEST__LABEL__LABEL_2 = 1
PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(ENUM_INT_TEST__LABEL)
} EnumIntTest__Label;
/* --- messages --- */
typedef enum {
ENUM_INT_TEST__LABEL__NOT_SET = 0,
ENUM_INT_TEST__LABEL_LABEL_LABEL = 123,
ENUM_INT_TEST__LABEL_LABEL_UINT64 = 124
PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(ENUM_INT_TEST__LABEL)
} EnumIntTest__LabelCase;
struct _EnumIntTest
{
ProtobufCMessage base;
EnumIntTest__LabelCase label_case;
union {
EnumIntTest__Label label_label;
uint64_t label_uint64;
};
};
#define ENUM_INT_TEST__INIT \
{ PROTOBUF_C_MESSAGE_INIT (&enum_int_test__descriptor) \
, ENUM_INT_TEST__LABEL__NOT_SET, {0} }
/* EnumIntTest methods */
void enum_int_test__init
(EnumIntTest *message);
size_t enum_int_test__get_packed_size
(const EnumIntTest *message);
size_t enum_int_test__pack
(const EnumIntTest *message,
uint8_t *out);
size_t enum_int_test__pack_to_buffer
(const EnumIntTest *message,
ProtobufCBuffer *buffer);
EnumIntTest *
enum_int_test__unpack
(ProtobufCAllocator *allocator,
size_t len,
const uint8_t *data);
void enum_int_test__free_unpacked
(EnumIntTest *message,
ProtobufCAllocator *allocator);
/* --- per-message closures --- */
typedef void (*EnumIntTest_Closure)
(const EnumIntTest *message,
void *closure_data);
/* --- services --- */
/* --- descriptors --- */
extern const ProtobufCMessageDescriptor enum_int_test__descriptor;
extern const ProtobufCEnumDescriptor enum_int_test__label__descriptor;
PROTOBUF_C__END_DECLS
#endif /* PROTOBUF_C_enum_5fint_5ftest_2eproto__INCLUDED */
syntax = "proto3";
message EnumIntTest {
enum Label {
LABEL_1 = 0;
LABEL_2 = 1;
}
oneof label {
Label label_label = 123;
uint64 label_uint64 = 124;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment