提交 b8831606 编写于 作者: L liuruilong

format files

上级 30d22c55
...@@ -45,19 +45,19 @@ ...@@ -45,19 +45,19 @@
* \todo Use size_t consistently. * \todo Use size_t consistently.
*/ */
#include <stdlib.h> /* for malloc, free */ #include <stdlib.h> /* for malloc, free */
#include <string.h> /* for strcmp, strlen, memcpy, memmove, memset */ #include <string.h> /* for strcmp, strlen, memcpy, memmove, memset */
#include "protobuf-c.h" #include "protobuf-c.h"
#define TRUE 1 #define TRUE 1
#define FALSE 0 #define FALSE 0
#define PROTOBUF_C__ASSERT_NOT_REACHED() assert(0) #define PROTOBUF_C__ASSERT_NOT_REACHED() assert(0)
/* Workaround for Microsoft compilers. */ /* Workaround for Microsoft compilers. */
#ifdef _MSC_VER #ifdef _MSC_VER
# define inline __inline #define inline __inline
#endif #endif
/** /**
...@@ -78,10 +78,10 @@ ...@@ -78,10 +78,10 @@
*/ */
/** The maximum length of a 64-bit integer in varint encoding. */ /** The maximum length of a 64-bit integer in varint encoding. */
#define MAX_UINT64_ENCODED_SIZE 10 #define MAX_UINT64_ENCODED_SIZE 10
#ifndef PROTOBUF_C_UNPACK_ERROR #ifndef PROTOBUF_C_UNPACK_ERROR
# define PROTOBUF_C_UNPACK_ERROR(...) #define PROTOBUF_C_UNPACK_ERROR(...)
#endif #endif
const char protobuf_c_empty_string[] = ""; const char protobuf_c_empty_string[] = "";
...@@ -93,7 +93,7 @@ const char protobuf_c_empty_string[] = ""; ...@@ -93,7 +93,7 @@ const char protobuf_c_empty_string[] = "";
* STRUCT_MEMBER_PTR(). * STRUCT_MEMBER_PTR().
*/ */
#define STRUCT_MEMBER_P(struct_p, struct_offset) \ #define STRUCT_MEMBER_P(struct_p, struct_offset) \
((void *) ((uint8_t *) (struct_p) + (struct_offset))) ((void *)((uint8_t *)(struct_p) + (struct_offset)))
/** /**
* Return field in a `ProtobufCMessage` based on offset. * Return field in a `ProtobufCMessage` based on offset.
...@@ -102,7 +102,7 @@ const char protobuf_c_empty_string[] = ""; ...@@ -102,7 +102,7 @@ const char protobuf_c_empty_string[] = "";
* Cast it to the passed type. * Cast it to the passed type.
*/ */
#define STRUCT_MEMBER(member_type, struct_p, struct_offset) \ #define STRUCT_MEMBER(member_type, struct_p, struct_offset) \
(*(member_type *) STRUCT_MEMBER_P((struct_p), (struct_offset))) (*(member_type *)STRUCT_MEMBER_P((struct_p), (struct_offset)))
/** /**
* Return field in a `ProtobufCMessage` based on offset. * Return field in a `ProtobufCMessage` based on offset.
...@@ -111,63 +111,44 @@ const char protobuf_c_empty_string[] = ""; ...@@ -111,63 +111,44 @@ const char protobuf_c_empty_string[] = "";
* it to a pointer to the passed type. * it to a pointer to the passed type.
*/ */
#define STRUCT_MEMBER_PTR(member_type, struct_p, struct_offset) \ #define STRUCT_MEMBER_PTR(member_type, struct_p, struct_offset) \
((member_type *) STRUCT_MEMBER_P((struct_p), (struct_offset))) ((member_type *)STRUCT_MEMBER_P((struct_p), (struct_offset)))
/* Assertions for magic numbers. */ /* Assertions for magic numbers. */
#define ASSERT_IS_ENUM_DESCRIPTOR(desc) \ #define ASSERT_IS_ENUM_DESCRIPTOR(desc) \
assert((desc)->magic == PROTOBUF_C__ENUM_DESCRIPTOR_MAGIC) assert((desc)->magic == PROTOBUF_C__ENUM_DESCRIPTOR_MAGIC)
#define ASSERT_IS_MESSAGE_DESCRIPTOR(desc) \ #define ASSERT_IS_MESSAGE_DESCRIPTOR(desc) \
assert((desc)->magic == PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC) assert((desc)->magic == PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC)
#define ASSERT_IS_MESSAGE(message) \ #define ASSERT_IS_MESSAGE(message) \
ASSERT_IS_MESSAGE_DESCRIPTOR((message)->descriptor) ASSERT_IS_MESSAGE_DESCRIPTOR((message)->descriptor)
#define ASSERT_IS_SERVICE_DESCRIPTOR(desc) \ #define ASSERT_IS_SERVICE_DESCRIPTOR(desc) \
assert((desc)->magic == PROTOBUF_C__SERVICE_DESCRIPTOR_MAGIC) assert((desc)->magic == PROTOBUF_C__SERVICE_DESCRIPTOR_MAGIC)
/**@}*/ /**@}*/
/* --- version --- */ /* --- version --- */
const char * const char *protobuf_c_version(void) { return PROTOBUF_C_VERSION; }
protobuf_c_version(void)
{
return PROTOBUF_C_VERSION;
}
uint32_t uint32_t protobuf_c_version_number(void) { return PROTOBUF_C_VERSION_NUMBER; }
protobuf_c_version_number(void)
{
return PROTOBUF_C_VERSION_NUMBER;
}
/* --- allocator --- */ /* --- allocator --- */
static void * static void *system_alloc(void *allocator_data, size_t size) {
system_alloc(void *allocator_data, size_t size) return malloc(size);
{
return malloc(size);
} }
static void static void system_free(void *allocator_data, void *data) { free(data); }
system_free(void *allocator_data, void *data)
{
free(data);
}
static inline void * static inline void *do_alloc(ProtobufCAllocator *allocator, size_t size) {
do_alloc(ProtobufCAllocator *allocator, size_t size) return allocator->alloc(allocator->allocator_data, size);
{
return allocator->alloc(allocator->allocator_data, size);
} }
static inline void static inline void do_free(ProtobufCAllocator *allocator, void *data) {
do_free(ProtobufCAllocator *allocator, void *data) if (data != NULL) allocator->free(allocator->allocator_data, data);
{
if (data != NULL)
allocator->free(allocator->allocator_data, data);
} }
/* /*
...@@ -176,42 +157,37 @@ do_free(ProtobufCAllocator *allocator, void *data) ...@@ -176,42 +157,37 @@ do_free(ProtobufCAllocator *allocator, void *data)
* function. * function.
*/ */
static ProtobufCAllocator protobuf_c__allocator = { static ProtobufCAllocator protobuf_c__allocator = {
.alloc = &system_alloc, .alloc = &system_alloc,
.free = &system_free, .free = &system_free,
.allocator_data = NULL, .allocator_data = NULL,
}; };
/* === buffer-simple === */ /* === buffer-simple === */
void void protobuf_c_buffer_simple_append(ProtobufCBuffer *buffer, size_t len,
protobuf_c_buffer_simple_append(ProtobufCBuffer *buffer, const uint8_t *data) {
size_t len, const uint8_t *data) ProtobufCBufferSimple *simp = (ProtobufCBufferSimple *)buffer;
{ size_t new_len = simp->len + len;
ProtobufCBufferSimple *simp = (ProtobufCBufferSimple *) buffer;
size_t new_len = simp->len + len; if (new_len > simp->alloced) {
ProtobufCAllocator *allocator = simp->allocator;
if (new_len > simp->alloced) { size_t new_alloced = simp->alloced * 2;
ProtobufCAllocator *allocator = simp->allocator; uint8_t *new_data;
size_t new_alloced = simp->alloced * 2;
uint8_t *new_data; if (allocator == NULL) allocator = &protobuf_c__allocator;
while (new_alloced < new_len) new_alloced += new_alloced;
if (allocator == NULL) new_data = do_alloc(allocator, new_alloced);
allocator = &protobuf_c__allocator; if (!new_data) return;
while (new_alloced < new_len) memcpy(new_data, simp->data, simp->len);
new_alloced += new_alloced; if (simp->must_free_data)
new_data = do_alloc(allocator, new_alloced); do_free(allocator, simp->data);
if (!new_data) else
return; simp->must_free_data = TRUE;
memcpy(new_data, simp->data, simp->len); simp->data = new_data;
if (simp->must_free_data) simp->alloced = new_alloced;
do_free(allocator, simp->data); }
else memcpy(simp->data + simp->len, data, len);
simp->must_free_data = TRUE; simp->len = new_len;
simp->data = new_data;
simp->alloced = new_alloced;
}
memcpy(simp->data + simp->len, data, len);
simp->len = new_len;
} }
/** /**
...@@ -232,20 +208,18 @@ protobuf_c_buffer_simple_append(ProtobufCBuffer *buffer, ...@@ -232,20 +208,18 @@ protobuf_c_buffer_simple_append(ProtobufCBuffer *buffer,
* \return * \return
* Number of bytes required. * Number of bytes required.
*/ */
static inline size_t static inline size_t get_tag_size(uint32_t number) {
get_tag_size(uint32_t number) if (number < (1UL << 4)) {
{ return 1;
if (number < (1UL << 4)) { } else if (number < (1UL << 11)) {
return 1; return 2;
} else if (number < (1UL << 11)) { } else if (number < (1UL << 18)) {
return 2; return 3;
} else if (number < (1UL << 18)) { } else if (number < (1UL << 25)) {
return 3; return 4;
} else if (number < (1UL << 25)) { } else {
return 4; return 5;
} else { }
return 5;
}
} }
/** /**
...@@ -257,20 +231,18 @@ get_tag_size(uint32_t number) ...@@ -257,20 +231,18 @@ get_tag_size(uint32_t number)
* \return * \return
* Number of bytes required. * Number of bytes required.
*/ */
static inline size_t static inline size_t uint32_size(uint32_t v) {
uint32_size(uint32_t v) if (v < (1UL << 7)) {
{ return 1;
if (v < (1UL << 7)) { } else if (v < (1UL << 14)) {
return 1; return 2;
} else if (v < (1UL << 14)) { } else if (v < (1UL << 21)) {
return 2; return 3;
} else if (v < (1UL << 21)) { } else if (v < (1UL << 28)) {
return 3; return 4;
} else if (v < (1UL << 28)) { } else {
return 4; return 5;
} else { }
return 5;
}
} }
/** /**
...@@ -282,22 +254,20 @@ uint32_size(uint32_t v) ...@@ -282,22 +254,20 @@ uint32_size(uint32_t v)
* \return * \return
* Number of bytes required. * Number of bytes required.
*/ */
static inline size_t static inline size_t int32_size(int32_t v) {
int32_size(int32_t v) if (v < 0) {
{ return 10;
if (v < 0) { } else if (v < (1L << 7)) {
return 10; return 1;
} else if (v < (1L << 7)) { } else if (v < (1L << 14)) {
return 1; return 2;
} else if (v < (1L << 14)) { } else if (v < (1L << 21)) {
return 2; return 3;
} else if (v < (1L << 21)) { } else if (v < (1L << 28)) {
return 3; return 4;
} else if (v < (1L << 28)) { } else {
return 4; return 5;
} else { }
return 5;
}
} }
/** /**
...@@ -309,13 +279,11 @@ int32_size(int32_t v) ...@@ -309,13 +279,11 @@ int32_size(int32_t v)
* \return * \return
* ZigZag encoded integer. * ZigZag encoded integer.
*/ */
static inline uint32_t static inline uint32_t zigzag32(int32_t v) {
zigzag32(int32_t v) if (v < 0)
{ return (-(uint32_t)v) * 2 - 1;
if (v < 0) else
return (-(uint32_t)v) * 2 - 1; return (uint32_t)(v)*2;
else
return (uint32_t)(v) * 2;
} }
/** /**
...@@ -328,11 +296,7 @@ zigzag32(int32_t v) ...@@ -328,11 +296,7 @@ zigzag32(int32_t v)
* \return * \return
* Number of bytes required. * Number of bytes required.
*/ */
static inline size_t static inline size_t sint32_size(int32_t v) { return uint32_size(zigzag32(v)); }
sint32_size(int32_t v)
{
return uint32_size(zigzag32(v));
}
/** /**
* Return the number of bytes required to store a 64-bit unsigned integer in * Return the number of bytes required to store a 64-bit unsigned integer in
...@@ -343,26 +307,24 @@ sint32_size(int32_t v) ...@@ -343,26 +307,24 @@ sint32_size(int32_t v)
* \return * \return
* Number of bytes required. * Number of bytes required.
*/ */
static inline size_t static inline size_t uint64_size(uint64_t v) {
uint64_size(uint64_t v) uint32_t upper_v = (uint32_t)(v >> 32);
{
uint32_t upper_v = (uint32_t) (v >> 32); if (upper_v == 0) {
return uint32_size((uint32_t)v);
if (upper_v == 0) { } else if (upper_v < (1UL << 3)) {
return uint32_size((uint32_t) v); return 5;
} else if (upper_v < (1UL << 3)) { } else if (upper_v < (1UL << 10)) {
return 5; return 6;
} else if (upper_v < (1UL << 10)) { } else if (upper_v < (1UL << 17)) {
return 6; return 7;
} else if (upper_v < (1UL << 17)) { } else if (upper_v < (1UL << 24)) {
return 7; return 8;
} else if (upper_v < (1UL << 24)) { } else if (upper_v < (1UL << 31)) {
return 8; return 9;
} else if (upper_v < (1UL << 31)) { } else {
return 9; return 10;
} else { }
return 10;
}
} }
/** /**
...@@ -374,13 +336,11 @@ uint64_size(uint64_t v) ...@@ -374,13 +336,11 @@ uint64_size(uint64_t v)
* \return * \return
* ZigZag encoded integer. * ZigZag encoded integer.
*/ */
static inline uint64_t static inline uint64_t zigzag64(int64_t v) {
zigzag64(int64_t v) if (v < 0)
{ return (-(uint64_t)v) * 2 - 1;
if (v < 0) else
return (-(uint64_t)v) * 2 - 1; return (uint64_t)(v)*2;
else
return (uint64_t)(v) * 2;
} }
/** /**
...@@ -393,11 +353,7 @@ zigzag64(int64_t v) ...@@ -393,11 +353,7 @@ zigzag64(int64_t v)
* \return * \return
* Number of bytes required. * Number of bytes required.
*/ */
static inline size_t static inline size_t sint64_size(int64_t v) { return uint64_size(zigzag64(v)); }
sint64_size(int64_t v)
{
return uint64_size(zigzag64(v));
}
/** /**
* Calculate the serialized size of a single required message field, including * Calculate the serialized size of a single required message field, including
...@@ -410,54 +366,52 @@ sint64_size(int64_t v) ...@@ -410,54 +366,52 @@ sint64_size(int64_t v)
* \return * \return
* Number of bytes required. * Number of bytes required.
*/ */
static size_t static size_t required_field_get_packed_size(
required_field_get_packed_size(const ProtobufCFieldDescriptor *field, const ProtobufCFieldDescriptor *field, const void *member) {
const void *member) size_t rv = get_tag_size(field->id);
{
size_t rv = get_tag_size(field->id); switch (field->type) {
case PROTOBUF_C_TYPE_SINT32:
switch (field->type) { return rv + sint32_size(*(const int32_t *)member);
case PROTOBUF_C_TYPE_SINT32: case PROTOBUF_C_TYPE_ENUM:
return rv + sint32_size(*(const int32_t *) member); case PROTOBUF_C_TYPE_INT32:
case PROTOBUF_C_TYPE_ENUM: return rv + int32_size(*(const int32_t *)member);
case PROTOBUF_C_TYPE_INT32: case PROTOBUF_C_TYPE_UINT32:
return rv + int32_size(*(const int32_t *) member); return rv + uint32_size(*(const uint32_t *)member);
case PROTOBUF_C_TYPE_UINT32: case PROTOBUF_C_TYPE_SINT64:
return rv + uint32_size(*(const uint32_t *) member); return rv + sint64_size(*(const int64_t *)member);
case PROTOBUF_C_TYPE_SINT64: case PROTOBUF_C_TYPE_INT64:
return rv + sint64_size(*(const int64_t *) member); case PROTOBUF_C_TYPE_UINT64:
case PROTOBUF_C_TYPE_INT64: return rv + uint64_size(*(const uint64_t *)member);
case PROTOBUF_C_TYPE_UINT64: case PROTOBUF_C_TYPE_SFIXED32:
return rv + uint64_size(*(const uint64_t *) member); case PROTOBUF_C_TYPE_FIXED32:
case PROTOBUF_C_TYPE_SFIXED32: return rv + 4;
case PROTOBUF_C_TYPE_FIXED32: case PROTOBUF_C_TYPE_SFIXED64:
return rv + 4; case PROTOBUF_C_TYPE_FIXED64:
case PROTOBUF_C_TYPE_SFIXED64: return rv + 8;
case PROTOBUF_C_TYPE_FIXED64: case PROTOBUF_C_TYPE_BOOL:
return rv + 8; return rv + 1;
case PROTOBUF_C_TYPE_BOOL: case PROTOBUF_C_TYPE_FLOAT:
return rv + 1; return rv + 4;
case PROTOBUF_C_TYPE_FLOAT: case PROTOBUF_C_TYPE_DOUBLE:
return rv + 4; return rv + 8;
case PROTOBUF_C_TYPE_DOUBLE: case PROTOBUF_C_TYPE_STRING: {
return rv + 8; const char *str = *(char *const *)member;
case PROTOBUF_C_TYPE_STRING: { size_t len = str ? strlen(str) : 0;
const char *str = *(char * const *) member; return rv + uint32_size(len) + len;
size_t len = str ? strlen(str) : 0; }
return rv + uint32_size(len) + len; case PROTOBUF_C_TYPE_BYTES: {
} size_t len = ((const ProtobufCBinaryData *)member)->len;
case PROTOBUF_C_TYPE_BYTES: { return rv + uint32_size(len) + len;
size_t len = ((const ProtobufCBinaryData *) member)->len; }
return rv + uint32_size(len) + len; case PROTOBUF_C_TYPE_MESSAGE: {
} const ProtobufCMessage *msg = *(ProtobufCMessage *const *)member;
case PROTOBUF_C_TYPE_MESSAGE: { size_t subrv = msg ? protobuf_c_message_get_packed_size(msg) : 0;
const ProtobufCMessage *msg = *(ProtobufCMessage * const *) member; return rv + uint32_size(subrv) + subrv;
size_t subrv = msg ? protobuf_c_message_get_packed_size(msg) : 0; }
return rv + uint32_size(subrv) + subrv; }
} PROTOBUF_C__ASSERT_NOT_REACHED();
} return 0;
PROTOBUF_C__ASSERT_NOT_REACHED();
return 0;
} }
/** /**
...@@ -474,22 +428,18 @@ required_field_get_packed_size(const ProtobufCFieldDescriptor *field, ...@@ -474,22 +428,18 @@ required_field_get_packed_size(const ProtobufCFieldDescriptor *field,
* \return * \return
* Number of bytes required. * Number of bytes required.
*/ */
static size_t static size_t oneof_field_get_packed_size(const ProtobufCFieldDescriptor *field,
oneof_field_get_packed_size(const ProtobufCFieldDescriptor *field, uint32_t oneof_case,
uint32_t oneof_case, const void *member) {
const void *member) if (oneof_case != field->id) {
{ return 0;
if (oneof_case != field->id) { }
return 0; if (field->type == PROTOBUF_C_TYPE_MESSAGE ||
} field->type == PROTOBUF_C_TYPE_STRING) {
if (field->type == PROTOBUF_C_TYPE_MESSAGE || const void *ptr = *(const void *const *)member;
field->type == PROTOBUF_C_TYPE_STRING) if (ptr == NULL || ptr == field->default_value) return 0;
{ }
const void *ptr = *(const void * const *) member; return required_field_get_packed_size(field, member);
if (ptr == NULL || ptr == field->default_value)
return 0;
}
return required_field_get_packed_size(field, member);
} }
/** /**
...@@ -506,69 +456,62 @@ oneof_field_get_packed_size(const ProtobufCFieldDescriptor *field, ...@@ -506,69 +456,62 @@ oneof_field_get_packed_size(const ProtobufCFieldDescriptor *field,
* \return * \return
* Number of bytes required. * Number of bytes required.
*/ */
static size_t static size_t optional_field_get_packed_size(
optional_field_get_packed_size(const ProtobufCFieldDescriptor *field, const ProtobufCFieldDescriptor *field, const protobuf_c_boolean has,
const protobuf_c_boolean has, const void *member) {
const void *member) if (field->type == PROTOBUF_C_TYPE_MESSAGE ||
{ field->type == PROTOBUF_C_TYPE_STRING) {
if (field->type == PROTOBUF_C_TYPE_MESSAGE || const void *ptr = *(const void *const *)member;
field->type == PROTOBUF_C_TYPE_STRING) if (ptr == NULL || ptr == field->default_value) return 0;
{ } else {
const void *ptr = *(const void * const *) member; if (!has) return 0;
if (ptr == NULL || ptr == field->default_value) }
return 0; return required_field_get_packed_size(field, member);
} else { }
if (!has)
return 0; static protobuf_c_boolean field_is_zeroish(
} const ProtobufCFieldDescriptor *field, const void *member) {
return required_field_get_packed_size(field, member); protobuf_c_boolean ret = FALSE;
}
switch (field->type) {
static protobuf_c_boolean case PROTOBUF_C_TYPE_BOOL:
field_is_zeroish(const ProtobufCFieldDescriptor *field, ret = (0 == *(const protobuf_c_boolean *)member);
const void *member) break;
{ case PROTOBUF_C_TYPE_ENUM:
protobuf_c_boolean ret = FALSE; case PROTOBUF_C_TYPE_SINT32:
case PROTOBUF_C_TYPE_INT32:
switch (field->type) { case PROTOBUF_C_TYPE_UINT32:
case PROTOBUF_C_TYPE_BOOL: case PROTOBUF_C_TYPE_SFIXED32:
ret = (0 == *(const protobuf_c_boolean *) member); case PROTOBUF_C_TYPE_FIXED32:
break; ret = (0 == *(const uint32_t *)member);
case PROTOBUF_C_TYPE_ENUM: break;
case PROTOBUF_C_TYPE_SINT32: case PROTOBUF_C_TYPE_SINT64:
case PROTOBUF_C_TYPE_INT32: case PROTOBUF_C_TYPE_INT64:
case PROTOBUF_C_TYPE_UINT32: case PROTOBUF_C_TYPE_UINT64:
case PROTOBUF_C_TYPE_SFIXED32: case PROTOBUF_C_TYPE_SFIXED64:
case PROTOBUF_C_TYPE_FIXED32: case PROTOBUF_C_TYPE_FIXED64:
ret = (0 == *(const uint32_t *) member); ret = (0 == *(const uint64_t *)member);
break; break;
case PROTOBUF_C_TYPE_SINT64: case PROTOBUF_C_TYPE_FLOAT:
case PROTOBUF_C_TYPE_INT64: ret = (0 == *(const float *)member);
case PROTOBUF_C_TYPE_UINT64: break;
case PROTOBUF_C_TYPE_SFIXED64: case PROTOBUF_C_TYPE_DOUBLE:
case PROTOBUF_C_TYPE_FIXED64: ret = (0 == *(const double *)member);
ret = (0 == *(const uint64_t *) member); break;
break; case PROTOBUF_C_TYPE_STRING:
case PROTOBUF_C_TYPE_FLOAT: ret = (NULL == *(const char *const *)member) ||
ret = (0 == *(const float *) member); ('\0' == **(const char *const *)member);
break; break;
case PROTOBUF_C_TYPE_DOUBLE: case PROTOBUF_C_TYPE_BYTES:
ret = (0 == *(const double *) member); case PROTOBUF_C_TYPE_MESSAGE:
break; ret = (NULL == *(const void *const *)member);
case PROTOBUF_C_TYPE_STRING: break;
ret = (NULL == *(const char * const *) member) || default:
('\0' == **(const char * const *) member); ret = TRUE;
break; break;
case PROTOBUF_C_TYPE_BYTES: }
case PROTOBUF_C_TYPE_MESSAGE:
ret = (NULL == *(const void * const *) member); return ret;
break;
default:
ret = TRUE;
break;
}
return ret;
} }
/** /**
...@@ -584,13 +527,10 @@ field_is_zeroish(const ProtobufCFieldDescriptor *field, ...@@ -584,13 +527,10 @@ field_is_zeroish(const ProtobufCFieldDescriptor *field,
* \return * \return
* Number of bytes required. * Number of bytes required.
*/ */
static size_t static size_t unlabeled_field_get_packed_size(
unlabeled_field_get_packed_size(const ProtobufCFieldDescriptor *field, const ProtobufCFieldDescriptor *field, const void *member) {
const void *member) if (field_is_zeroish(field, member)) return 0;
{ return required_field_get_packed_size(field, member);
if (field_is_zeroish(field, member))
return 0;
return required_field_get_packed_size(field, member);
} }
/** /**
...@@ -607,81 +547,72 @@ unlabeled_field_get_packed_size(const ProtobufCFieldDescriptor *field, ...@@ -607,81 +547,72 @@ unlabeled_field_get_packed_size(const ProtobufCFieldDescriptor *field,
* \return * \return
* Number of bytes required. * Number of bytes required.
*/ */
static size_t static size_t repeated_field_get_packed_size(
repeated_field_get_packed_size(const ProtobufCFieldDescriptor *field, const ProtobufCFieldDescriptor *field, size_t count, const void *member) {
size_t count, const void *member) size_t header_size;
{ size_t rv = 0;
size_t header_size; unsigned i;
size_t rv = 0; void *array = *(void *const *)member;
unsigned i;
void *array = *(void * const *) member; if (count == 0) return 0;
header_size = get_tag_size(field->id);
if (count == 0) if (0 == (field->flags & PROTOBUF_C_FIELD_FLAG_PACKED)) header_size *= count;
return 0;
header_size = get_tag_size(field->id); switch (field->type) {
if (0 == (field->flags & PROTOBUF_C_FIELD_FLAG_PACKED)) case PROTOBUF_C_TYPE_SINT32:
header_size *= count; for (i = 0; i < count; i++) rv += sint32_size(((int32_t *)array)[i]);
break;
switch (field->type) { case PROTOBUF_C_TYPE_ENUM:
case PROTOBUF_C_TYPE_SINT32: case PROTOBUF_C_TYPE_INT32:
for (i = 0; i < count; i++) for (i = 0; i < count; i++) rv += int32_size(((int32_t *)array)[i]);
rv += sint32_size(((int32_t *) array)[i]); break;
break; case PROTOBUF_C_TYPE_UINT32:
case PROTOBUF_C_TYPE_ENUM: for (i = 0; i < count; i++) rv += uint32_size(((uint32_t *)array)[i]);
case PROTOBUF_C_TYPE_INT32: break;
for (i = 0; i < count; i++) case PROTOBUF_C_TYPE_SINT64:
rv += int32_size(((int32_t *) array)[i]); for (i = 0; i < count; i++) rv += sint64_size(((int64_t *)array)[i]);
break; break;
case PROTOBUF_C_TYPE_UINT32: case PROTOBUF_C_TYPE_INT64:
for (i = 0; i < count; i++) case PROTOBUF_C_TYPE_UINT64:
rv += uint32_size(((uint32_t *) array)[i]); for (i = 0; i < count; i++) rv += uint64_size(((uint64_t *)array)[i]);
break; break;
case PROTOBUF_C_TYPE_SINT64: case PROTOBUF_C_TYPE_SFIXED32:
for (i = 0; i < count; i++) case PROTOBUF_C_TYPE_FIXED32:
rv += sint64_size(((int64_t *) array)[i]); case PROTOBUF_C_TYPE_FLOAT:
break; rv += 4 * count;
case PROTOBUF_C_TYPE_INT64: break;
case PROTOBUF_C_TYPE_UINT64: case PROTOBUF_C_TYPE_SFIXED64:
for (i = 0; i < count; i++) case PROTOBUF_C_TYPE_FIXED64:
rv += uint64_size(((uint64_t *) array)[i]); case PROTOBUF_C_TYPE_DOUBLE:
break; rv += 8 * count;
case PROTOBUF_C_TYPE_SFIXED32: break;
case PROTOBUF_C_TYPE_FIXED32: case PROTOBUF_C_TYPE_BOOL:
case PROTOBUF_C_TYPE_FLOAT: rv += count;
rv += 4 * count; break;
break; case PROTOBUF_C_TYPE_STRING:
case PROTOBUF_C_TYPE_SFIXED64: for (i = 0; i < count; i++) {
case PROTOBUF_C_TYPE_FIXED64: size_t len = strlen(((char **)array)[i]);
case PROTOBUF_C_TYPE_DOUBLE: rv += uint32_size(len) + len;
rv += 8 * count; }
break; break;
case PROTOBUF_C_TYPE_BOOL: case PROTOBUF_C_TYPE_BYTES:
rv += count; for (i = 0; i < count; i++) {
break; size_t len = ((ProtobufCBinaryData *)array)[i].len;
case PROTOBUF_C_TYPE_STRING: rv += uint32_size(len) + len;
for (i = 0; i < count; i++) { }
size_t len = strlen(((char **) array)[i]); break;
rv += uint32_size(len) + len; case PROTOBUF_C_TYPE_MESSAGE:
} for (i = 0; i < count; i++) {
break; size_t len =
case PROTOBUF_C_TYPE_BYTES: protobuf_c_message_get_packed_size(((ProtobufCMessage **)array)[i]);
for (i = 0; i < count; i++) { rv += uint32_size(len) + len;
size_t len = ((ProtobufCBinaryData *) array)[i].len; }
rv += uint32_size(len) + len; break;
} }
break;
case PROTOBUF_C_TYPE_MESSAGE: if (0 != (field->flags & PROTOBUF_C_FIELD_FLAG_PACKED))
for (i = 0; i < count; i++) { header_size += uint32_size(rv);
size_t len = protobuf_c_message_get_packed_size( return header_size + rv;
((ProtobufCMessage **) array)[i]);
rv += uint32_size(len) + len;
}
break;
}
if (0 != (field->flags & PROTOBUF_C_FIELD_FLAG_PACKED))
header_size += uint32_size(rv);
return header_size + rv;
} }
/** /**
...@@ -694,10 +625,9 @@ repeated_field_get_packed_size(const ProtobufCFieldDescriptor *field, ...@@ -694,10 +625,9 @@ repeated_field_get_packed_size(const ProtobufCFieldDescriptor *field,
* \return * \return
* Number of bytes required. * Number of bytes required.
*/ */
static inline size_t static inline size_t unknown_field_get_packed_size(
unknown_field_get_packed_size(const ProtobufCMessageUnknownField *field) const ProtobufCMessageUnknownField *field) {
{ return get_tag_size(field->tag) + field->len;
return get_tag_size(field->tag) + field->len;
} }
/**@}*/ /**@}*/
...@@ -705,52 +635,36 @@ unknown_field_get_packed_size(const ProtobufCMessageUnknownField *field) ...@@ -705,52 +635,36 @@ unknown_field_get_packed_size(const ProtobufCMessageUnknownField *field)
/* /*
* Calculate the serialized size of the message. * Calculate the serialized size of the message.
*/ */
size_t protobuf_c_message_get_packed_size(const ProtobufCMessage *message) size_t protobuf_c_message_get_packed_size(const ProtobufCMessage *message) {
{ unsigned i;
unsigned i; size_t rv = 0;
size_t rv = 0;
ASSERT_IS_MESSAGE(message);
ASSERT_IS_MESSAGE(message); for (i = 0; i < message->descriptor->n_fields; i++) {
for (i = 0; i < message->descriptor->n_fields; i++) { const ProtobufCFieldDescriptor *field = message->descriptor->fields + i;
const ProtobufCFieldDescriptor *field = const void *member = ((const char *)message) + field->offset;
message->descriptor->fields + i; const void *qmember = ((const char *)message) + field->quantifier_offset;
const void *member =
((const char *) message) + field->offset; if (field->label == PROTOBUF_C_LABEL_REQUIRED) {
const void *qmember = rv += required_field_get_packed_size(field, member);
((const char *) message) + field->quantifier_offset; } else if ((field->label == PROTOBUF_C_LABEL_OPTIONAL ||
field->label == PROTOBUF_C_LABEL_NONE) &&
if (field->label == PROTOBUF_C_LABEL_REQUIRED) { (0 != (field->flags & PROTOBUF_C_FIELD_FLAG_ONEOF))) {
rv += required_field_get_packed_size(field, member); rv += oneof_field_get_packed_size(field, *(const uint32_t *)qmember,
} else if ((field->label == PROTOBUF_C_LABEL_OPTIONAL || member);
field->label == PROTOBUF_C_LABEL_NONE) && } else if (field->label == PROTOBUF_C_LABEL_OPTIONAL) {
(0 != (field->flags & PROTOBUF_C_FIELD_FLAG_ONEOF))) { rv += optional_field_get_packed_size(
rv += oneof_field_get_packed_size( field, *(protobuf_c_boolean *)qmember, member);
field, } else if (field->label == PROTOBUF_C_LABEL_NONE) {
*(const uint32_t *) qmember, rv += unlabeled_field_get_packed_size(field, member);
member } else {
); rv += repeated_field_get_packed_size(field, *(const size_t *)qmember,
} else if (field->label == PROTOBUF_C_LABEL_OPTIONAL) { member);
rv += optional_field_get_packed_size( }
field, }
*(protobuf_c_boolean *) qmember, for (i = 0; i < message->n_unknown_fields; i++)
member rv += unknown_field_get_packed_size(&message->unknown_fields[i]);
); return rv;
} else if (field->label == PROTOBUF_C_LABEL_NONE) {
rv += unlabeled_field_get_packed_size(
field,
member
);
} else {
rv += repeated_field_get_packed_size(
field,
*(const size_t *) qmember,
member
);
}
}
for (i = 0; i < message->n_unknown_fields; i++)
rv += unknown_field_get_packed_size(&message->unknown_fields[i]);
return rv;
} }
/** /**
...@@ -773,30 +687,28 @@ size_t protobuf_c_message_get_packed_size(const ProtobufCMessage *message) ...@@ -773,30 +687,28 @@ size_t protobuf_c_message_get_packed_size(const ProtobufCMessage *message)
* \return * \return
* Number of bytes written to `out`. * Number of bytes written to `out`.
*/ */
static inline size_t static inline size_t uint32_pack(uint32_t value, uint8_t *out) {
uint32_pack(uint32_t value, uint8_t *out) unsigned rv = 0;
{
unsigned rv = 0; if (value >= 0x80) {
out[rv++] = value | 0x80;
if (value >= 0x80) { value >>= 7;
out[rv++] = value | 0x80; if (value >= 0x80) {
value >>= 7; out[rv++] = value | 0x80;
if (value >= 0x80) { value >>= 7;
out[rv++] = value | 0x80; if (value >= 0x80) {
value >>= 7; out[rv++] = value | 0x80;
if (value >= 0x80) { value >>= 7;
out[rv++] = value | 0x80; if (value >= 0x80) {
value >>= 7; out[rv++] = value | 0x80;
if (value >= 0x80) { value >>= 7;
out[rv++] = value | 0x80; }
value >>= 7; }
} }
} }
} /* assert: value<128 */
} out[rv++] = value;
/* assert: value<128 */ return rv;
out[rv++] = value;
return rv;
} }
/** /**
...@@ -810,21 +722,19 @@ uint32_pack(uint32_t value, uint8_t *out) ...@@ -810,21 +722,19 @@ uint32_pack(uint32_t value, uint8_t *out)
* \return * \return
* Number of bytes written to `out`. * Number of bytes written to `out`.
*/ */
static inline size_t static inline size_t int32_pack(int32_t value, uint8_t *out) {
int32_pack(int32_t value, uint8_t *out) if (value < 0) {
{ out[0] = value | 0x80;
if (value < 0) { out[1] = (value >> 7) | 0x80;
out[0] = value | 0x80; out[2] = (value >> 14) | 0x80;
out[1] = (value >> 7) | 0x80; out[3] = (value >> 21) | 0x80;
out[2] = (value >> 14) | 0x80; out[4] = (value >> 28) | 0x80;
out[3] = (value >> 21) | 0x80; out[5] = out[6] = out[7] = out[8] = 0xff;
out[4] = (value >> 28) | 0x80; out[9] = 0x01;
out[5] = out[6] = out[7] = out[8] = 0xff; return 10;
out[9] = 0x01; } else {
return 10; return uint32_pack(value, out);
} else { }
return uint32_pack(value, out);
}
} }
/** /**
...@@ -838,10 +748,8 @@ int32_pack(int32_t value, uint8_t *out) ...@@ -838,10 +748,8 @@ int32_pack(int32_t value, uint8_t *out)
* \return * \return
* Number of bytes written to `out`. * Number of bytes written to `out`.
*/ */
static inline size_t static inline size_t sint32_pack(int32_t value, uint8_t *out) {
sint32_pack(int32_t value, uint8_t *out) return uint32_pack(zigzag32(value), out);
{
return uint32_pack(zigzag32(value), out);
} }
/** /**
...@@ -855,33 +763,30 @@ sint32_pack(int32_t value, uint8_t *out) ...@@ -855,33 +763,30 @@ sint32_pack(int32_t value, uint8_t *out)
* \return * \return
* Number of bytes written to `out`. * Number of bytes written to `out`.
*/ */
static size_t static size_t uint64_pack(uint64_t value, uint8_t *out) {
uint64_pack(uint64_t value, uint8_t *out) uint32_t hi = (uint32_t)(value >> 32);
{ uint32_t lo = (uint32_t)value;
uint32_t hi = (uint32_t) (value >> 32); unsigned rv;
uint32_t lo = (uint32_t) value;
unsigned rv; if (hi == 0) return uint32_pack((uint32_t)lo, out);
out[0] = (lo) | 0x80;
if (hi == 0) out[1] = (lo >> 7) | 0x80;
return uint32_pack((uint32_t) lo, out); out[2] = (lo >> 14) | 0x80;
out[0] = (lo) | 0x80; out[3] = (lo >> 21) | 0x80;
out[1] = (lo >> 7) | 0x80; if (hi < 8) {
out[2] = (lo >> 14) | 0x80; out[4] = (hi << 4) | (lo >> 28);
out[3] = (lo >> 21) | 0x80; return 5;
if (hi < 8) { } else {
out[4] = (hi << 4) | (lo >> 28); out[4] = ((hi & 7) << 4) | (lo >> 28) | 0x80;
return 5; hi >>= 3;
} else { }
out[4] = ((hi & 7) << 4) | (lo >> 28) | 0x80; rv = 5;
hi >>= 3; while (hi >= 128) {
} out[rv++] = hi | 0x80;
rv = 5; hi >>= 7;
while (hi >= 128) { }
out[rv++] = hi | 0x80; out[rv++] = hi;
hi >>= 7; return rv;
}
out[rv++] = hi;
return rv;
} }
/** /**
...@@ -895,10 +800,8 @@ uint64_pack(uint64_t value, uint8_t *out) ...@@ -895,10 +800,8 @@ uint64_pack(uint64_t value, uint8_t *out)
* \return * \return
* Number of bytes written to `out`. * Number of bytes written to `out`.
*/ */
static inline size_t static inline size_t sint64_pack(int64_t value, uint8_t *out) {
sint64_pack(int64_t value, uint8_t *out) return uint64_pack(zigzag64(value), out);
{
return uint64_pack(zigzag64(value), out);
} }
/** /**
...@@ -912,20 +815,18 @@ sint64_pack(int64_t value, uint8_t *out) ...@@ -912,20 +815,18 @@ sint64_pack(int64_t value, uint8_t *out)
* \return * \return
* Number of bytes written to `out`. * Number of bytes written to `out`.
*/ */
static inline size_t static inline size_t fixed32_pack(uint32_t value, void *out) {
fixed32_pack(uint32_t value, void *out)
{
#if !defined(WORDS_BIGENDIAN) #if !defined(WORDS_BIGENDIAN)
memcpy(out, &value, 4); memcpy(out, &value, 4);
#else #else
uint8_t *buf = out; uint8_t *buf = out;
buf[0] = value; buf[0] = value;
buf[1] = value >> 8; buf[1] = value >> 8;
buf[2] = value >> 16; buf[2] = value >> 16;
buf[3] = value >> 24; buf[3] = value >> 24;
#endif #endif
return 4; return 4;
} }
/** /**
...@@ -943,16 +844,14 @@ fixed32_pack(uint32_t value, void *out) ...@@ -943,16 +844,14 @@ fixed32_pack(uint32_t value, void *out)
* \return * \return
* Number of bytes written to `out`. * Number of bytes written to `out`.
*/ */
static inline size_t static inline size_t fixed64_pack(uint64_t value, void *out) {
fixed64_pack(uint64_t value, void *out)
{
#if !defined(WORDS_BIGENDIAN) #if !defined(WORDS_BIGENDIAN)
memcpy(out, &value, 8); memcpy(out, &value, 8);
#else #else
fixed32_pack(value, out); fixed32_pack(value, out);
fixed32_pack(value >> 32, ((char *) out) + 4); fixed32_pack(value >> 32, ((char *)out) + 4);
#endif #endif
return 8; return 8;
} }
/** /**
...@@ -968,11 +867,9 @@ fixed64_pack(uint64_t value, void *out) ...@@ -968,11 +867,9 @@ fixed64_pack(uint64_t value, void *out)
* \return * \return
* Number of bytes written to `out`. * Number of bytes written to `out`.
*/ */
static inline size_t static inline size_t boolean_pack(protobuf_c_boolean value, uint8_t *out) {
boolean_pack(protobuf_c_boolean value, uint8_t *out) *out = value ? TRUE : FALSE;
{ return 1;
*out = value ? TRUE : FALSE;
return 1;
} }
/** /**
...@@ -990,18 +887,16 @@ boolean_pack(protobuf_c_boolean value, uint8_t *out) ...@@ -990,18 +887,16 @@ boolean_pack(protobuf_c_boolean value, uint8_t *out)
* \return * \return
* Number of bytes written to `out`. * Number of bytes written to `out`.
*/ */
static inline size_t static inline size_t string_pack(const char *str, uint8_t *out) {
string_pack(const char *str, uint8_t *out) if (str == NULL) {
{ out[0] = 0;
if (str == NULL) { return 1;
out[0] = 0; } else {
return 1; size_t len = strlen(str);
} else { size_t rv = uint32_pack(len, out);
size_t len = strlen(str); memcpy(out + rv, str, len);
size_t rv = uint32_pack(len, out); return rv + len;
memcpy(out + rv, str, len); }
return rv + len;
}
} }
/** /**
...@@ -1015,13 +910,12 @@ string_pack(const char *str, uint8_t *out) ...@@ -1015,13 +910,12 @@ string_pack(const char *str, uint8_t *out)
* \return * \return
* Number of bytes written to `out`. * Number of bytes written to `out`.
*/ */
static inline size_t static inline size_t binary_data_pack(const ProtobufCBinaryData *bd,
binary_data_pack(const ProtobufCBinaryData *bd, uint8_t *out) uint8_t *out) {
{ size_t len = bd->len;
size_t len = bd->len; size_t rv = uint32_pack(len, out);
size_t rv = uint32_pack(len, out); memcpy(out + rv, bd->data, len);
memcpy(out + rv, bd->data, len); return rv + len;
return rv + len;
} }
/** /**
...@@ -1035,19 +929,17 @@ binary_data_pack(const ProtobufCBinaryData *bd, uint8_t *out) ...@@ -1035,19 +929,17 @@ binary_data_pack(const ProtobufCBinaryData *bd, uint8_t *out)
* \return * \return
* Number of bytes written to `out`. * Number of bytes written to `out`.
*/ */
static inline size_t static inline size_t prefixed_message_pack(const ProtobufCMessage *message,
prefixed_message_pack(const ProtobufCMessage *message, uint8_t *out) uint8_t *out) {
{ if (message == NULL) {
if (message == NULL) { out[0] = 0;
out[0] = 0; return 1;
return 1; } else {
} else { size_t rv = protobuf_c_message_pack(message, out + 1);
size_t rv = protobuf_c_message_pack(message, out + 1); uint32_t rv_packed_size = uint32_size(rv);
uint32_t rv_packed_size = uint32_size(rv); if (rv_packed_size != 1) memmove(out + rv_packed_size, out + 1, rv);
if (rv_packed_size != 1) return uint32_pack(rv, out) + rv;
memmove(out + rv_packed_size, out + 1, rv); }
return uint32_pack(rv, out) + rv;
}
} }
/** /**
...@@ -1064,13 +956,11 @@ prefixed_message_pack(const ProtobufCMessage *message, uint8_t *out) ...@@ -1064,13 +956,11 @@ prefixed_message_pack(const ProtobufCMessage *message, uint8_t *out)
* \return * \return
* Number of bytes written to `out`. * Number of bytes written to `out`.
*/ */
static size_t static size_t tag_pack(uint32_t id, uint8_t *out) {
tag_pack(uint32_t id, uint8_t *out) if (id < (1UL << (32 - 3)))
{ return uint32_pack(id << 3, out);
if (id < (1UL << (32 - 3))) else
return uint32_pack(id << 3, out); return uint64_pack(((uint64_t)id) << 3, out);
else
return uint64_pack(((uint64_t) id) << 3, out);
} }
/** /**
...@@ -1085,55 +975,55 @@ tag_pack(uint32_t id, uint8_t *out) ...@@ -1085,55 +975,55 @@ tag_pack(uint32_t id, uint8_t *out)
* \return * \return
* Number of bytes written to `out`. * Number of bytes written to `out`.
*/ */
static size_t static size_t required_field_pack(const ProtobufCFieldDescriptor *field,
required_field_pack(const ProtobufCFieldDescriptor *field, const void *member, uint8_t *out) {
const void *member, uint8_t *out) size_t rv = tag_pack(field->id, out);
{
size_t rv = tag_pack(field->id, out); switch (field->type) {
case PROTOBUF_C_TYPE_SINT32:
switch (field->type) { out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
case PROTOBUF_C_TYPE_SINT32: return rv + sint32_pack(*(const int32_t *)member, out + rv);
out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT; case PROTOBUF_C_TYPE_ENUM:
return rv + sint32_pack(*(const int32_t *) member, out + rv); case PROTOBUF_C_TYPE_INT32:
case PROTOBUF_C_TYPE_ENUM: out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
case PROTOBUF_C_TYPE_INT32: return rv + int32_pack(*(const int32_t *)member, out + rv);
out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT; case PROTOBUF_C_TYPE_UINT32:
return rv + int32_pack(*(const int32_t *) member, out + rv); out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
case PROTOBUF_C_TYPE_UINT32: return rv + uint32_pack(*(const uint32_t *)member, out + rv);
out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT; case PROTOBUF_C_TYPE_SINT64:
return rv + uint32_pack(*(const uint32_t *) member, out + rv); out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
case PROTOBUF_C_TYPE_SINT64: return rv + sint64_pack(*(const int64_t *)member, out + rv);
out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT; case PROTOBUF_C_TYPE_INT64:
return rv + sint64_pack(*(const int64_t *) member, out + rv); case PROTOBUF_C_TYPE_UINT64:
case PROTOBUF_C_TYPE_INT64: out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
case PROTOBUF_C_TYPE_UINT64: return rv + uint64_pack(*(const uint64_t *)member, out + rv);
out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT; case PROTOBUF_C_TYPE_SFIXED32:
return rv + uint64_pack(*(const uint64_t *) member, out + rv); case PROTOBUF_C_TYPE_FIXED32:
case PROTOBUF_C_TYPE_SFIXED32: case PROTOBUF_C_TYPE_FLOAT:
case PROTOBUF_C_TYPE_FIXED32: out[0] |= PROTOBUF_C_WIRE_TYPE_32BIT;
case PROTOBUF_C_TYPE_FLOAT: return rv + fixed32_pack(*(const uint32_t *)member, out + rv);
out[0] |= PROTOBUF_C_WIRE_TYPE_32BIT; case PROTOBUF_C_TYPE_SFIXED64:
return rv + fixed32_pack(*(const uint32_t *) member, out + rv); case PROTOBUF_C_TYPE_FIXED64:
case PROTOBUF_C_TYPE_SFIXED64: case PROTOBUF_C_TYPE_DOUBLE:
case PROTOBUF_C_TYPE_FIXED64: out[0] |= PROTOBUF_C_WIRE_TYPE_64BIT;
case PROTOBUF_C_TYPE_DOUBLE: return rv + fixed64_pack(*(const uint64_t *)member, out + rv);
out[0] |= PROTOBUF_C_WIRE_TYPE_64BIT; case PROTOBUF_C_TYPE_BOOL:
return rv + fixed64_pack(*(const uint64_t *) member, out + rv); out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT;
case PROTOBUF_C_TYPE_BOOL: return rv + boolean_pack(*(const protobuf_c_boolean *)member, out + rv);
out[0] |= PROTOBUF_C_WIRE_TYPE_VARINT; case PROTOBUF_C_TYPE_STRING:
return rv + boolean_pack(*(const protobuf_c_boolean *) member, out + rv); out[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
case PROTOBUF_C_TYPE_STRING: return rv + string_pack(*(char *const *)member, out + rv);
out[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED; case PROTOBUF_C_TYPE_BYTES:
return rv + string_pack(*(char *const *) member, out + rv); out[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
case PROTOBUF_C_TYPE_BYTES: return rv +
out[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED; binary_data_pack((const ProtobufCBinaryData *)member, out + rv);
return rv + binary_data_pack((const ProtobufCBinaryData *) member, out + rv); case PROTOBUF_C_TYPE_MESSAGE:
case PROTOBUF_C_TYPE_MESSAGE: out[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
out[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED; return rv + prefixed_message_pack(*(ProtobufCMessage *const *)member,
return rv + prefixed_message_pack(*(ProtobufCMessage * const *) member, out + rv); out + rv);
} }
PROTOBUF_C__ASSERT_NOT_REACHED(); PROTOBUF_C__ASSERT_NOT_REACHED();
return 0; return 0;
} }
/** /**
...@@ -1151,22 +1041,18 @@ required_field_pack(const ProtobufCFieldDescriptor *field, ...@@ -1151,22 +1041,18 @@ required_field_pack(const ProtobufCFieldDescriptor *field,
* \return * \return
* Number of bytes written to `out`. * Number of bytes written to `out`.
*/ */
static size_t static size_t oneof_field_pack(const ProtobufCFieldDescriptor *field,
oneof_field_pack(const ProtobufCFieldDescriptor *field, uint32_t oneof_case, const void *member,
uint32_t oneof_case, uint8_t *out) {
const void *member, uint8_t *out) if (oneof_case != field->id) {
{ return 0;
if (oneof_case != field->id) { }
return 0; if (field->type == PROTOBUF_C_TYPE_MESSAGE ||
} field->type == PROTOBUF_C_TYPE_STRING) {
if (field->type == PROTOBUF_C_TYPE_MESSAGE || const void *ptr = *(const void *const *)member;
field->type == PROTOBUF_C_TYPE_STRING) if (ptr == NULL || ptr == field->default_value) return 0;
{ }
const void *ptr = *(const void * const *) member; return required_field_pack(field, member, out);
if (ptr == NULL || ptr == field->default_value)
return 0;
}
return required_field_pack(field, member, out);
} }
/** /**
...@@ -1183,22 +1069,17 @@ oneof_field_pack(const ProtobufCFieldDescriptor *field, ...@@ -1183,22 +1069,17 @@ oneof_field_pack(const ProtobufCFieldDescriptor *field,
* \return * \return
* Number of bytes written to `out`. * Number of bytes written to `out`.
*/ */
static size_t static size_t optional_field_pack(const ProtobufCFieldDescriptor *field,
optional_field_pack(const ProtobufCFieldDescriptor *field, const protobuf_c_boolean has,
const protobuf_c_boolean has, const void *member, uint8_t *out) {
const void *member, uint8_t *out) if (field->type == PROTOBUF_C_TYPE_MESSAGE ||
{ field->type == PROTOBUF_C_TYPE_STRING) {
if (field->type == PROTOBUF_C_TYPE_MESSAGE || const void *ptr = *(const void *const *)member;
field->type == PROTOBUF_C_TYPE_STRING) if (ptr == NULL || ptr == field->default_value) return 0;
{ } else {
const void *ptr = *(const void * const *) member; if (!has) return 0;
if (ptr == NULL || ptr == field->default_value) }
return 0; return required_field_pack(field, member, out);
} else {
if (!has)
return 0;
}
return required_field_pack(field, member, out);
} }
/** /**
...@@ -1213,13 +1094,10 @@ optional_field_pack(const ProtobufCFieldDescriptor *field, ...@@ -1213,13 +1094,10 @@ optional_field_pack(const ProtobufCFieldDescriptor *field,
* \return * \return
* Number of bytes written to `out`. * Number of bytes written to `out`.
*/ */
static size_t static size_t unlabeled_field_pack(const ProtobufCFieldDescriptor *field,
unlabeled_field_pack(const ProtobufCFieldDescriptor *field, const void *member, uint8_t *out) {
const void *member, uint8_t *out) if (field_is_zeroish(field, member)) return 0;
{ return required_field_pack(field, member, out);
if (field_is_zeroish(field, member))
return 0;
return required_field_pack(field, member, out);
} }
/** /**
...@@ -1232,35 +1110,33 @@ unlabeled_field_pack(const ProtobufCFieldDescriptor *field, ...@@ -1232,35 +1110,33 @@ unlabeled_field_pack(const ProtobufCFieldDescriptor *field,
* \return * \return
* Size of the field. * Size of the field.
*/ */
static inline size_t static inline size_t sizeof_elt_in_repeated_array(ProtobufCType type) {
sizeof_elt_in_repeated_array(ProtobufCType type) switch (type) {
{ case PROTOBUF_C_TYPE_SINT32:
switch (type) { case PROTOBUF_C_TYPE_INT32:
case PROTOBUF_C_TYPE_SINT32: case PROTOBUF_C_TYPE_UINT32:
case PROTOBUF_C_TYPE_INT32: case PROTOBUF_C_TYPE_SFIXED32:
case PROTOBUF_C_TYPE_UINT32: case PROTOBUF_C_TYPE_FIXED32:
case PROTOBUF_C_TYPE_SFIXED32: case PROTOBUF_C_TYPE_FLOAT:
case PROTOBUF_C_TYPE_FIXED32: case PROTOBUF_C_TYPE_ENUM:
case PROTOBUF_C_TYPE_FLOAT: return 4;
case PROTOBUF_C_TYPE_ENUM: case PROTOBUF_C_TYPE_SINT64:
return 4; case PROTOBUF_C_TYPE_INT64:
case PROTOBUF_C_TYPE_SINT64: case PROTOBUF_C_TYPE_UINT64:
case PROTOBUF_C_TYPE_INT64: case PROTOBUF_C_TYPE_SFIXED64:
case PROTOBUF_C_TYPE_UINT64: case PROTOBUF_C_TYPE_FIXED64:
case PROTOBUF_C_TYPE_SFIXED64: case PROTOBUF_C_TYPE_DOUBLE:
case PROTOBUF_C_TYPE_FIXED64: return 8;
case PROTOBUF_C_TYPE_DOUBLE: case PROTOBUF_C_TYPE_BOOL:
return 8; return sizeof(protobuf_c_boolean);
case PROTOBUF_C_TYPE_BOOL: case PROTOBUF_C_TYPE_STRING:
return sizeof(protobuf_c_boolean); case PROTOBUF_C_TYPE_MESSAGE:
case PROTOBUF_C_TYPE_STRING: return sizeof(void *);
case PROTOBUF_C_TYPE_MESSAGE: case PROTOBUF_C_TYPE_BYTES:
return sizeof(void *); return sizeof(ProtobufCBinaryData);
case PROTOBUF_C_TYPE_BYTES: }
return sizeof(ProtobufCBinaryData); PROTOBUF_C__ASSERT_NOT_REACHED();
} return 0;
PROTOBUF_C__ASSERT_NOT_REACHED();
return 0;
} }
/** /**
...@@ -1273,16 +1149,14 @@ sizeof_elt_in_repeated_array(ProtobufCType type) ...@@ -1273,16 +1149,14 @@ sizeof_elt_in_repeated_array(ProtobufCType type)
* \param[in] n * \param[in] n
* Number of elements in the source array. * Number of elements in the source array.
*/ */
static void static void copy_to_little_endian_32(void *out, const void *in,
copy_to_little_endian_32(void *out, const void *in, const unsigned n) const unsigned n) {
{
#if !defined(WORDS_BIGENDIAN) #if !defined(WORDS_BIGENDIAN)
memcpy(out, in, n * 4); memcpy(out, in, n * 4);
#else #else
unsigned i; unsigned i;
const uint32_t *ini = in; const uint32_t *ini = in;
for (i = 0; i < n; i++) for (i = 0; i < n; i++) fixed32_pack(ini[i], (uint32_t *)out + i);
fixed32_pack(ini[i], (uint32_t *) out + i);
#endif #endif
} }
...@@ -1296,16 +1170,14 @@ copy_to_little_endian_32(void *out, const void *in, const unsigned n) ...@@ -1296,16 +1170,14 @@ copy_to_little_endian_32(void *out, const void *in, const unsigned n)
* \param[in] n * \param[in] n
* Number of elements in the source array. * Number of elements in the source array.
*/ */
static void static void copy_to_little_endian_64(void *out, const void *in,
copy_to_little_endian_64(void *out, const void *in, const unsigned n) const unsigned n) {
{
#if !defined(WORDS_BIGENDIAN) #if !defined(WORDS_BIGENDIAN)
memcpy(out, in, n * 8); memcpy(out, in, n * 8);
#else #else
unsigned i; unsigned i;
const uint64_t *ini = in; const uint64_t *ini = in;
for (i = 0; i < n; i++) for (i = 0; i < n; i++) fixed64_pack(ini[i], (uint64_t *)out + i);
fixed64_pack(ini[i], (uint64_t *) out + i);
#endif #endif
} }
...@@ -1318,22 +1190,16 @@ copy_to_little_endian_64(void *out, const void *in, const unsigned n) ...@@ -1318,22 +1190,16 @@ copy_to_little_endian_64(void *out, const void *in, const unsigned n)
* \return * \return
* Number of bytes. * Number of bytes.
*/ */
static unsigned static unsigned get_type_min_size(ProtobufCType type) {
get_type_min_size(ProtobufCType type) if (type == PROTOBUF_C_TYPE_SFIXED32 || type == PROTOBUF_C_TYPE_FIXED32 ||
{ type == PROTOBUF_C_TYPE_FLOAT) {
if (type == PROTOBUF_C_TYPE_SFIXED32 || return 4;
type == PROTOBUF_C_TYPE_FIXED32 || }
type == PROTOBUF_C_TYPE_FLOAT) if (type == PROTOBUF_C_TYPE_SFIXED64 || type == PROTOBUF_C_TYPE_FIXED64 ||
{ type == PROTOBUF_C_TYPE_DOUBLE) {
return 4; return 8;
} }
if (type == PROTOBUF_C_TYPE_SFIXED64 || return 1;
type == PROTOBUF_C_TYPE_FIXED64 ||
type == PROTOBUF_C_TYPE_DOUBLE)
{
return 8;
}
return 1;
} }
/** /**
...@@ -1348,60 +1214,53 @@ get_type_min_size(ProtobufCType type) ...@@ -1348,60 +1214,53 @@ get_type_min_size(ProtobufCType type)
* \return * \return
* Number of bytes required. * Number of bytes required.
*/ */
static size_t static size_t get_packed_payload_length(const ProtobufCFieldDescriptor *field,
get_packed_payload_length(const ProtobufCFieldDescriptor *field, unsigned count, const void *array) {
unsigned count, const void *array) unsigned rv = 0;
{ unsigned i;
unsigned rv = 0;
unsigned i; switch (field->type) {
case PROTOBUF_C_TYPE_SFIXED32:
switch (field->type) { case PROTOBUF_C_TYPE_FIXED32:
case PROTOBUF_C_TYPE_SFIXED32: case PROTOBUF_C_TYPE_FLOAT:
case PROTOBUF_C_TYPE_FIXED32: return count * 4;
case PROTOBUF_C_TYPE_FLOAT: case PROTOBUF_C_TYPE_SFIXED64:
return count * 4; case PROTOBUF_C_TYPE_FIXED64:
case PROTOBUF_C_TYPE_SFIXED64: case PROTOBUF_C_TYPE_DOUBLE:
case PROTOBUF_C_TYPE_FIXED64: return count * 8;
case PROTOBUF_C_TYPE_DOUBLE: case PROTOBUF_C_TYPE_ENUM:
return count * 8; case PROTOBUF_C_TYPE_INT32: {
case PROTOBUF_C_TYPE_ENUM: const int32_t *arr = (const int32_t *)array;
case PROTOBUF_C_TYPE_INT32: { for (i = 0; i < count; i++) rv += int32_size(arr[i]);
const int32_t *arr = (const int32_t *) array; break;
for (i = 0; i < count; i++) }
rv += int32_size(arr[i]); case PROTOBUF_C_TYPE_SINT32: {
break; const int32_t *arr = (const int32_t *)array;
} for (i = 0; i < count; i++) rv += sint32_size(arr[i]);
case PROTOBUF_C_TYPE_SINT32: { break;
const int32_t *arr = (const int32_t *) array; }
for (i = 0; i < count; i++) case PROTOBUF_C_TYPE_UINT32: {
rv += sint32_size(arr[i]); const uint32_t *arr = (const uint32_t *)array;
break; for (i = 0; i < count; i++) rv += uint32_size(arr[i]);
} break;
case PROTOBUF_C_TYPE_UINT32: { }
const uint32_t *arr = (const uint32_t *) array; case PROTOBUF_C_TYPE_SINT64: {
for (i = 0; i < count; i++) const int64_t *arr = (const int64_t *)array;
rv += uint32_size(arr[i]); for (i = 0; i < count; i++) rv += sint64_size(arr[i]);
break; break;
} }
case PROTOBUF_C_TYPE_SINT64: { case PROTOBUF_C_TYPE_INT64:
const int64_t *arr = (const int64_t *) array; case PROTOBUF_C_TYPE_UINT64: {
for (i = 0; i < count; i++) const uint64_t *arr = (const uint64_t *)array;
rv += sint64_size(arr[i]); for (i = 0; i < count; i++) rv += uint64_size(arr[i]);
break; break;
} }
case PROTOBUF_C_TYPE_INT64: case PROTOBUF_C_TYPE_BOOL:
case PROTOBUF_C_TYPE_UINT64: { return count;
const uint64_t *arr = (const uint64_t *) array; default:
for (i = 0; i < count; i++) PROTOBUF_C__ASSERT_NOT_REACHED();
rv += uint64_size(arr[i]); }
break; return rv;
}
case PROTOBUF_C_TYPE_BOOL:
return count;
default:
PROTOBUF_C__ASSERT_NOT_REACHED();
}
return rv;
} }
/** /**
...@@ -1418,168 +1277,156 @@ get_packed_payload_length(const ProtobufCFieldDescriptor *field, ...@@ -1418,168 +1277,156 @@ get_packed_payload_length(const ProtobufCFieldDescriptor *field,
* \return * \return
* Number of bytes packed. * Number of bytes packed.
*/ */
static size_t static size_t pack_buffer_packed_payload(const ProtobufCFieldDescriptor *field,
pack_buffer_packed_payload(const ProtobufCFieldDescriptor *field, unsigned count, const void *array,
unsigned count, const void *array, ProtobufCBuffer *buffer) {
ProtobufCBuffer *buffer) uint8_t scratch[16];
{ size_t rv = 0;
uint8_t scratch[16]; unsigned i;
size_t rv = 0;
unsigned i; switch (field->type) {
case PROTOBUF_C_TYPE_SFIXED32:
switch (field->type) { case PROTOBUF_C_TYPE_FIXED32:
case PROTOBUF_C_TYPE_SFIXED32: case PROTOBUF_C_TYPE_FLOAT:
case PROTOBUF_C_TYPE_FIXED32:
case PROTOBUF_C_TYPE_FLOAT:
#if !defined(WORDS_BIGENDIAN) #if !defined(WORDS_BIGENDIAN)
rv = count * 4; rv = count * 4;
goto no_packing_needed; goto no_packing_needed;
#else #else
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
unsigned len = fixed32_pack(((uint32_t *) array)[i], scratch); unsigned len = fixed32_pack(((uint32_t *)array)[i], scratch);
buffer->append(buffer, len, scratch); buffer->append(buffer, len, scratch);
rv += len; rv += len;
} }
break; break;
#endif #endif
case PROTOBUF_C_TYPE_SFIXED64: case PROTOBUF_C_TYPE_SFIXED64:
case PROTOBUF_C_TYPE_FIXED64: case PROTOBUF_C_TYPE_FIXED64:
case PROTOBUF_C_TYPE_DOUBLE: case PROTOBUF_C_TYPE_DOUBLE:
#if !defined(WORDS_BIGENDIAN) #if !defined(WORDS_BIGENDIAN)
rv = count * 8; rv = count * 8;
goto no_packing_needed; goto no_packing_needed;
#else #else
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
unsigned len = fixed64_pack(((uint64_t *) array)[i], scratch); unsigned len = fixed64_pack(((uint64_t *)array)[i], scratch);
buffer->append(buffer, len, scratch); buffer->append(buffer, len, scratch);
rv += len; rv += len;
} }
break; break;
#endif #endif
case PROTOBUF_C_TYPE_ENUM: case PROTOBUF_C_TYPE_ENUM:
case PROTOBUF_C_TYPE_INT32: case PROTOBUF_C_TYPE_INT32:
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
unsigned len = int32_pack(((int32_t *) array)[i], scratch); unsigned len = int32_pack(((int32_t *)array)[i], scratch);
buffer->append(buffer, len, scratch); buffer->append(buffer, len, scratch);
rv += len; rv += len;
} }
break; break;
case PROTOBUF_C_TYPE_SINT32: case PROTOBUF_C_TYPE_SINT32:
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
unsigned len = sint32_pack(((int32_t *) array)[i], scratch); unsigned len = sint32_pack(((int32_t *)array)[i], scratch);
buffer->append(buffer, len, scratch); buffer->append(buffer, len, scratch);
rv += len; rv += len;
} }
break; break;
case PROTOBUF_C_TYPE_UINT32: case PROTOBUF_C_TYPE_UINT32:
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
unsigned len = uint32_pack(((uint32_t *) array)[i], scratch); unsigned len = uint32_pack(((uint32_t *)array)[i], scratch);
buffer->append(buffer, len, scratch); buffer->append(buffer, len, scratch);
rv += len; rv += len;
} }
break; break;
case PROTOBUF_C_TYPE_SINT64: case PROTOBUF_C_TYPE_SINT64:
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
unsigned len = sint64_pack(((int64_t *) array)[i], scratch); unsigned len = sint64_pack(((int64_t *)array)[i], scratch);
buffer->append(buffer, len, scratch); buffer->append(buffer, len, scratch);
rv += len; rv += len;
} }
break; break;
case PROTOBUF_C_TYPE_INT64: case PROTOBUF_C_TYPE_INT64:
case PROTOBUF_C_TYPE_UINT64: case PROTOBUF_C_TYPE_UINT64:
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
unsigned len = uint64_pack(((uint64_t *) array)[i], scratch); unsigned len = uint64_pack(((uint64_t *)array)[i], scratch);
buffer->append(buffer, len, scratch); buffer->append(buffer, len, scratch);
rv += len; rv += len;
} }
break; break;
case PROTOBUF_C_TYPE_BOOL: case PROTOBUF_C_TYPE_BOOL:
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
unsigned len = boolean_pack(((protobuf_c_boolean *) array)[i], scratch); unsigned len = boolean_pack(((protobuf_c_boolean *)array)[i], scratch);
buffer->append(buffer, len, scratch); buffer->append(buffer, len, scratch);
rv += len; rv += len;
} }
return count; return count;
default: default:
PROTOBUF_C__ASSERT_NOT_REACHED(); PROTOBUF_C__ASSERT_NOT_REACHED();
} }
return rv; return rv;
#if !defined(WORDS_BIGENDIAN) #if !defined(WORDS_BIGENDIAN)
no_packing_needed: no_packing_needed:
buffer->append(buffer, rv, array); buffer->append(buffer, rv, array);
return rv; return rv;
#endif #endif
} }
static inline int static inline int int_range_lookup(unsigned n_ranges,
int_range_lookup(unsigned n_ranges, const ProtobufCIntRange *ranges, int value) const ProtobufCIntRange *ranges, int value) {
{ unsigned n;
unsigned n; unsigned start;
unsigned start;
if (n_ranges == 0) return -1;
if (n_ranges == 0) start = 0;
return -1; n = n_ranges;
start = 0; while (n > 1) {
n = n_ranges; unsigned mid = start + n / 2;
while (n > 1) {
unsigned mid = start + n / 2; if (value < ranges[mid].start_value) {
n = mid - start;
if (value < ranges[mid].start_value) { } else if (value >=
n = mid - start; ranges[mid].start_value +
} else if (value >= ranges[mid].start_value + (int)(ranges[mid + 1].orig_index - ranges[mid].orig_index)) {
(int) (ranges[mid + 1].orig_index - unsigned new_start = mid + 1;
ranges[mid].orig_index)) n = start + n - new_start;
{ start = new_start;
unsigned new_start = mid + 1; } else
n = start + n - new_start; return (value - ranges[mid].start_value) + ranges[mid].orig_index;
start = new_start; }
} else if (n > 0) {
return (value - ranges[mid].start_value) + unsigned start_orig_index = ranges[start].orig_index;
ranges[mid].orig_index; unsigned range_size = ranges[start + 1].orig_index - start_orig_index;
}
if (n > 0) { if (ranges[start].start_value <= value &&
unsigned start_orig_index = ranges[start].orig_index; value < (int)(ranges[start].start_value + range_size)) {
unsigned range_size = return (value - ranges[start].start_value) + start_orig_index;
ranges[start + 1].orig_index - start_orig_index; }
}
if (ranges[start].start_value <= value && return -1;
value < (int) (ranges[start].start_value + range_size)) }
{
return (value - ranges[start].start_value) + static size_t parse_tag_and_wiretype(size_t len, const uint8_t *data,
start_orig_index; uint32_t *tag_out,
} ProtobufCWireType *wiretype_out) {
} unsigned max_rv = len > 5 ? 5 : len;
return -1; uint32_t tag = (data[0] & 0x7f) >> 3;
} unsigned shift = 4;
unsigned rv;
static size_t
parse_tag_and_wiretype(size_t len, *wiretype_out = data[0] & 7;
const uint8_t *data, if ((data[0] & 0x80) == 0) {
uint32_t *tag_out, *tag_out = tag;
ProtobufCWireType *wiretype_out) return 1;
{ }
unsigned max_rv = len > 5 ? 5 : len; for (rv = 1; rv < max_rv; rv++) {
uint32_t tag = (data[0] & 0x7f) >> 3; if (data[rv] & 0x80) {
unsigned shift = 4; tag |= (data[rv] & 0x7f) << shift;
unsigned rv; shift += 7;
} else {
*wiretype_out = data[0] & 7; tag |= data[rv] << shift;
if ((data[0] & 0x80) == 0) { *tag_out = tag;
*tag_out = tag; return rv + 1;
return 1; }
} }
for (rv = 1; rv < max_rv; rv++) { return 0; /* error: bad header */
if (data[rv] & 0x80) {
tag |= (data[rv] & 0x7f) << shift;
shift += 7;
} else {
tag |= data[rv] << shift;
*tag_out = tag;
return rv + 1;
}
}
return 0; /* error: bad header */
} }
/* sizeof(ScannedMember) must be <= (1UL<<BOUND_SIZEOF_SCANNED_MEMBER_LOG2) */ /* sizeof(ScannedMember) must be <= (1UL<<BOUND_SIZEOF_SCANNED_MEMBER_LOG2) */
...@@ -1587,51 +1434,46 @@ parse_tag_and_wiretype(size_t len, ...@@ -1587,51 +1434,46 @@ parse_tag_and_wiretype(size_t len,
typedef struct _ScannedMember ScannedMember; typedef struct _ScannedMember ScannedMember;
/** Field as it's being read. */ /** Field as it's being read. */
struct _ScannedMember { struct _ScannedMember {
uint32_t tag; /**< Field tag. */ uint32_t tag; /**< Field tag. */
uint8_t wire_type; /**< Field type. */ uint8_t wire_type; /**< Field type. */
uint8_t length_prefix_len; /**< Prefix length. */ uint8_t length_prefix_len; /**< Prefix length. */
const ProtobufCFieldDescriptor *field; /**< Field descriptor. */ const ProtobufCFieldDescriptor *field; /**< Field descriptor. */
size_t len; /**< Field length. */ size_t len; /**< Field length. */
const uint8_t *data; /**< Pointer to field data. */ const uint8_t *data; /**< Pointer to field data. */
}; };
static inline uint32_t static inline uint32_t scan_length_prefixed_data(size_t len,
scan_length_prefixed_data(size_t len, const uint8_t *data, const uint8_t *data,
size_t *prefix_len_out) size_t *prefix_len_out) {
{ unsigned hdr_max = len < 5 ? len : 5;
unsigned hdr_max = len < 5 ? len : 5; unsigned hdr_len;
unsigned hdr_len; uint32_t val = 0;
uint32_t val = 0; unsigned i;
unsigned i; unsigned shift = 0;
unsigned shift = 0;
for (i = 0; i < hdr_max; i++) {
for (i = 0; i < hdr_max; i++) { val |= (data[i] & 0x7f) << shift;
val |= (data[i] & 0x7f) << shift; shift += 7;
shift += 7; if ((data[i] & 0x80) == 0) break;
if ((data[i] & 0x80) == 0) }
break; if (i == hdr_max) {
} PROTOBUF_C_UNPACK_ERROR("error parsing length for length-prefixed data");
if (i == hdr_max) { return 0;
PROTOBUF_C_UNPACK_ERROR("error parsing length for length-prefixed data"); }
return 0; hdr_len = i + 1;
} *prefix_len_out = hdr_len;
hdr_len = i + 1; if (hdr_len + val > len) {
*prefix_len_out = hdr_len; PROTOBUF_C_UNPACK_ERROR("data too short after length-prefix of %u", val);
if (hdr_len + val > len) { return 0;
PROTOBUF_C_UNPACK_ERROR("data too short after length-prefix of %u", val); }
return 0; return hdr_len + val;
} }
return hdr_len + val;
} static size_t max_b128_numbers(size_t len, const uint8_t *data) {
size_t rv = 0;
static size_t while (len--)
max_b128_numbers(size_t len, const uint8_t *data) if ((*data++ & 0x80) == 0) ++rv;
{ return rv;
size_t rv = 0;
while (len--)
if ((*data++ & 0x80) == 0)
++rv;
return rv;
} }
/**@}*/ /**@}*/
...@@ -1650,176 +1492,144 @@ max_b128_numbers(size_t len, const uint8_t *data) ...@@ -1650,176 +1492,144 @@ max_b128_numbers(size_t len, const uint8_t *data)
* some of its fields may have been reused and changed to their default * some of its fields may have been reused and changed to their default
* values during the merge. * values during the merge.
*/ */
static protobuf_c_boolean static protobuf_c_boolean merge_messages(ProtobufCMessage *earlier_msg,
merge_messages(ProtobufCMessage *earlier_msg, ProtobufCMessage *latter_msg,
ProtobufCMessage *latter_msg, ProtobufCAllocator *allocator) {
ProtobufCAllocator *allocator) unsigned i;
{ const ProtobufCFieldDescriptor *fields = latter_msg->descriptor->fields;
unsigned i; for (i = 0; i < latter_msg->descriptor->n_fields; i++) {
const ProtobufCFieldDescriptor *fields = if (fields[i].label == PROTOBUF_C_LABEL_REPEATED) {
latter_msg->descriptor->fields; size_t *n_earlier =
for (i = 0; i < latter_msg->descriptor->n_fields; i++) { STRUCT_MEMBER_PTR(size_t, earlier_msg, fields[i].quantifier_offset);
if (fields[i].label == PROTOBUF_C_LABEL_REPEATED) { uint8_t **p_earlier =
size_t *n_earlier = STRUCT_MEMBER_PTR(uint8_t *, earlier_msg, fields[i].offset);
STRUCT_MEMBER_PTR(size_t, earlier_msg, size_t *n_latter =
fields[i].quantifier_offset); STRUCT_MEMBER_PTR(size_t, latter_msg, fields[i].quantifier_offset);
uint8_t **p_earlier = uint8_t **p_latter =
STRUCT_MEMBER_PTR(uint8_t *, earlier_msg, STRUCT_MEMBER_PTR(uint8_t *, latter_msg, fields[i].offset);
fields[i].offset);
size_t *n_latter = if (*n_earlier > 0) {
STRUCT_MEMBER_PTR(size_t, latter_msg, if (*n_latter > 0) {
fields[i].quantifier_offset); /* Concatenate the repeated field */
uint8_t **p_latter = size_t el_size = sizeof_elt_in_repeated_array(fields[i].type);
STRUCT_MEMBER_PTR(uint8_t *, latter_msg, uint8_t *new_field;
fields[i].offset);
new_field = do_alloc(allocator, (*n_earlier + *n_latter) * el_size);
if (*n_earlier > 0) { if (!new_field) return FALSE;
if (*n_latter > 0) {
/* Concatenate the repeated field */ memcpy(new_field, *p_earlier, *n_earlier * el_size);
size_t el_size = memcpy(new_field + *n_earlier * el_size, *p_latter,
sizeof_elt_in_repeated_array(fields[i].type); *n_latter * el_size);
uint8_t *new_field;
do_free(allocator, *p_latter);
new_field = do_alloc(allocator, do_free(allocator, *p_earlier);
(*n_earlier + *n_latter) * el_size); *p_latter = new_field;
if (!new_field) *n_latter = *n_earlier + *n_latter;
return FALSE; } else {
/* Zero copy the repeated field from the earlier message */
memcpy(new_field, *p_earlier, *n_latter = *n_earlier;
*n_earlier * el_size); *p_latter = *p_earlier;
memcpy(new_field + }
*n_earlier * el_size, /* Make sure the field does not get double freed */
*p_latter, *n_earlier = 0;
*n_latter * el_size); *p_earlier = 0;
}
do_free(allocator, *p_latter); } else if (fields[i].label == PROTOBUF_C_LABEL_OPTIONAL ||
do_free(allocator, *p_earlier); fields[i].label == PROTOBUF_C_LABEL_NONE) {
*p_latter = new_field; const ProtobufCFieldDescriptor *field;
*n_latter = *n_earlier + *n_latter; uint32_t *earlier_case_p =
} else { STRUCT_MEMBER_PTR(uint32_t, earlier_msg, fields[i].quantifier_offset);
/* Zero copy the repeated field from the earlier message */ uint32_t *latter_case_p =
*n_latter = *n_earlier; STRUCT_MEMBER_PTR(uint32_t, latter_msg, fields[i].quantifier_offset);
*p_latter = *p_earlier; protobuf_c_boolean need_to_merge = FALSE;
} void *earlier_elem;
/* Make sure the field does not get double freed */ void *latter_elem;
*n_earlier = 0; const void *def_val;
*p_earlier = 0;
} if (fields[i].flags & PROTOBUF_C_FIELD_FLAG_ONEOF) {
} else if (fields[i].label == PROTOBUF_C_LABEL_OPTIONAL || if (*latter_case_p == 0) {
fields[i].label == PROTOBUF_C_LABEL_NONE) { /* lookup correct oneof field */
const ProtobufCFieldDescriptor *field; int field_index = int_range_lookup(
uint32_t *earlier_case_p = STRUCT_MEMBER_PTR(uint32_t, latter_msg->descriptor->n_field_ranges,
earlier_msg, latter_msg->descriptor->field_ranges, *earlier_case_p);
fields[i]. field = latter_msg->descriptor->fields + field_index;
quantifier_offset); } else {
uint32_t *latter_case_p = STRUCT_MEMBER_PTR(uint32_t, /* Oneof is present in the latter message, move on */
latter_msg, continue;
fields[i]. }
quantifier_offset); } else {
protobuf_c_boolean need_to_merge = FALSE; field = &fields[i];
void *earlier_elem; }
void *latter_elem;
const void *def_val; earlier_elem = STRUCT_MEMBER_P(earlier_msg, field->offset);
latter_elem = STRUCT_MEMBER_P(latter_msg, field->offset);
if (fields[i].flags & PROTOBUF_C_FIELD_FLAG_ONEOF) { def_val = field->default_value;
if (*latter_case_p == 0) {
/* lookup correct oneof field */ switch (field->type) {
int field_index = case PROTOBUF_C_TYPE_MESSAGE: {
int_range_lookup( ProtobufCMessage *em = *(ProtobufCMessage **)earlier_elem;
latter_msg->descriptor ProtobufCMessage *lm = *(ProtobufCMessage **)latter_elem;
->n_field_ranges, if (em != NULL) {
latter_msg->descriptor if (lm != NULL) {
->field_ranges, if (!merge_messages(em, lm, allocator)) return FALSE;
*earlier_case_p); /* Already merged */
field = latter_msg->descriptor->fields + need_to_merge = FALSE;
field_index; } else {
} else { /* Zero copy the message */
/* Oneof is present in the latter message, move on */ need_to_merge = TRUE;
continue; }
} }
} else { break;
field = &fields[i]; }
} case PROTOBUF_C_TYPE_BYTES: {
uint8_t *e_data = ((ProtobufCBinaryData *)earlier_elem)->data;
earlier_elem = STRUCT_MEMBER_P(earlier_msg, field->offset); uint8_t *l_data = ((ProtobufCBinaryData *)latter_elem)->data;
latter_elem = STRUCT_MEMBER_P(latter_msg, field->offset); const ProtobufCBinaryData *d_bd = (ProtobufCBinaryData *)def_val;
def_val = field->default_value;
need_to_merge =
switch (field->type) { (e_data != NULL && (d_bd == NULL || e_data != d_bd->data)) &&
case PROTOBUF_C_TYPE_MESSAGE: { (l_data == NULL || (d_bd != NULL && l_data == d_bd->data));
ProtobufCMessage *em = *(ProtobufCMessage **) earlier_elem; break;
ProtobufCMessage *lm = *(ProtobufCMessage **) latter_elem; }
if (em != NULL) { case PROTOBUF_C_TYPE_STRING: {
if (lm != NULL) { char *e_str = *(char **)earlier_elem;
if (!merge_messages(em, lm, allocator)) char *l_str = *(char **)latter_elem;
return FALSE; const char *d_str = def_val;
/* Already merged */
need_to_merge = FALSE; need_to_merge = e_str != d_str && l_str == d_str;
} else { break;
/* Zero copy the message */ }
need_to_merge = TRUE; default: {
} /* Could be has field or case enum, the logic is
} * equivalent, since 0 (FALSE) means not set for
break; * oneof */
} need_to_merge = (*earlier_case_p != 0) && (*latter_case_p == 0);
case PROTOBUF_C_TYPE_BYTES: { break;
uint8_t *e_data = }
((ProtobufCBinaryData *) earlier_elem)->data; }
uint8_t *l_data =
((ProtobufCBinaryData *) latter_elem)->data; if (need_to_merge) {
const ProtobufCBinaryData *d_bd = size_t el_size = sizeof_elt_in_repeated_array(field->type);
(ProtobufCBinaryData *) def_val; memcpy(latter_elem, earlier_elem, el_size);
/*
need_to_merge = * Reset the element from the old message to 0
(e_data != NULL && * to make sure earlier message deallocation
(d_bd == NULL || * doesn't corrupt zero-copied data in the new
e_data != d_bd->data)) && * message, earlier message will be freed after
(l_data == NULL || * this function is called anyway
(d_bd != NULL && */
l_data == d_bd->data)); memset(earlier_elem, 0, el_size);
break;
} if (field->quantifier_offset != 0) {
case PROTOBUF_C_TYPE_STRING: { /* Set the has field or the case enum,
char *e_str = *(char **) earlier_elem; * if applicable */
char *l_str = *(char **) latter_elem; *latter_case_p = *earlier_case_p;
const char *d_str = def_val; *earlier_case_p = 0;
}
need_to_merge = e_str != d_str && l_str == d_str; }
break; }
} }
default: { return TRUE;
/* Could be has field or case enum, the logic is
* equivalent, since 0 (FALSE) means not set for
* oneof */
need_to_merge = (*earlier_case_p != 0) &&
(*latter_case_p == 0);
break;
}
}
if (need_to_merge) {
size_t el_size =
sizeof_elt_in_repeated_array(field->type);
memcpy(latter_elem, earlier_elem, el_size);
/*
* Reset the element from the old message to 0
* to make sure earlier message deallocation
* doesn't corrupt zero-copied data in the new
* message, earlier message will be freed after
* this function is called anyway
*/
memset(earlier_elem, 0, el_size);
if (field->quantifier_offset != 0) {
/* Set the has field or the case enum,
* if applicable */
*latter_case_p = *earlier_case_p;
*earlier_case_p = 0;
}
}
}
}
return TRUE;
} }
/** /**
...@@ -1830,580 +1640,501 @@ merge_messages(ProtobufCMessage *earlier_msg, ...@@ -1830,580 +1640,501 @@ merge_messages(ProtobufCMessage *earlier_msg,
* others; the remaining error checking is done by * others; the remaining error checking is done by
* parse_packed_repeated_member(). * parse_packed_repeated_member().
*/ */
static protobuf_c_boolean static protobuf_c_boolean count_packed_elements(ProtobufCType type, size_t len,
count_packed_elements(ProtobufCType type, const uint8_t *data,
size_t len, const uint8_t *data, size_t *count_out) size_t *count_out) {
{ switch (type) {
switch (type) { case PROTOBUF_C_TYPE_SFIXED32:
case PROTOBUF_C_TYPE_SFIXED32: case PROTOBUF_C_TYPE_FIXED32:
case PROTOBUF_C_TYPE_FIXED32: case PROTOBUF_C_TYPE_FLOAT:
case PROTOBUF_C_TYPE_FLOAT: if (len % 4 != 0) {
if (len % 4 != 0) { PROTOBUF_C_UNPACK_ERROR(
PROTOBUF_C_UNPACK_ERROR("length must be a multiple of 4 for fixed-length 32-bit types"); "length must be a multiple of 4 for fixed-length 32-bit types");
return FALSE; return FALSE;
} }
*count_out = len / 4; *count_out = len / 4;
return TRUE; return TRUE;
case PROTOBUF_C_TYPE_SFIXED64: case PROTOBUF_C_TYPE_SFIXED64:
case PROTOBUF_C_TYPE_FIXED64: case PROTOBUF_C_TYPE_FIXED64:
case PROTOBUF_C_TYPE_DOUBLE: case PROTOBUF_C_TYPE_DOUBLE:
if (len % 8 != 0) { if (len % 8 != 0) {
PROTOBUF_C_UNPACK_ERROR("length must be a multiple of 8 for fixed-length 64-bit types"); PROTOBUF_C_UNPACK_ERROR(
return FALSE; "length must be a multiple of 8 for fixed-length 64-bit types");
} return FALSE;
*count_out = len / 8; }
return TRUE; *count_out = len / 8;
case PROTOBUF_C_TYPE_ENUM: return TRUE;
case PROTOBUF_C_TYPE_INT32: case PROTOBUF_C_TYPE_ENUM:
case PROTOBUF_C_TYPE_SINT32: case PROTOBUF_C_TYPE_INT32:
case PROTOBUF_C_TYPE_UINT32: case PROTOBUF_C_TYPE_SINT32:
case PROTOBUF_C_TYPE_INT64: case PROTOBUF_C_TYPE_UINT32:
case PROTOBUF_C_TYPE_SINT64: case PROTOBUF_C_TYPE_INT64:
case PROTOBUF_C_TYPE_UINT64: case PROTOBUF_C_TYPE_SINT64:
*count_out = max_b128_numbers(len, data); case PROTOBUF_C_TYPE_UINT64:
return TRUE; *count_out = max_b128_numbers(len, data);
case PROTOBUF_C_TYPE_BOOL: return TRUE;
*count_out = len; case PROTOBUF_C_TYPE_BOOL:
return TRUE; *count_out = len;
case PROTOBUF_C_TYPE_STRING: return TRUE;
case PROTOBUF_C_TYPE_BYTES: case PROTOBUF_C_TYPE_STRING:
case PROTOBUF_C_TYPE_MESSAGE: case PROTOBUF_C_TYPE_BYTES:
default: case PROTOBUF_C_TYPE_MESSAGE:
PROTOBUF_C_UNPACK_ERROR("bad protobuf-c type %u for packed-repeated", type); default:
return FALSE; PROTOBUF_C_UNPACK_ERROR("bad protobuf-c type %u for packed-repeated",
} type);
} return FALSE;
}
static inline uint32_t }
parse_uint32(unsigned len, const uint8_t *data)
{ static inline uint32_t parse_uint32(unsigned len, const uint8_t *data) {
uint32_t rv = data[0] & 0x7f; uint32_t rv = data[0] & 0x7f;
if (len > 1) { if (len > 1) {
rv |= ((uint32_t) (data[1] & 0x7f) << 7); rv |= ((uint32_t)(data[1] & 0x7f) << 7);
if (len > 2) { if (len > 2) {
rv |= ((uint32_t) (data[2] & 0x7f) << 14); rv |= ((uint32_t)(data[2] & 0x7f) << 14);
if (len > 3) { if (len > 3) {
rv |= ((uint32_t) (data[3] & 0x7f) << 21); rv |= ((uint32_t)(data[3] & 0x7f) << 21);
if (len > 4) if (len > 4) rv |= ((uint32_t)(data[4]) << 28);
rv |= ((uint32_t) (data[4]) << 28); }
} }
} }
} return rv;
return rv; }
}
static inline uint32_t parse_int32(unsigned len, const uint8_t *data) {
static inline uint32_t return parse_uint32(len, data);
parse_int32(unsigned len, const uint8_t *data) }
{
return parse_uint32(len, data); static inline int32_t unzigzag32(uint32_t v) {
} if (v & 1)
return -(v >> 1) - 1;
static inline int32_t else
unzigzag32(uint32_t v) return v >> 1;
{ }
if (v & 1)
return -(v >> 1) - 1; static inline uint32_t parse_fixed_uint32(const uint8_t *data) {
else
return v >> 1;
}
static inline uint32_t
parse_fixed_uint32(const uint8_t *data)
{
#if !defined(WORDS_BIGENDIAN) #if !defined(WORDS_BIGENDIAN)
uint32_t t; uint32_t t;
memcpy(&t, data, 4); memcpy(&t, data, 4);
return t; return t;
#else #else
return data[0] | return data[0] | ((uint32_t)(data[1]) << 8) | ((uint32_t)(data[2]) << 16) |
((uint32_t) (data[1]) << 8) | ((uint32_t)(data[3]) << 24);
((uint32_t) (data[2]) << 16) |
((uint32_t) (data[3]) << 24);
#endif #endif
} }
static uint64_t static uint64_t parse_uint64(unsigned len, const uint8_t *data) {
parse_uint64(unsigned len, const uint8_t *data) unsigned shift, i;
{ uint64_t rv;
unsigned shift, i;
uint64_t rv; if (len < 5) return parse_uint32(len, data);
rv = ((uint64_t)(data[0] & 0x7f)) | ((uint64_t)(data[1] & 0x7f) << 7) |
if (len < 5) ((uint64_t)(data[2] & 0x7f) << 14) | ((uint64_t)(data[3] & 0x7f) << 21);
return parse_uint32(len, data); shift = 28;
rv = ((uint64_t) (data[0] & 0x7f)) | for (i = 4; i < len; i++) {
((uint64_t) (data[1] & 0x7f) << 7) | rv |= (((uint64_t)(data[i] & 0x7f)) << shift);
((uint64_t) (data[2] & 0x7f) << 14) | shift += 7;
((uint64_t) (data[3] & 0x7f) << 21); }
shift = 28; return rv;
for (i = 4; i < len; i++) { }
rv |= (((uint64_t) (data[i] & 0x7f)) << shift);
shift += 7; static inline int64_t unzigzag64(uint64_t v) {
} if (v & 1)
return rv; return -(v >> 1) - 1;
} else
return v >> 1;
static inline int64_t }
unzigzag64(uint64_t v)
{ static inline uint64_t parse_fixed_uint64(const uint8_t *data) {
if (v & 1)
return -(v >> 1) - 1;
else
return v >> 1;
}
static inline uint64_t
parse_fixed_uint64(const uint8_t *data)
{
#if !defined(WORDS_BIGENDIAN) #if !defined(WORDS_BIGENDIAN)
uint64_t t; uint64_t t;
memcpy(&t, data, 8); memcpy(&t, data, 8);
return t; return t;
#else #else
return (uint64_t) parse_fixed_uint32(data) | return (uint64_t)parse_fixed_uint32(data) |
(((uint64_t) parse_fixed_uint32(data + 4)) << 32); (((uint64_t)parse_fixed_uint32(data + 4)) << 32);
#endif #endif
} }
static protobuf_c_boolean static protobuf_c_boolean parse_boolean(unsigned len, const uint8_t *data) {
parse_boolean(unsigned len, const uint8_t *data) unsigned i;
{ for (i = 0; i < len; i++)
unsigned i; if (data[i] & 0x7f) return TRUE;
for (i = 0; i < len; i++) return FALSE;
if (data[i] & 0x7f) }
return TRUE;
return FALSE; static protobuf_c_boolean parse_required_member(
} ScannedMember *scanned_member, void *member, ProtobufCAllocator *allocator,
protobuf_c_boolean maybe_clear) {
static protobuf_c_boolean unsigned len = scanned_member->len;
parse_required_member(ScannedMember *scanned_member, const uint8_t *data = scanned_member->data;
void *member, ProtobufCWireType wire_type = scanned_member->wire_type;
ProtobufCAllocator *allocator,
protobuf_c_boolean maybe_clear) switch (scanned_member->field->type) {
{ case PROTOBUF_C_TYPE_ENUM:
unsigned len = scanned_member->len; case PROTOBUF_C_TYPE_INT32:
const uint8_t *data = scanned_member->data; if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT) return FALSE;
ProtobufCWireType wire_type = scanned_member->wire_type; *(int32_t *)member = parse_int32(len, data);
return TRUE;
switch (scanned_member->field->type) { case PROTOBUF_C_TYPE_UINT32:
case PROTOBUF_C_TYPE_ENUM: if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT) return FALSE;
case PROTOBUF_C_TYPE_INT32: *(uint32_t *)member = parse_uint32(len, data);
if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT) return TRUE;
return FALSE; case PROTOBUF_C_TYPE_SINT32:
*(int32_t *) member = parse_int32(len, data); if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT) return FALSE;
return TRUE; *(int32_t *)member = unzigzag32(parse_uint32(len, data));
case PROTOBUF_C_TYPE_UINT32: return TRUE;
if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT) case PROTOBUF_C_TYPE_SFIXED32:
return FALSE; case PROTOBUF_C_TYPE_FIXED32:
*(uint32_t *) member = parse_uint32(len, data); case PROTOBUF_C_TYPE_FLOAT:
return TRUE; if (wire_type != PROTOBUF_C_WIRE_TYPE_32BIT) return FALSE;
case PROTOBUF_C_TYPE_SINT32: *(uint32_t *)member = parse_fixed_uint32(data);
if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT) return TRUE;
return FALSE; case PROTOBUF_C_TYPE_INT64:
*(int32_t *) member = unzigzag32(parse_uint32(len, data)); case PROTOBUF_C_TYPE_UINT64:
return TRUE; if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT) return FALSE;
case PROTOBUF_C_TYPE_SFIXED32: *(uint64_t *)member = parse_uint64(len, data);
case PROTOBUF_C_TYPE_FIXED32: return TRUE;
case PROTOBUF_C_TYPE_FLOAT: case PROTOBUF_C_TYPE_SINT64:
if (wire_type != PROTOBUF_C_WIRE_TYPE_32BIT) if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT) return FALSE;
return FALSE; *(int64_t *)member = unzigzag64(parse_uint64(len, data));
*(uint32_t *) member = parse_fixed_uint32(data); return TRUE;
return TRUE; case PROTOBUF_C_TYPE_SFIXED64:
case PROTOBUF_C_TYPE_INT64: case PROTOBUF_C_TYPE_FIXED64:
case PROTOBUF_C_TYPE_UINT64: case PROTOBUF_C_TYPE_DOUBLE:
if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT) if (wire_type != PROTOBUF_C_WIRE_TYPE_64BIT) return FALSE;
return FALSE; *(uint64_t *)member = parse_fixed_uint64(data);
*(uint64_t *) member = parse_uint64(len, data); return TRUE;
return TRUE; case PROTOBUF_C_TYPE_BOOL:
case PROTOBUF_C_TYPE_SINT64: *(protobuf_c_boolean *)member = parse_boolean(len, data);
if (wire_type != PROTOBUF_C_WIRE_TYPE_VARINT) return TRUE;
return FALSE; case PROTOBUF_C_TYPE_STRING: {
*(int64_t *) member = unzigzag64(parse_uint64(len, data)); char **pstr = member;
return TRUE; unsigned pref_len = scanned_member->length_prefix_len;
case PROTOBUF_C_TYPE_SFIXED64:
case PROTOBUF_C_TYPE_FIXED64: if (wire_type != PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED) return FALSE;
case PROTOBUF_C_TYPE_DOUBLE:
if (wire_type != PROTOBUF_C_WIRE_TYPE_64BIT) if (maybe_clear && *pstr != NULL) {
return FALSE; const char *def = scanned_member->field->default_value;
*(uint64_t *) member = parse_fixed_uint64(data); if (*pstr != NULL && *pstr != def) do_free(allocator, *pstr);
return TRUE; }
case PROTOBUF_C_TYPE_BOOL: *pstr = do_alloc(allocator, len - pref_len + 1);
*(protobuf_c_boolean *) member = parse_boolean(len, data); if (*pstr == NULL) return FALSE;
return TRUE; memcpy(*pstr, data + pref_len, len - pref_len);
case PROTOBUF_C_TYPE_STRING: { (*pstr)[len - pref_len] = 0;
char **pstr = member; return TRUE;
unsigned pref_len = scanned_member->length_prefix_len; }
case PROTOBUF_C_TYPE_BYTES: {
if (wire_type != PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED) ProtobufCBinaryData *bd = member;
return FALSE; const ProtobufCBinaryData *def_bd;
unsigned pref_len = scanned_member->length_prefix_len;
if (maybe_clear && *pstr != NULL) {
const char *def = scanned_member->field->default_value; if (wire_type != PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED) return FALSE;
if (*pstr != NULL && *pstr != def)
do_free(allocator, *pstr); def_bd = scanned_member->field->default_value;
} if (maybe_clear && bd->data != NULL &&
*pstr = do_alloc(allocator, len - pref_len + 1); (def_bd == NULL || bd->data != def_bd->data)) {
if (*pstr == NULL) do_free(allocator, bd->data);
return FALSE; }
memcpy(*pstr, data + pref_len, len - pref_len); if (len - pref_len > 0) {
(*pstr)[len - pref_len] = 0; bd->data = do_alloc(allocator, len - pref_len);
return TRUE; if (bd->data == NULL) return FALSE;
} memcpy(bd->data, data + pref_len, len - pref_len);
case PROTOBUF_C_TYPE_BYTES: { } else {
ProtobufCBinaryData *bd = member; bd->data = NULL;
const ProtobufCBinaryData *def_bd; }
unsigned pref_len = scanned_member->length_prefix_len; bd->len = len - pref_len;
return TRUE;
if (wire_type != PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED) }
return FALSE; case PROTOBUF_C_TYPE_MESSAGE: {
ProtobufCMessage **pmessage = member;
def_bd = scanned_member->field->default_value; ProtobufCMessage *subm;
if (maybe_clear && const ProtobufCMessage *def_mess;
bd->data != NULL && protobuf_c_boolean merge_successful = TRUE;
(def_bd == NULL || bd->data != def_bd->data)) unsigned pref_len = scanned_member->length_prefix_len;
{
do_free(allocator, bd->data); if (wire_type != PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED) return FALSE;
}
if (len - pref_len > 0) { def_mess = scanned_member->field->default_value;
bd->data = do_alloc(allocator, len - pref_len); subm =
if (bd->data == NULL) protobuf_c_message_unpack(scanned_member->field->descriptor,
return FALSE; allocator, len - pref_len, data + pref_len);
memcpy(bd->data, data + pref_len, len - pref_len);
} else { if (maybe_clear && *pmessage != NULL && *pmessage != def_mess) {
bd->data = NULL; if (subm != NULL)
} merge_successful = merge_messages(*pmessage, subm, allocator);
bd->len = len - pref_len; /* Delete the previous message */
return TRUE; protobuf_c_message_free_unpacked(*pmessage, allocator);
} }
case PROTOBUF_C_TYPE_MESSAGE: { *pmessage = subm;
ProtobufCMessage **pmessage = member; if (subm == NULL || !merge_successful) return FALSE;
ProtobufCMessage *subm; return TRUE;
const ProtobufCMessage *def_mess; }
protobuf_c_boolean merge_successful = TRUE; }
unsigned pref_len = scanned_member->length_prefix_len; return FALSE;
}
if (wire_type != PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED)
return FALSE; static protobuf_c_boolean parse_oneof_member(ScannedMember *scanned_member,
void *member,
def_mess = scanned_member->field->default_value; ProtobufCMessage *message,
subm = protobuf_c_message_unpack(scanned_member->field->descriptor, ProtobufCAllocator *allocator) {
allocator, uint32_t *oneof_case = STRUCT_MEMBER_PTR(
len - pref_len, uint32_t, message, scanned_member->field->quantifier_offset);
data + pref_len);
/* If we have already parsed a member of this oneof, free it. */
if (maybe_clear && if (*oneof_case != 0) {
*pmessage != NULL && /* lookup field */
*pmessage != def_mess) int field_index =
{ int_range_lookup(message->descriptor->n_field_ranges,
if (subm != NULL) message->descriptor->field_ranges, *oneof_case);
merge_successful = merge_messages(*pmessage, subm, allocator); const ProtobufCFieldDescriptor *old_field =
/* Delete the previous message */ message->descriptor->fields + field_index;
protobuf_c_message_free_unpacked(*pmessage, allocator); size_t el_size = sizeof_elt_in_repeated_array(old_field->type);
}
*pmessage = subm; switch (old_field->type) {
if (subm == NULL || !merge_successful) case PROTOBUF_C_TYPE_STRING: {
return FALSE; char **pstr = member;
return TRUE; const char *def = old_field->default_value;
} if (*pstr != NULL && *pstr != def) do_free(allocator, *pstr);
} break;
return FALSE; }
} case PROTOBUF_C_TYPE_BYTES: {
ProtobufCBinaryData *bd = member;
static protobuf_c_boolean const ProtobufCBinaryData *def_bd = old_field->default_value;
parse_oneof_member (ScannedMember *scanned_member, if (bd->data != NULL && (def_bd == NULL || bd->data != def_bd->data)) {
void *member, do_free(allocator, bd->data);
ProtobufCMessage *message, }
ProtobufCAllocator *allocator) break;
{ }
uint32_t *oneof_case = STRUCT_MEMBER_PTR(uint32_t, message, case PROTOBUF_C_TYPE_MESSAGE: {
scanned_member->field->quantifier_offset); ProtobufCMessage **pmessage = member;
const ProtobufCMessage *def_mess = old_field->default_value;
/* If we have already parsed a member of this oneof, free it. */ if (*pmessage != NULL && *pmessage != def_mess)
if (*oneof_case != 0) { protobuf_c_message_free_unpacked(*pmessage, allocator);
/* lookup field */ break;
int field_index = }
int_range_lookup(message->descriptor->n_field_ranges, default:
message->descriptor->field_ranges, break;
*oneof_case); }
const ProtobufCFieldDescriptor *old_field =
message->descriptor->fields + field_index; memset(member, 0, el_size);
size_t el_size = sizeof_elt_in_repeated_array(old_field->type); }
if (!parse_required_member(scanned_member, member, allocator, TRUE))
switch (old_field->type) { return FALSE;
case PROTOBUF_C_TYPE_STRING: {
char **pstr = member; *oneof_case = scanned_member->tag;
const char *def = old_field->default_value; return TRUE;
if (*pstr != NULL && *pstr != def) }
do_free(allocator, *pstr);
break; static protobuf_c_boolean parse_optional_member(ScannedMember *scanned_member,
} void *member,
case PROTOBUF_C_TYPE_BYTES: { ProtobufCMessage *message,
ProtobufCBinaryData *bd = member; ProtobufCAllocator *allocator) {
const ProtobufCBinaryData *def_bd = old_field->default_value; if (!parse_required_member(scanned_member, member, allocator, TRUE))
if (bd->data != NULL && return FALSE;
(def_bd == NULL || bd->data != def_bd->data)) if (scanned_member->field->quantifier_offset != 0)
{ STRUCT_MEMBER(protobuf_c_boolean, message,
do_free(allocator, bd->data); scanned_member->field->quantifier_offset) = TRUE;
} return TRUE;
break; }
}
case PROTOBUF_C_TYPE_MESSAGE: { static protobuf_c_boolean parse_repeated_member(ScannedMember *scanned_member,
ProtobufCMessage **pmessage = member; void *member,
const ProtobufCMessage *def_mess = old_field->default_value; ProtobufCMessage *message,
if (*pmessage != NULL && *pmessage != def_mess) ProtobufCAllocator *allocator) {
protobuf_c_message_free_unpacked(*pmessage, allocator); const ProtobufCFieldDescriptor *field = scanned_member->field;
break; size_t *p_n = STRUCT_MEMBER_PTR(size_t, message, field->quantifier_offset);
} size_t siz = sizeof_elt_in_repeated_array(field->type);
default: char *array = *(char **)member;
break;
} if (!parse_required_member(scanned_member, array + siz * (*p_n), allocator,
FALSE)) {
memset (member, 0, el_size); return FALSE;
} }
if (!parse_required_member (scanned_member, member, allocator, TRUE)) *p_n += 1;
return FALSE; return TRUE;
}
*oneof_case = scanned_member->tag;
return TRUE; static unsigned scan_varint(unsigned len, const uint8_t *data) {
} unsigned i;
if (len > 10) len = 10;
for (i = 0; i < len; i++)
static protobuf_c_boolean if ((data[i] & 0x80) == 0) break;
parse_optional_member(ScannedMember *scanned_member, if (i == len) return 0;
void *member, return i + 1;
ProtobufCMessage *message, }
ProtobufCAllocator *allocator)
{ static protobuf_c_boolean parse_packed_repeated_member(
if (!parse_required_member(scanned_member, member, allocator, TRUE)) ScannedMember *scanned_member, void *member, ProtobufCMessage *message) {
return FALSE; const ProtobufCFieldDescriptor *field = scanned_member->field;
if (scanned_member->field->quantifier_offset != 0) size_t *p_n = STRUCT_MEMBER_PTR(size_t, message, field->quantifier_offset);
STRUCT_MEMBER(protobuf_c_boolean, size_t siz = sizeof_elt_in_repeated_array(field->type);
message, void *array = *(char **)member + siz * (*p_n);
scanned_member->field->quantifier_offset) = TRUE; const uint8_t *at = scanned_member->data + scanned_member->length_prefix_len;
return TRUE; size_t rem = scanned_member->len - scanned_member->length_prefix_len;
} size_t count = 0;
unsigned i;
static protobuf_c_boolean
parse_repeated_member(ScannedMember *scanned_member, switch (field->type) {
void *member, case PROTOBUF_C_TYPE_SFIXED32:
ProtobufCMessage *message, case PROTOBUF_C_TYPE_FIXED32:
ProtobufCAllocator *allocator) case PROTOBUF_C_TYPE_FLOAT:
{ count = (scanned_member->len - scanned_member->length_prefix_len) / 4;
const ProtobufCFieldDescriptor *field = scanned_member->field;
size_t *p_n = STRUCT_MEMBER_PTR(size_t, message, field->quantifier_offset);
size_t siz = sizeof_elt_in_repeated_array(field->type);
char *array = *(char **) member;
if (!parse_required_member(scanned_member, array + siz * (*p_n),
allocator, FALSE))
{
return FALSE;
}
*p_n += 1;
return TRUE;
}
static unsigned
scan_varint(unsigned len, const uint8_t *data)
{
unsigned i;
if (len > 10)
len = 10;
for (i = 0; i < len; i++)
if ((data[i] & 0x80) == 0)
break;
if (i == len)
return 0;
return i + 1;
}
static protobuf_c_boolean
parse_packed_repeated_member(ScannedMember *scanned_member,
void *member,
ProtobufCMessage *message)
{
const ProtobufCFieldDescriptor *field = scanned_member->field;
size_t *p_n = STRUCT_MEMBER_PTR(size_t, message, field->quantifier_offset);
size_t siz = sizeof_elt_in_repeated_array(field->type);
void *array = *(char **) member + siz * (*p_n);
const uint8_t *at = scanned_member->data + scanned_member->length_prefix_len;
size_t rem = scanned_member->len - scanned_member->length_prefix_len;
size_t count = 0;
unsigned i;
switch (field->type) {
case PROTOBUF_C_TYPE_SFIXED32:
case PROTOBUF_C_TYPE_FIXED32:
case PROTOBUF_C_TYPE_FLOAT:
count = (scanned_member->len - scanned_member->length_prefix_len) / 4;
#if !defined(WORDS_BIGENDIAN) #if !defined(WORDS_BIGENDIAN)
goto no_unpacking_needed; goto no_unpacking_needed;
#else #else
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
((uint32_t *) array)[i] = parse_fixed_uint32(at); ((uint32_t *)array)[i] = parse_fixed_uint32(at);
at += 4; at += 4;
} }
break; break;
#endif #endif
case PROTOBUF_C_TYPE_SFIXED64: case PROTOBUF_C_TYPE_SFIXED64:
case PROTOBUF_C_TYPE_FIXED64: case PROTOBUF_C_TYPE_FIXED64:
case PROTOBUF_C_TYPE_DOUBLE: case PROTOBUF_C_TYPE_DOUBLE:
count = (scanned_member->len - scanned_member->length_prefix_len) / 8; count = (scanned_member->len - scanned_member->length_prefix_len) / 8;
#if !defined(WORDS_BIGENDIAN) #if !defined(WORDS_BIGENDIAN)
goto no_unpacking_needed; goto no_unpacking_needed;
#else #else
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
((uint64_t *) array)[i] = parse_fixed_uint64(at); ((uint64_t *)array)[i] = parse_fixed_uint64(at);
at += 8; at += 8;
} }
break; break;
#endif #endif
case PROTOBUF_C_TYPE_ENUM: case PROTOBUF_C_TYPE_ENUM:
case PROTOBUF_C_TYPE_INT32: case PROTOBUF_C_TYPE_INT32:
while (rem > 0) { while (rem > 0) {
unsigned s = scan_varint(rem, at); unsigned s = scan_varint(rem, at);
if (s == 0) { if (s == 0) {
PROTOBUF_C_UNPACK_ERROR("bad packed-repeated int32 value"); PROTOBUF_C_UNPACK_ERROR("bad packed-repeated int32 value");
return FALSE; return FALSE;
} }
((int32_t *) array)[count++] = parse_int32(s, at); ((int32_t *)array)[count++] = parse_int32(s, at);
at += s; at += s;
rem -= s; rem -= s;
} }
break; break;
case PROTOBUF_C_TYPE_SINT32: case PROTOBUF_C_TYPE_SINT32:
while (rem > 0) { while (rem > 0) {
unsigned s = scan_varint(rem, at); unsigned s = scan_varint(rem, at);
if (s == 0) { if (s == 0) {
PROTOBUF_C_UNPACK_ERROR("bad packed-repeated sint32 value"); PROTOBUF_C_UNPACK_ERROR("bad packed-repeated sint32 value");
return FALSE; return FALSE;
} }
((int32_t *) array)[count++] = unzigzag32(parse_uint32(s, at)); ((int32_t *)array)[count++] = unzigzag32(parse_uint32(s, at));
at += s; at += s;
rem -= s; rem -= s;
} }
break; break;
case PROTOBUF_C_TYPE_UINT32: case PROTOBUF_C_TYPE_UINT32:
while (rem > 0) { while (rem > 0) {
unsigned s = scan_varint(rem, at); unsigned s = scan_varint(rem, at);
if (s == 0) { if (s == 0) {
PROTOBUF_C_UNPACK_ERROR("bad packed-repeated enum or uint32 value"); PROTOBUF_C_UNPACK_ERROR("bad packed-repeated enum or uint32 value");
return FALSE; return FALSE;
} }
((uint32_t *) array)[count++] = parse_uint32(s, at); ((uint32_t *)array)[count++] = parse_uint32(s, at);
at += s; at += s;
rem -= s; rem -= s;
} }
break; break;
case PROTOBUF_C_TYPE_SINT64: case PROTOBUF_C_TYPE_SINT64:
while (rem > 0) { while (rem > 0) {
unsigned s = scan_varint(rem, at); unsigned s = scan_varint(rem, at);
if (s == 0) { if (s == 0) {
PROTOBUF_C_UNPACK_ERROR("bad packed-repeated sint64 value"); PROTOBUF_C_UNPACK_ERROR("bad packed-repeated sint64 value");
return FALSE; return FALSE;
} }
((int64_t *) array)[count++] = unzigzag64(parse_uint64(s, at)); ((int64_t *)array)[count++] = unzigzag64(parse_uint64(s, at));
at += s; at += s;
rem -= s; rem -= s;
} }
break; break;
case PROTOBUF_C_TYPE_INT64: case PROTOBUF_C_TYPE_INT64:
case PROTOBUF_C_TYPE_UINT64: case PROTOBUF_C_TYPE_UINT64:
while (rem > 0) { while (rem > 0) {
unsigned s = scan_varint(rem, at); unsigned s = scan_varint(rem, at);
if (s == 0) { if (s == 0) {
PROTOBUF_C_UNPACK_ERROR("bad packed-repeated int64/uint64 value"); PROTOBUF_C_UNPACK_ERROR("bad packed-repeated int64/uint64 value");
return FALSE; return FALSE;
} }
((int64_t *) array)[count++] = parse_uint64(s, at); ((int64_t *)array)[count++] = parse_uint64(s, at);
at += s; at += s;
rem -= s; rem -= s;
} }
break; break;
case PROTOBUF_C_TYPE_BOOL: case PROTOBUF_C_TYPE_BOOL:
count = rem; count = rem;
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
if (at[i] > 1) { if (at[i] > 1) {
PROTOBUF_C_UNPACK_ERROR("bad packed-repeated boolean value"); PROTOBUF_C_UNPACK_ERROR("bad packed-repeated boolean value");
return FALSE; return FALSE;
} }
((protobuf_c_boolean *) array)[i] = at[i]; ((protobuf_c_boolean *)array)[i] = at[i];
} }
break; break;
default: default:
PROTOBUF_C__ASSERT_NOT_REACHED(); PROTOBUF_C__ASSERT_NOT_REACHED();
} }
*p_n += count; *p_n += count;
return TRUE; return TRUE;
#if !defined(WORDS_BIGENDIAN) #if !defined(WORDS_BIGENDIAN)
no_unpacking_needed: no_unpacking_needed:
memcpy(array, at, count * siz); memcpy(array, at, count * siz);
*p_n += count; *p_n += count;
return TRUE; return TRUE;
#endif #endif
} }
static protobuf_c_boolean static protobuf_c_boolean is_packable_type(ProtobufCType type) {
is_packable_type(ProtobufCType type) return type != PROTOBUF_C_TYPE_STRING && type != PROTOBUF_C_TYPE_BYTES &&
{ type != PROTOBUF_C_TYPE_MESSAGE;
return }
type != PROTOBUF_C_TYPE_STRING &&
type != PROTOBUF_C_TYPE_BYTES && static protobuf_c_boolean parse_member(ScannedMember *scanned_member,
type != PROTOBUF_C_TYPE_MESSAGE; ProtobufCMessage *message,
} ProtobufCAllocator *allocator) {
const ProtobufCFieldDescriptor *field = scanned_member->field;
static protobuf_c_boolean void *member;
parse_member(ScannedMember *scanned_member,
ProtobufCMessage *message, if (field == NULL) {
ProtobufCAllocator *allocator) ProtobufCMessageUnknownField *ufield =
{ message->unknown_fields + (message->n_unknown_fields++);
const ProtobufCFieldDescriptor *field = scanned_member->field; ufield->tag = scanned_member->tag;
void *member; ufield->wire_type = scanned_member->wire_type;
ufield->len = scanned_member->len;
if (field == NULL) { ufield->data = do_alloc(allocator, scanned_member->len);
ProtobufCMessageUnknownField *ufield = if (ufield->data == NULL) return FALSE;
message->unknown_fields + memcpy(ufield->data, scanned_member->data, ufield->len);
(message->n_unknown_fields++); return TRUE;
ufield->tag = scanned_member->tag; }
ufield->wire_type = scanned_member->wire_type; member = (char *)message + field->offset;
ufield->len = scanned_member->len; switch (field->label) {
ufield->data = do_alloc(allocator, scanned_member->len); case PROTOBUF_C_LABEL_REQUIRED:
if (ufield->data == NULL) return parse_required_member(scanned_member, member, allocator, TRUE);
return FALSE; case PROTOBUF_C_LABEL_OPTIONAL:
memcpy(ufield->data, scanned_member->data, ufield->len); case PROTOBUF_C_LABEL_NONE:
return TRUE; if (0 != (field->flags & PROTOBUF_C_FIELD_FLAG_ONEOF)) {
} return parse_oneof_member(scanned_member, member, message, allocator);
member = (char *) message + field->offset; } else {
switch (field->label) { return parse_optional_member(scanned_member, member, message,
case PROTOBUF_C_LABEL_REQUIRED: allocator);
return parse_required_member(scanned_member, member, }
allocator, TRUE); case PROTOBUF_C_LABEL_REPEATED:
case PROTOBUF_C_LABEL_OPTIONAL: if (scanned_member->wire_type == PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED &&
case PROTOBUF_C_LABEL_NONE: (0 != (field->flags & PROTOBUF_C_FIELD_FLAG_PACKED) ||
if (0 != (field->flags & PROTOBUF_C_FIELD_FLAG_ONEOF)) { is_packable_type(field->type))) {
return parse_oneof_member(scanned_member, member, return parse_packed_repeated_member(scanned_member, member, message);
message, allocator); } else {
} else { return parse_repeated_member(scanned_member, member, message,
return parse_optional_member(scanned_member, member, allocator);
message, allocator); }
} }
case PROTOBUF_C_LABEL_REPEATED: PROTOBUF_C__ASSERT_NOT_REACHED();
if (scanned_member->wire_type == return 0;
PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED &&
(0 != (field->flags & PROTOBUF_C_FIELD_FLAG_PACKED) ||
is_packable_type(field->type)))
{
return parse_packed_repeated_member(scanned_member,
member, message);
} else {
return parse_repeated_member(scanned_member,
member, message,
allocator);
}
}
PROTOBUF_C__ASSERT_NOT_REACHED();
return 0;
} }
/** /**
...@@ -2413,58 +2144,54 @@ parse_member(ScannedMember *scanned_member, ...@@ -2413,58 +2144,54 @@ parse_member(ScannedMember *scanned_member,
* for old code, and which would be useful to support allocating * for old code, and which would be useful to support allocating
* descriptors dynamically). * descriptors dynamically).
*/ */
static void static void message_init_generic(const ProtobufCMessageDescriptor *desc,
message_init_generic(const ProtobufCMessageDescriptor *desc, ProtobufCMessage *message) {
ProtobufCMessage *message) unsigned i;
{
unsigned i; memset(message, 0, desc->sizeof_message);
message->descriptor = desc;
memset(message, 0, desc->sizeof_message); for (i = 0; i < desc->n_fields; i++) {
message->descriptor = desc; if (desc->fields[i].default_value != NULL &&
for (i = 0; i < desc->n_fields; i++) { desc->fields[i].label != PROTOBUF_C_LABEL_REPEATED) {
if (desc->fields[i].default_value != NULL && void *field = STRUCT_MEMBER_P(message, desc->fields[i].offset);
desc->fields[i].label != PROTOBUF_C_LABEL_REPEATED) const void *dv = desc->fields[i].default_value;
{
void *field = switch (desc->fields[i].type) {
STRUCT_MEMBER_P(message, desc->fields[i].offset); case PROTOBUF_C_TYPE_INT32:
const void *dv = desc->fields[i].default_value; case PROTOBUF_C_TYPE_SINT32:
case PROTOBUF_C_TYPE_SFIXED32:
switch (desc->fields[i].type) { case PROTOBUF_C_TYPE_UINT32:
case PROTOBUF_C_TYPE_INT32: case PROTOBUF_C_TYPE_FIXED32:
case PROTOBUF_C_TYPE_SINT32: case PROTOBUF_C_TYPE_FLOAT:
case PROTOBUF_C_TYPE_SFIXED32: case PROTOBUF_C_TYPE_ENUM:
case PROTOBUF_C_TYPE_UINT32: memcpy(field, dv, 4);
case PROTOBUF_C_TYPE_FIXED32: break;
case PROTOBUF_C_TYPE_FLOAT: case PROTOBUF_C_TYPE_INT64:
case PROTOBUF_C_TYPE_ENUM: case PROTOBUF_C_TYPE_SINT64:
memcpy(field, dv, 4); case PROTOBUF_C_TYPE_SFIXED64:
break; case PROTOBUF_C_TYPE_UINT64:
case PROTOBUF_C_TYPE_INT64: case PROTOBUF_C_TYPE_FIXED64:
case PROTOBUF_C_TYPE_SINT64: case PROTOBUF_C_TYPE_DOUBLE:
case PROTOBUF_C_TYPE_SFIXED64: memcpy(field, dv, 8);
case PROTOBUF_C_TYPE_UINT64: break;
case PROTOBUF_C_TYPE_FIXED64: case PROTOBUF_C_TYPE_BOOL:
case PROTOBUF_C_TYPE_DOUBLE: memcpy(field, dv, sizeof(protobuf_c_boolean));
memcpy(field, dv, 8); break;
break; case PROTOBUF_C_TYPE_BYTES:
case PROTOBUF_C_TYPE_BOOL: memcpy(field, dv, sizeof(ProtobufCBinaryData));
memcpy(field, dv, sizeof(protobuf_c_boolean)); break;
break;
case PROTOBUF_C_TYPE_BYTES: case PROTOBUF_C_TYPE_STRING:
memcpy(field, dv, sizeof(ProtobufCBinaryData)); case PROTOBUF_C_TYPE_MESSAGE:
break; /*
* The next line essentially implements a cast
case PROTOBUF_C_TYPE_STRING: * from const, which is totally unavoidable.
case PROTOBUF_C_TYPE_MESSAGE: */
/* *(const void **)field = dv;
* The next line essentially implements a cast break;
* from const, which is totally unavoidable. }
*/ }
*(const void **) field = dv; }
break;
}
}
}
} }
/**@}*/ /**@}*/
...@@ -2485,650 +2212,573 @@ message_init_generic(const ProtobufCMessageDescriptor *desc, ...@@ -2485,650 +2212,573 @@ message_init_generic(const ProtobufCMessageDescriptor *desc,
* The number of slabs, including the stack-allocated ones; choose the number so * The number of slabs, including the stack-allocated ones; choose the number so
* that we would overflow if we needed a slab larger than provided. * that we would overflow if we needed a slab larger than provided.
*/ */
#define MAX_SCANNED_MEMBER_SLAB \ #define MAX_SCANNED_MEMBER_SLAB \
(sizeof(unsigned int)*8 - 1 \ (sizeof(unsigned int) * 8 - 1 - BOUND_SIZEOF_SCANNED_MEMBER_LOG2 - \
- BOUND_SIZEOF_SCANNED_MEMBER_LOG2 \ FIRST_SCANNED_MEMBER_SLAB_SIZE_LOG2)
- FIRST_SCANNED_MEMBER_SLAB_SIZE_LOG2)
#define REQUIRED_FIELD_BITMAP_SET(index) \
#define REQUIRED_FIELD_BITMAP_SET(index) \ (required_fields_bitmap[(index) / 8] |= (1UL << ((index) % 8)))
(required_fields_bitmap[(index)/8] |= (1UL<<((index)%8)))
#define REQUIRED_FIELD_BITMAP_IS_SET(index) \
#define REQUIRED_FIELD_BITMAP_IS_SET(index) \ (required_fields_bitmap[(index) / 8] & (1UL << ((index) % 8)))
(required_fields_bitmap[(index)/8] & (1UL<<((index)%8)))
ProtobufCMessage *protobuf_c_message_unpack(
ProtobufCMessage * const ProtobufCMessageDescriptor *desc, ProtobufCAllocator *allocator,
protobuf_c_message_unpack(const ProtobufCMessageDescriptor *desc, size_t len, const uint8_t *data) {
ProtobufCAllocator *allocator, ProtobufCMessage *rv;
size_t len, const uint8_t *data) size_t rem = len;
{ const uint8_t *at = data;
ProtobufCMessage *rv; const ProtobufCFieldDescriptor *last_field = desc->fields + 0;
size_t rem = len; ScannedMember first_member_slab[1UL << FIRST_SCANNED_MEMBER_SLAB_SIZE_LOG2];
const uint8_t *at = data;
const ProtobufCFieldDescriptor *last_field = desc->fields + 0; /*
ScannedMember first_member_slab[1UL << * scanned_member_slabs[i] is an array of arrays of ScannedMember.
FIRST_SCANNED_MEMBER_SLAB_SIZE_LOG2]; * The first slab (scanned_member_slabs[0] is just a pointer to
* first_member_slab), above. All subsequent slabs will be allocated
/* * using the allocator.
* scanned_member_slabs[i] is an array of arrays of ScannedMember. */
* The first slab (scanned_member_slabs[0] is just a pointer to ScannedMember *scanned_member_slabs[MAX_SCANNED_MEMBER_SLAB + 1];
* first_member_slab), above. All subsequent slabs will be allocated unsigned which_slab = 0; /* the slab we are currently populating */
* using the allocator. unsigned in_slab_index = 0; /* number of members in the slab */
*/ size_t n_unknown = 0;
ScannedMember *scanned_member_slabs[MAX_SCANNED_MEMBER_SLAB + 1]; unsigned f;
unsigned which_slab = 0; /* the slab we are currently populating */ unsigned j;
unsigned in_slab_index = 0; /* number of members in the slab */ unsigned i_slab;
size_t n_unknown = 0; unsigned last_field_index = 0;
unsigned f; unsigned required_fields_bitmap_len;
unsigned j; unsigned char required_fields_bitmap_stack[16];
unsigned i_slab; unsigned char *required_fields_bitmap = required_fields_bitmap_stack;
unsigned last_field_index = 0; protobuf_c_boolean required_fields_bitmap_alloced = FALSE;
unsigned required_fields_bitmap_len;
unsigned char required_fields_bitmap_stack[16]; ASSERT_IS_MESSAGE_DESCRIPTOR(desc);
unsigned char *required_fields_bitmap = required_fields_bitmap_stack;
protobuf_c_boolean required_fields_bitmap_alloced = FALSE; if (allocator == NULL) allocator = &protobuf_c__allocator;
ASSERT_IS_MESSAGE_DESCRIPTOR(desc); rv = do_alloc(allocator, desc->sizeof_message);
if (!rv) return (NULL);
if (allocator == NULL) scanned_member_slabs[0] = first_member_slab;
allocator = &protobuf_c__allocator;
required_fields_bitmap_len = (desc->n_fields + 7) / 8;
rv = do_alloc(allocator, desc->sizeof_message); if (required_fields_bitmap_len > sizeof(required_fields_bitmap_stack)) {
if (!rv) required_fields_bitmap = do_alloc(allocator, required_fields_bitmap_len);
return (NULL); if (!required_fields_bitmap) {
scanned_member_slabs[0] = first_member_slab; do_free(allocator, rv);
return (NULL);
required_fields_bitmap_len = (desc->n_fields + 7) / 8; }
if (required_fields_bitmap_len > sizeof(required_fields_bitmap_stack)) { required_fields_bitmap_alloced = TRUE;
required_fields_bitmap = do_alloc(allocator, required_fields_bitmap_len); }
if (!required_fields_bitmap) { memset(required_fields_bitmap, 0, required_fields_bitmap_len);
do_free(allocator, rv);
return (NULL); /*
} * Generated code always defines "message_init". However, we provide a
required_fields_bitmap_alloced = TRUE; * fallback for (1) users of old protobuf-c generated-code that do not
} * provide the function, and (2) descriptors constructed from some other
memset(required_fields_bitmap, 0, required_fields_bitmap_len); * source (most likely, direct construction from the .proto file).
*/
/* if (desc->message_init != NULL)
* Generated code always defines "message_init". However, we provide a protobuf_c_message_init(desc, rv);
* fallback for (1) users of old protobuf-c generated-code that do not else
* provide the function, and (2) descriptors constructed from some other message_init_generic(desc, rv);
* source (most likely, direct construction from the .proto file).
*/ while (rem > 0) {
if (desc->message_init != NULL) uint32_t tag;
protobuf_c_message_init(desc, rv); ProtobufCWireType wire_type;
else size_t used = parse_tag_and_wiretype(rem, at, &tag, &wire_type);
message_init_generic(desc, rv); const ProtobufCFieldDescriptor *field;
ScannedMember tmp;
while (rem > 0) {
uint32_t tag; if (used == 0) {
ProtobufCWireType wire_type; PROTOBUF_C_UNPACK_ERROR("error parsing tag/wiretype at offset %u",
size_t used = parse_tag_and_wiretype(rem, at, &tag, &wire_type); (unsigned)(at - data));
const ProtobufCFieldDescriptor *field; goto error_cleanup_during_scan;
ScannedMember tmp; }
/*
if (used == 0) { * \todo Consider optimizing for field[1].id == tag, if field[1]
PROTOBUF_C_UNPACK_ERROR("error parsing tag/wiretype at offset %u", * exists!
(unsigned) (at - data)); */
goto error_cleanup_during_scan; if (last_field == NULL || last_field->id != tag) {
} /* lookup field */
/* int field_index =
* \todo Consider optimizing for field[1].id == tag, if field[1] int_range_lookup(desc->n_field_ranges, desc->field_ranges, tag);
* exists! if (field_index < 0) {
*/ field = NULL;
if (last_field == NULL || last_field->id != tag) { n_unknown++;
/* lookup field */ } else {
int field_index = field = desc->fields + field_index;
int_range_lookup(desc->n_field_ranges, last_field = field;
desc->field_ranges, last_field_index = field_index;
tag); }
if (field_index < 0) { } else {
field = NULL; field = last_field;
n_unknown++; }
} else {
field = desc->fields + field_index; if (field != NULL && field->label == PROTOBUF_C_LABEL_REQUIRED)
last_field = field; REQUIRED_FIELD_BITMAP_SET(last_field_index);
last_field_index = field_index;
} at += used;
} else { rem -= used;
field = last_field; tmp.tag = tag;
} tmp.wire_type = wire_type;
tmp.field = field;
if (field != NULL && field->label == PROTOBUF_C_LABEL_REQUIRED) tmp.data = at;
REQUIRED_FIELD_BITMAP_SET(last_field_index); tmp.length_prefix_len = 0;
at += used; switch (wire_type) {
rem -= used; case PROTOBUF_C_WIRE_TYPE_VARINT: {
tmp.tag = tag; unsigned max_len = rem < 10 ? rem : 10;
tmp.wire_type = wire_type; unsigned i;
tmp.field = field;
tmp.data = at; for (i = 0; i < max_len; i++)
tmp.length_prefix_len = 0; if ((at[i] & 0x80) == 0) break;
if (i == max_len) {
switch (wire_type) { PROTOBUF_C_UNPACK_ERROR("unterminated varint at offset %u",
case PROTOBUF_C_WIRE_TYPE_VARINT: { (unsigned)(at - data));
unsigned max_len = rem < 10 ? rem : 10; goto error_cleanup_during_scan;
unsigned i; }
tmp.len = i + 1;
for (i = 0; i < max_len; i++) break;
if ((at[i] & 0x80) == 0) }
break; case PROTOBUF_C_WIRE_TYPE_64BIT:
if (i == max_len) { if (rem < 8) {
PROTOBUF_C_UNPACK_ERROR("unterminated varint at offset %u", PROTOBUF_C_UNPACK_ERROR("too short after 64bit wiretype at offset %u",
(unsigned) (at - data)); (unsigned)(at - data));
goto error_cleanup_during_scan; goto error_cleanup_during_scan;
} }
tmp.len = i + 1; tmp.len = 8;
break; break;
} case PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED: {
case PROTOBUF_C_WIRE_TYPE_64BIT: size_t pref_len;
if (rem < 8) {
PROTOBUF_C_UNPACK_ERROR("too short after 64bit wiretype at offset %u", tmp.len = scan_length_prefixed_data(rem, at, &pref_len);
(unsigned) (at - data)); if (tmp.len == 0) {
goto error_cleanup_during_scan; /* NOTE: scan_length_prefixed_data calls UNPACK_ERROR */
} goto error_cleanup_during_scan;
tmp.len = 8; }
break; tmp.length_prefix_len = pref_len;
case PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED: { break;
size_t pref_len; }
case PROTOBUF_C_WIRE_TYPE_32BIT:
tmp.len = scan_length_prefixed_data(rem, at, &pref_len); if (rem < 4) {
if (tmp.len == 0) { PROTOBUF_C_UNPACK_ERROR("too short after 32bit wiretype at offset %u",
/* NOTE: scan_length_prefixed_data calls UNPACK_ERROR */ (unsigned)(at - data));
goto error_cleanup_during_scan; goto error_cleanup_during_scan;
} }
tmp.length_prefix_len = pref_len; tmp.len = 4;
break; break;
} default:
case PROTOBUF_C_WIRE_TYPE_32BIT: PROTOBUF_C_UNPACK_ERROR("unsupported tag %u at offset %u", wire_type,
if (rem < 4) { (unsigned)(at - data));
PROTOBUF_C_UNPACK_ERROR("too short after 32bit wiretype at offset %u", goto error_cleanup_during_scan;
(unsigned) (at - data)); }
goto error_cleanup_during_scan;
} if (in_slab_index ==
tmp.len = 4; (1UL << (which_slab + FIRST_SCANNED_MEMBER_SLAB_SIZE_LOG2))) {
break; size_t size;
default:
PROTOBUF_C_UNPACK_ERROR("unsupported tag %u at offset %u", in_slab_index = 0;
wire_type, (unsigned) (at - data)); if (which_slab == MAX_SCANNED_MEMBER_SLAB) {
goto error_cleanup_during_scan; PROTOBUF_C_UNPACK_ERROR("too many fields");
} goto error_cleanup_during_scan;
}
if (in_slab_index == (1UL << which_slab++;
(which_slab + FIRST_SCANNED_MEMBER_SLAB_SIZE_LOG2))) size = sizeof(ScannedMember)
{ << (which_slab + FIRST_SCANNED_MEMBER_SLAB_SIZE_LOG2);
size_t size; scanned_member_slabs[which_slab] = do_alloc(allocator, size);
if (scanned_member_slabs[which_slab] == NULL)
in_slab_index = 0; goto error_cleanup_during_scan;
if (which_slab == MAX_SCANNED_MEMBER_SLAB) { }
PROTOBUF_C_UNPACK_ERROR("too many fields"); scanned_member_slabs[which_slab][in_slab_index++] = tmp;
goto error_cleanup_during_scan;
} if (field != NULL && field->label == PROTOBUF_C_LABEL_REPEATED) {
which_slab++; size_t *n = STRUCT_MEMBER_PTR(size_t, rv, field->quantifier_offset);
size = sizeof(ScannedMember) if (wire_type == PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED &&
<< (which_slab + FIRST_SCANNED_MEMBER_SLAB_SIZE_LOG2); (0 != (field->flags & PROTOBUF_C_FIELD_FLAG_PACKED) ||
scanned_member_slabs[which_slab] = do_alloc(allocator, size); is_packable_type(field->type))) {
if (scanned_member_slabs[which_slab] == NULL) size_t count;
goto error_cleanup_during_scan; if (!count_packed_elements(field->type, tmp.len - tmp.length_prefix_len,
} tmp.data + tmp.length_prefix_len, &count)) {
scanned_member_slabs[which_slab][in_slab_index++] = tmp; PROTOBUF_C_UNPACK_ERROR("counting packed elements");
goto error_cleanup_during_scan;
if (field != NULL && field->label == PROTOBUF_C_LABEL_REPEATED) { }
size_t *n = STRUCT_MEMBER_PTR(size_t, rv, *n += count;
field->quantifier_offset); } else {
if (wire_type == PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED && *n += 1;
(0 != (field->flags & PROTOBUF_C_FIELD_FLAG_PACKED) || }
is_packable_type(field->type))) }
{
size_t count; at += tmp.len;
if (!count_packed_elements(field->type, rem -= tmp.len;
tmp.len - }
tmp.length_prefix_len,
tmp.data + /* allocate space for repeated fields, also check that all required fields
tmp.length_prefix_len, * have been set */
&count)) for (f = 0; f < desc->n_fields; f++) {
{ const ProtobufCFieldDescriptor *field = desc->fields + f;
PROTOBUF_C_UNPACK_ERROR("counting packed elements"); if (field->label == PROTOBUF_C_LABEL_REPEATED) {
goto error_cleanup_during_scan; size_t siz = sizeof_elt_in_repeated_array(field->type);
} size_t *n_ptr = STRUCT_MEMBER_PTR(size_t, rv, field->quantifier_offset);
*n += count; if (*n_ptr != 0) {
} else { unsigned n = *n_ptr;
*n += 1; void *a;
} *n_ptr = 0;
} assert(rv->descriptor != NULL);
#define CLEAR_REMAINING_N_PTRS() \
at += tmp.len; for (f++; f < desc->n_fields; f++) { \
rem -= tmp.len; field = desc->fields + f; \
} if (field->label == PROTOBUF_C_LABEL_REPEATED) \
STRUCT_MEMBER(size_t, rv, field->quantifier_offset) = 0; \
/* allocate space for repeated fields, also check that all required fields have been set */ }
for (f = 0; f < desc->n_fields; f++) { a = do_alloc(allocator, siz * n);
const ProtobufCFieldDescriptor *field = desc->fields + f; if (!a) {
if (field->label == PROTOBUF_C_LABEL_REPEATED) { CLEAR_REMAINING_N_PTRS();
size_t siz = goto error_cleanup;
sizeof_elt_in_repeated_array(field->type); }
size_t *n_ptr = STRUCT_MEMBER(void *, rv, field->offset) = a;
STRUCT_MEMBER_PTR(size_t, rv, }
field->quantifier_offset); } else if (field->label == PROTOBUF_C_LABEL_REQUIRED) {
if (*n_ptr != 0) { if (field->default_value == NULL && !REQUIRED_FIELD_BITMAP_IS_SET(f)) {
unsigned n = *n_ptr; CLEAR_REMAINING_N_PTRS();
void *a; PROTOBUF_C_UNPACK_ERROR("message '%s': missing required field '%s'",
*n_ptr = 0; desc->name, field->name);
assert(rv->descriptor != NULL); goto error_cleanup;
#define CLEAR_REMAINING_N_PTRS() \ }
for(f++;f < desc->n_fields; f++) \ }
{ \ }
field = desc->fields + f; \
if (field->label == PROTOBUF_C_LABEL_REPEATED) \
STRUCT_MEMBER (size_t, rv, field->quantifier_offset) = 0; \
}
a = do_alloc(allocator, siz * n);
if (!a) {
CLEAR_REMAINING_N_PTRS();
goto error_cleanup;
}
STRUCT_MEMBER(void *, rv, field->offset) = a;
}
} else if (field->label == PROTOBUF_C_LABEL_REQUIRED) {
if (field->default_value == NULL &&
!REQUIRED_FIELD_BITMAP_IS_SET(f))
{
CLEAR_REMAINING_N_PTRS();
PROTOBUF_C_UNPACK_ERROR("message '%s': missing required field '%s'",
desc->name, field->name);
goto error_cleanup;
}
}
}
#undef CLEAR_REMAINING_N_PTRS #undef CLEAR_REMAINING_N_PTRS
/* allocate space for unknown fields */ /* allocate space for unknown fields */
if (n_unknown) { if (n_unknown) {
rv->unknown_fields = do_alloc(allocator, rv->unknown_fields =
n_unknown * sizeof(ProtobufCMessageUnknownField)); do_alloc(allocator, n_unknown * sizeof(ProtobufCMessageUnknownField));
if (rv->unknown_fields == NULL) if (rv->unknown_fields == NULL) goto error_cleanup;
goto error_cleanup; }
}
/* do real parsing */
/* do real parsing */ for (i_slab = 0; i_slab <= which_slab; i_slab++) {
for (i_slab = 0; i_slab <= which_slab; i_slab++) { unsigned max =
unsigned max = (i_slab == which_slab) ? (i_slab == which_slab) ? in_slab_index : (1UL << (i_slab + 4));
in_slab_index : (1UL << (i_slab + 4)); ScannedMember *slab = scanned_member_slabs[i_slab];
ScannedMember *slab = scanned_member_slabs[i_slab];
for (j = 0; j < max; j++) {
for (j = 0; j < max; j++) { if (!parse_member(slab + j, rv, allocator)) {
if (!parse_member(slab + j, rv, allocator)) { PROTOBUF_C_UNPACK_ERROR(
PROTOBUF_C_UNPACK_ERROR("error parsing member %s of %s", "error parsing member %s of %s",
slab->field ? slab->field->name : "*unknown-field*", slab->field ? slab->field->name : "*unknown-field*", desc->name);
desc->name); goto error_cleanup;
goto error_cleanup; }
} }
} }
}
/* cleanup */
/* cleanup */ for (j = 1; j <= which_slab; j++) do_free(allocator, scanned_member_slabs[j]);
for (j = 1; j <= which_slab; j++) if (required_fields_bitmap_alloced)
do_free(allocator, scanned_member_slabs[j]); do_free(allocator, required_fields_bitmap);
if (required_fields_bitmap_alloced) return rv;
do_free(allocator, required_fields_bitmap);
return rv;
error_cleanup: error_cleanup:
protobuf_c_message_free_unpacked(rv, allocator); protobuf_c_message_free_unpacked(rv, allocator);
for (j = 1; j <= which_slab; j++) for (j = 1; j <= which_slab; j++) do_free(allocator, scanned_member_slabs[j]);
do_free(allocator, scanned_member_slabs[j]); if (required_fields_bitmap_alloced)
if (required_fields_bitmap_alloced) do_free(allocator, required_fields_bitmap);
do_free(allocator, required_fields_bitmap); return NULL;
return NULL;
error_cleanup_during_scan: error_cleanup_during_scan:
do_free(allocator, rv); do_free(allocator, rv);
for (j = 1; j <= which_slab; j++) for (j = 1; j <= which_slab; j++) do_free(allocator, scanned_member_slabs[j]);
do_free(allocator, scanned_member_slabs[j]); if (required_fields_bitmap_alloced)
if (required_fields_bitmap_alloced) do_free(allocator, required_fields_bitmap);
do_free(allocator, required_fields_bitmap); return NULL;
return NULL; }
}
void protobuf_c_message_free_unpacked(ProtobufCMessage *message,
void ProtobufCAllocator *allocator) {
protobuf_c_message_free_unpacked(ProtobufCMessage *message, const ProtobufCMessageDescriptor *desc;
ProtobufCAllocator *allocator) unsigned f;
{
const ProtobufCMessageDescriptor *desc; if (message == NULL) return;
unsigned f;
desc = message->descriptor;
if (message == NULL)
return; ASSERT_IS_MESSAGE(message);
desc = message->descriptor; if (allocator == NULL) allocator = &protobuf_c__allocator;
message->descriptor = NULL;
ASSERT_IS_MESSAGE(message); for (f = 0; f < desc->n_fields; f++) {
if (0 != (desc->fields[f].flags & PROTOBUF_C_FIELD_FLAG_ONEOF) &&
if (allocator == NULL) desc->fields[f].id !=
allocator = &protobuf_c__allocator; STRUCT_MEMBER(uint32_t, message,
message->descriptor = NULL; desc->fields[f].quantifier_offset)) {
for (f = 0; f < desc->n_fields; f++) { /* This is not the selected oneof, skip it */
if (0 != (desc->fields[f].flags & PROTOBUF_C_FIELD_FLAG_ONEOF) && continue;
desc->fields[f].id != }
STRUCT_MEMBER(uint32_t, message, desc->fields[f].quantifier_offset))
{ if (desc->fields[f].label == PROTOBUF_C_LABEL_REPEATED) {
/* This is not the selected oneof, skip it */ size_t n =
continue; STRUCT_MEMBER(size_t, message, desc->fields[f].quantifier_offset);
} void *arr = STRUCT_MEMBER(void *, message, desc->fields[f].offset);
if (desc->fields[f].label == PROTOBUF_C_LABEL_REPEATED) { if (arr != NULL) {
size_t n = STRUCT_MEMBER(size_t, if (desc->fields[f].type == PROTOBUF_C_TYPE_STRING) {
message, unsigned i;
desc->fields[f].quantifier_offset); for (i = 0; i < n; i++) do_free(allocator, ((char **)arr)[i]);
void *arr = STRUCT_MEMBER(void *, } else if (desc->fields[f].type == PROTOBUF_C_TYPE_BYTES) {
message, unsigned i;
desc->fields[f].offset); for (i = 0; i < n; i++)
do_free(allocator, ((ProtobufCBinaryData *)arr)[i].data);
if (arr != NULL) { } else if (desc->fields[f].type == PROTOBUF_C_TYPE_MESSAGE) {
if (desc->fields[f].type == PROTOBUF_C_TYPE_STRING) { unsigned i;
unsigned i; for (i = 0; i < n; i++)
for (i = 0; i < n; i++) protobuf_c_message_free_unpacked(((ProtobufCMessage **)arr)[i],
do_free(allocator, ((char **) arr)[i]); allocator);
} else if (desc->fields[f].type == PROTOBUF_C_TYPE_BYTES) { }
unsigned i; do_free(allocator, arr);
for (i = 0; i < n; i++) }
do_free(allocator, ((ProtobufCBinaryData *) arr)[i].data); } else if (desc->fields[f].type == PROTOBUF_C_TYPE_STRING) {
} else if (desc->fields[f].type == PROTOBUF_C_TYPE_MESSAGE) { char *str = STRUCT_MEMBER(char *, message, desc->fields[f].offset);
unsigned i;
for (i = 0; i < n; i++) if (str && str != desc->fields[f].default_value) do_free(allocator, str);
protobuf_c_message_free_unpacked( } else if (desc->fields[f].type == PROTOBUF_C_TYPE_BYTES) {
((ProtobufCMessage **) arr)[i], void *data =
allocator STRUCT_MEMBER(ProtobufCBinaryData, message, desc->fields[f].offset)
); .data;
} const ProtobufCBinaryData *default_bd;
do_free(allocator, arr);
} default_bd = desc->fields[f].default_value;
} else if (desc->fields[f].type == PROTOBUF_C_TYPE_STRING) { if (data != NULL && (default_bd == NULL || default_bd->data != data)) {
char *str = STRUCT_MEMBER(char *, message, do_free(allocator, data);
desc->fields[f].offset); }
} else if (desc->fields[f].type == PROTOBUF_C_TYPE_MESSAGE) {
if (str && str != desc->fields[f].default_value) ProtobufCMessage *sm;
do_free(allocator, str);
} else if (desc->fields[f].type == PROTOBUF_C_TYPE_BYTES) { sm = STRUCT_MEMBER(ProtobufCMessage *, message, desc->fields[f].offset);
void *data = STRUCT_MEMBER(ProtobufCBinaryData, message, if (sm && sm != desc->fields[f].default_value)
desc->fields[f].offset).data; protobuf_c_message_free_unpacked(sm, allocator);
const ProtobufCBinaryData *default_bd; }
}
default_bd = desc->fields[f].default_value;
if (data != NULL && for (f = 0; f < message->n_unknown_fields; f++)
(default_bd == NULL || do_free(allocator, message->unknown_fields[f].data);
default_bd->data != data)) if (message->unknown_fields != NULL)
{ do_free(allocator, message->unknown_fields);
do_free(allocator, data);
} do_free(allocator, message);
} else if (desc->fields[f].type == PROTOBUF_C_TYPE_MESSAGE) { }
ProtobufCMessage *sm;
void protobuf_c_message_init(const ProtobufCMessageDescriptor *descriptor,
sm = STRUCT_MEMBER(ProtobufCMessage *, message, void *message) {
desc->fields[f].offset); descriptor->message_init((ProtobufCMessage *)(message));
if (sm && sm != desc->fields[f].default_value) }
protobuf_c_message_free_unpacked(sm, allocator);
} protobuf_c_boolean protobuf_c_message_check(const ProtobufCMessage *message) {
} unsigned i;
for (f = 0; f < message->n_unknown_fields; f++) if (!message || !message->descriptor ||
do_free(allocator, message->unknown_fields[f].data); message->descriptor->magic != PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC) {
if (message->unknown_fields != NULL) return FALSE;
do_free(allocator, message->unknown_fields); }
do_free(allocator, message); for (i = 0; i < message->descriptor->n_fields; i++) {
} const ProtobufCFieldDescriptor *f = message->descriptor->fields + i;
ProtobufCType type = f->type;
void ProtobufCLabel label = f->label;
protobuf_c_message_init(const ProtobufCMessageDescriptor * descriptor, void *field = STRUCT_MEMBER_P(message, f->offset);
void *message)
{ if (label == PROTOBUF_C_LABEL_REPEATED) {
descriptor->message_init((ProtobufCMessage *) (message)); size_t *quantity = STRUCT_MEMBER_P(message, f->quantifier_offset);
}
if (*quantity > 0 && *(void **)field == NULL) {
protobuf_c_boolean return FALSE;
protobuf_c_message_check(const ProtobufCMessage *message) }
{
unsigned i; if (type == PROTOBUF_C_TYPE_MESSAGE) {
ProtobufCMessage **submessage = *(ProtobufCMessage ***)field;
if (!message || unsigned j;
!message->descriptor || for (j = 0; j < *quantity; j++) {
message->descriptor->magic != PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC) if (!protobuf_c_message_check(submessage[j])) return FALSE;
{ }
return FALSE; } else if (type == PROTOBUF_C_TYPE_STRING) {
} char **string = *(char ***)field;
unsigned j;
for (i = 0; i < message->descriptor->n_fields; i++) { for (j = 0; j < *quantity; j++) {
const ProtobufCFieldDescriptor *f = message->descriptor->fields + i; if (!string[j]) return FALSE;
ProtobufCType type = f->type; }
ProtobufCLabel label = f->label; } else if (type == PROTOBUF_C_TYPE_BYTES) {
void *field = STRUCT_MEMBER_P (message, f->offset); ProtobufCBinaryData *bd = *(ProtobufCBinaryData **)field;
unsigned j;
if (label == PROTOBUF_C_LABEL_REPEATED) { for (j = 0; j < *quantity; j++) {
size_t *quantity = STRUCT_MEMBER_P (message, f->quantifier_offset); if (bd[j].len > 0 && bd[j].data == NULL) return FALSE;
}
if (*quantity > 0 && *(void **) field == NULL) { }
return FALSE;
} } else { /* PROTOBUF_C_LABEL_REQUIRED or PROTOBUF_C_LABEL_OPTIONAL */
if (type == PROTOBUF_C_TYPE_MESSAGE) { if (type == PROTOBUF_C_TYPE_MESSAGE) {
ProtobufCMessage **submessage = *(ProtobufCMessage ***) field; ProtobufCMessage *submessage = *(ProtobufCMessage **)field;
unsigned j; if (label == PROTOBUF_C_LABEL_REQUIRED || submessage != NULL) {
for (j = 0; j < *quantity; j++) { if (!protobuf_c_message_check(submessage)) return FALSE;
if (!protobuf_c_message_check(submessage[j])) }
return FALSE; } else if (type == PROTOBUF_C_TYPE_STRING) {
} char *string = *(char **)field;
} else if (type == PROTOBUF_C_TYPE_STRING) { if (label == PROTOBUF_C_LABEL_REQUIRED && string == NULL) return FALSE;
char **string = *(char ***) field; } else if (type == PROTOBUF_C_TYPE_BYTES) {
unsigned j; protobuf_c_boolean *has =
for (j = 0; j < *quantity; j++) { STRUCT_MEMBER_P(message, f->quantifier_offset);
if (!string[j]) ProtobufCBinaryData *bd = field;
return FALSE; if (label == PROTOBUF_C_LABEL_REQUIRED || *has == TRUE) {
} if (bd->len > 0 && bd->data == NULL) return FALSE;
} else if (type == PROTOBUF_C_TYPE_BYTES) { }
ProtobufCBinaryData *bd = *(ProtobufCBinaryData **) field; }
unsigned j; }
for (j = 0; j < *quantity; j++) { }
if (bd[j].len > 0 && bd[j].data == NULL)
return FALSE; return TRUE;
}
}
} else { /* PROTOBUF_C_LABEL_REQUIRED or PROTOBUF_C_LABEL_OPTIONAL */
if (type == PROTOBUF_C_TYPE_MESSAGE) {
ProtobufCMessage *submessage = *(ProtobufCMessage **) field;
if (label == PROTOBUF_C_LABEL_REQUIRED || submessage != NULL) {
if (!protobuf_c_message_check(submessage))
return FALSE;
}
} else if (type == PROTOBUF_C_TYPE_STRING) {
char *string = *(char **) field;
if (label == PROTOBUF_C_LABEL_REQUIRED && string == NULL)
return FALSE;
} else if (type == PROTOBUF_C_TYPE_BYTES) {
protobuf_c_boolean *has = STRUCT_MEMBER_P (message, f->quantifier_offset);
ProtobufCBinaryData *bd = field;
if (label == PROTOBUF_C_LABEL_REQUIRED || *has == TRUE) {
if (bd->len > 0 && bd->data == NULL)
return FALSE;
}
}
}
}
return TRUE;
} }
/* === services === */ /* === services === */
typedef void (*GenericHandler) (void *service, typedef void (*GenericHandler)(void *service, const ProtobufCMessage *input,
const ProtobufCMessage *input, ProtobufCClosure closure, void *closure_data);
ProtobufCClosure closure, void protobuf_c_service_invoke_internal(ProtobufCService *service,
void *closure_data); unsigned method_index,
void const ProtobufCMessage *input,
protobuf_c_service_invoke_internal(ProtobufCService *service, ProtobufCClosure closure,
unsigned method_index, void *closure_data) {
const ProtobufCMessage *input, GenericHandler *handlers;
ProtobufCClosure closure, GenericHandler handler;
void *closure_data)
{ /*
GenericHandler *handlers; * Verify that method_index is within range. If this fails, you are
GenericHandler handler; * likely invoking a newly added method on an old service. (Although
* other memory corruption bugs can cause this assertion too.)
/* */
* Verify that method_index is within range. If this fails, you are assert(method_index < service->descriptor->n_methods);
* likely invoking a newly added method on an old service. (Although
* other memory corruption bugs can cause this assertion too.) /*
*/ * Get the array of virtual methods (which are enumerated by the
assert(method_index < service->descriptor->n_methods); * generated code).
*/
/* handlers = (GenericHandler *)(service + 1);
* Get the array of virtual methods (which are enumerated by the
* generated code). /*
*/ * Get our method and invoke it.
handlers = (GenericHandler *) (service + 1); * \todo Seems like handler == NULL is a situation that needs handling.
*/
/* handler = handlers[method_index];
* Get our method and invoke it. (*handler)(service, input, closure, closure_data);
* \todo Seems like handler == NULL is a situation that needs handling. }
*/
handler = handlers[method_index]; void protobuf_c_service_generated_init(
(*handler)(service, input, closure, closure_data); ProtobufCService *service, const ProtobufCServiceDescriptor *descriptor,
} ProtobufCServiceDestroy destroy) {
ASSERT_IS_SERVICE_DESCRIPTOR(descriptor);
void service->descriptor = descriptor;
protobuf_c_service_generated_init(ProtobufCService *service, service->destroy = destroy;
const ProtobufCServiceDescriptor *descriptor, service->invoke = protobuf_c_service_invoke_internal;
ProtobufCServiceDestroy destroy) memset(service + 1, 0, descriptor->n_methods * sizeof(GenericHandler));
{ }
ASSERT_IS_SERVICE_DESCRIPTOR(descriptor);
service->descriptor = descriptor; void protobuf_c_service_destroy(ProtobufCService *service) {
service->destroy = destroy; service->destroy(service);
service->invoke = protobuf_c_service_invoke_internal;
memset(service + 1, 0, descriptor->n_methods * sizeof(GenericHandler));
}
void protobuf_c_service_destroy(ProtobufCService *service)
{
service->destroy(service);
} }
/* --- querying the descriptors --- */ /* --- querying the descriptors --- */
const ProtobufCEnumValue * const ProtobufCEnumValue *protobuf_c_enum_descriptor_get_value_by_name(
protobuf_c_enum_descriptor_get_value_by_name(const ProtobufCEnumDescriptor *desc, const ProtobufCEnumDescriptor *desc, const char *name) {
const char *name) unsigned start = 0;
{ unsigned count;
unsigned start = 0;
unsigned count; if (desc == NULL || desc->values_by_name == NULL) return NULL;
if (desc == NULL || desc->values_by_name == NULL) count = desc->n_value_names;
return NULL;
while (count > 1) {
count = desc->n_value_names; unsigned mid = start + count / 2;
int rv = strcmp(desc->values_by_name[mid].name, name);
while (count > 1) { if (rv == 0)
unsigned mid = start + count / 2; return desc->values + desc->values_by_name[mid].index;
int rv = strcmp(desc->values_by_name[mid].name, name); else if (rv < 0) {
if (rv == 0) count = start + count - (mid + 1);
return desc->values + desc->values_by_name[mid].index; start = mid + 1;
else if (rv < 0) { } else
count = start + count - (mid + 1); count = mid - start;
start = mid + 1; }
} else if (count == 0) return NULL;
count = mid - start; if (strcmp(desc->values_by_name[start].name, name) == 0)
} return desc->values + desc->values_by_name[start].index;
if (count == 0) return NULL;
return NULL; }
if (strcmp(desc->values_by_name[start].name, name) == 0)
return desc->values + desc->values_by_name[start].index; const ProtobufCEnumValue *protobuf_c_enum_descriptor_get_value(
return NULL; const ProtobufCEnumDescriptor *desc, int value) {
} int rv = int_range_lookup(desc->n_value_ranges, desc->value_ranges, value);
if (rv < 0) return NULL;
const ProtobufCEnumValue * return desc->values + rv;
protobuf_c_enum_descriptor_get_value(const ProtobufCEnumDescriptor *desc, }
int value)
{ const ProtobufCFieldDescriptor *protobuf_c_message_descriptor_get_field_by_name(
int rv = int_range_lookup(desc->n_value_ranges, desc->value_ranges, value); const ProtobufCMessageDescriptor *desc, const char *name) {
if (rv < 0) unsigned start = 0;
return NULL; unsigned count;
return desc->values + rv; const ProtobufCFieldDescriptor *field;
}
if (desc == NULL || desc->fields_sorted_by_name == NULL) return NULL;
const ProtobufCFieldDescriptor *
protobuf_c_message_descriptor_get_field_by_name(const ProtobufCMessageDescriptor *desc, count = desc->n_fields;
const char *name)
{ while (count > 1) {
unsigned start = 0; unsigned mid = start + count / 2;
unsigned count; int rv;
const ProtobufCFieldDescriptor *field; field = desc->fields + desc->fields_sorted_by_name[mid];
rv = strcmp(field->name, name);
if (desc == NULL || desc->fields_sorted_by_name == NULL) if (rv == 0)
return NULL; return field;
else if (rv < 0) {
count = desc->n_fields; count = start + count - (mid + 1);
start = mid + 1;
while (count > 1) { } else
unsigned mid = start + count / 2; count = mid - start;
int rv; }
field = desc->fields + desc->fields_sorted_by_name[mid]; if (count == 0) return NULL;
rv = strcmp(field->name, name); field = desc->fields + desc->fields_sorted_by_name[start];
if (rv == 0) if (strcmp(field->name, name) == 0) return field;
return field; return NULL;
else if (rv < 0) { }
count = start + count - (mid + 1);
start = mid + 1; const ProtobufCFieldDescriptor *protobuf_c_message_descriptor_get_field(
} else const ProtobufCMessageDescriptor *desc, unsigned value) {
count = mid - start; int rv = int_range_lookup(desc->n_field_ranges, desc->field_ranges, value);
} if (rv < 0) return NULL;
if (count == 0) return desc->fields + rv;
return NULL;
field = desc->fields + desc->fields_sorted_by_name[start];
if (strcmp(field->name, name) == 0)
return field;
return NULL;
}
const ProtobufCFieldDescriptor *
protobuf_c_message_descriptor_get_field(const ProtobufCMessageDescriptor *desc,
unsigned value)
{
int rv = int_range_lookup(desc->n_field_ranges,desc->field_ranges, value);
if (rv < 0)
return NULL;
return desc->fields + rv;
} }
const ProtobufCMethodDescriptor * const ProtobufCMethodDescriptor *
protobuf_c_service_descriptor_get_method_by_name(const ProtobufCServiceDescriptor *desc, protobuf_c_service_descriptor_get_method_by_name(
const char *name) const ProtobufCServiceDescriptor *desc, const char *name) {
{ unsigned start = 0;
unsigned start = 0; unsigned count;
unsigned count;
if (desc == NULL || desc->method_indices_by_name == NULL) return NULL;
if (desc == NULL || desc->method_indices_by_name == NULL)
return NULL; count = desc->n_methods;
count = desc->n_methods; while (count > 1) {
unsigned mid = start + count / 2;
while (count > 1) { unsigned mid_index = desc->method_indices_by_name[mid];
unsigned mid = start + count / 2; const char *mid_name = desc->methods[mid_index].name;
unsigned mid_index = desc->method_indices_by_name[mid]; int rv = strcmp(mid_name, name);
const char *mid_name = desc->methods[mid_index].name;
int rv = strcmp(mid_name, name); if (rv == 0) return desc->methods + desc->method_indices_by_name[mid];
if (rv < 0) {
if (rv == 0) count = start + count - (mid + 1);
return desc->methods + desc->method_indices_by_name[mid]; start = mid + 1;
if (rv < 0) { } else {
count = start + count - (mid + 1); count = mid - start;
start = mid + 1; }
} else { }
count = mid - start; if (count == 0) return NULL;
} if (strcmp(desc->methods[desc->method_indices_by_name[start]].name, name) ==
} 0)
if (count == 0) return desc->methods + desc->method_indices_by_name[start];
return NULL; return NULL;
if (strcmp(desc->methods[desc->method_indices_by_name[start]].name, name) == 0)
return desc->methods + desc->method_indices_by_name[start];
return NULL;
} }
...@@ -202,40 +202,40 @@ size_t foo__bar__baz_bah__pack_to_buffer ...@@ -202,40 +202,40 @@ size_t foo__bar__baz_bah__pack_to_buffer
#include <stdint.h> #include <stdint.h>
#ifdef __cplusplus #ifdef __cplusplus
# define PROTOBUF_C__BEGIN_DECLS extern "C" { #define PROTOBUF_C__BEGIN_DECLS extern "C" {
# define PROTOBUF_C__END_DECLS } #define PROTOBUF_C__END_DECLS }
#else #else
# define PROTOBUF_C__BEGIN_DECLS #define PROTOBUF_C__BEGIN_DECLS
# define PROTOBUF_C__END_DECLS #define PROTOBUF_C__END_DECLS
#endif #endif
PROTOBUF_C__BEGIN_DECLS PROTOBUF_C__BEGIN_DECLS
#if defined(_WIN32) && defined(PROTOBUF_C_USE_SHARED_LIB) #if defined(_WIN32) && defined(PROTOBUF_C_USE_SHARED_LIB)
# ifdef PROTOBUF_C_EXPORT #ifdef PROTOBUF_C_EXPORT
# define PROTOBUF_C__API __declspec(dllexport) #define PROTOBUF_C__API __declspec(dllexport)
# else
# define PROTOBUF_C__API __declspec(dllimport)
# endif
#else #else
# define PROTOBUF_C__API #define PROTOBUF_C__API __declspec(dllimport)
#endif
#else
#define PROTOBUF_C__API
#endif #endif
#if !defined(PROTOBUF_C__NO_DEPRECATED) && \ #if !defined(PROTOBUF_C__NO_DEPRECATED) && \
((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
# define PROTOBUF_C__DEPRECATED __attribute__((__deprecated__)) #define PROTOBUF_C__DEPRECATED __attribute__((__deprecated__))
#else #else
# define PROTOBUF_C__DEPRECATED #define PROTOBUF_C__DEPRECATED
#endif #endif
#ifndef PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE #ifndef PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE
#define PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(enum_name) \ #define PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(enum_name) \
, _##enum_name##_IS_INT_SIZE = INT_MAX , _##enum_name##_IS_INT_SIZE = INT_MAX
#endif #endif
#define PROTOBUF_C__SERVICE_DESCRIPTOR_MAGIC 0x14159bc3 #define PROTOBUF_C__SERVICE_DESCRIPTOR_MAGIC 0x14159bc3
#define PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC 0x28aaeef9 #define PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC 0x28aaeef9
#define PROTOBUF_C__ENUM_DESCRIPTOR_MAGIC 0x114315af #define PROTOBUF_C__ENUM_DESCRIPTOR_MAGIC 0x114315af
/* Empty string used for initializers */ /* Empty string used for initializers */
extern const char protobuf_c_empty_string[]; extern const char protobuf_c_empty_string[];
...@@ -253,14 +253,14 @@ extern const char protobuf_c_empty_string[]; ...@@ -253,14 +253,14 @@ extern const char protobuf_c_empty_string[];
* Values for the `flags` word in `ProtobufCFieldDescriptor`. * Values for the `flags` word in `ProtobufCFieldDescriptor`.
*/ */
typedef enum { typedef enum {
/** Set if the field is repeated and marked with the `packed` option. */ /** Set if the field is repeated and marked with the `packed` option. */
PROTOBUF_C_FIELD_FLAG_PACKED = (1 << 0), PROTOBUF_C_FIELD_FLAG_PACKED = (1 << 0),
/** Set if the field is marked with the `deprecated` option. */ /** Set if the field is marked with the `deprecated` option. */
PROTOBUF_C_FIELD_FLAG_DEPRECATED = (1 << 1), PROTOBUF_C_FIELD_FLAG_DEPRECATED = (1 << 1),
/** Set if the field is a member of a oneof (union). */ /** Set if the field is a member of a oneof (union). */
PROTOBUF_C_FIELD_FLAG_ONEOF = (1 << 2), PROTOBUF_C_FIELD_FLAG_ONEOF = (1 << 2),
} ProtobufCFieldFlag; } ProtobufCFieldFlag;
/** /**
...@@ -272,27 +272,27 @@ typedef enum { ...@@ -272,27 +272,27 @@ typedef enum {
* https://developers.google.com/protocol-buffers/docs/proto#simple * https://developers.google.com/protocol-buffers/docs/proto#simple
*/ */
typedef enum { typedef enum {
/** A well-formed message must have exactly one of this field. */ /** A well-formed message must have exactly one of this field. */
PROTOBUF_C_LABEL_REQUIRED, PROTOBUF_C_LABEL_REQUIRED,
/** /**
* A well-formed message can have zero or one of this field (but not * A well-formed message can have zero or one of this field (but not
* more than one). * more than one).
*/ */
PROTOBUF_C_LABEL_OPTIONAL, PROTOBUF_C_LABEL_OPTIONAL,
/** /**
* This field can be repeated any number of times (including zero) in a * This field can be repeated any number of times (including zero) in a
* well-formed message. The order of the repeated values will be * well-formed message. The order of the repeated values will be
* preserved. * preserved.
*/ */
PROTOBUF_C_LABEL_REPEATED, PROTOBUF_C_LABEL_REPEATED,
/** /**
* This field has no label. This is valid only in proto3 and is * This field has no label. This is valid only in proto3 and is
* equivalent to OPTIONAL but no "has" quantifier will be consulted. * equivalent to OPTIONAL but no "has" quantifier will be consulted.
*/ */
PROTOBUF_C_LABEL_NONE, PROTOBUF_C_LABEL_NONE,
} ProtobufCLabel; } ProtobufCLabel;
/** /**
...@@ -304,23 +304,23 @@ typedef enum { ...@@ -304,23 +304,23 @@ typedef enum {
* https://developers.google.com/protocol-buffers/docs/proto#scalar * https://developers.google.com/protocol-buffers/docs/proto#scalar
*/ */
typedef enum { typedef enum {
PROTOBUF_C_TYPE_INT32, /**< int32 */ PROTOBUF_C_TYPE_INT32, /**< int32 */
PROTOBUF_C_TYPE_SINT32, /**< signed int32 */ PROTOBUF_C_TYPE_SINT32, /**< signed int32 */
PROTOBUF_C_TYPE_SFIXED32, /**< signed int32 (4 bytes) */ PROTOBUF_C_TYPE_SFIXED32, /**< signed int32 (4 bytes) */
PROTOBUF_C_TYPE_INT64, /**< int64 */ PROTOBUF_C_TYPE_INT64, /**< int64 */
PROTOBUF_C_TYPE_SINT64, /**< signed int64 */ PROTOBUF_C_TYPE_SINT64, /**< signed int64 */
PROTOBUF_C_TYPE_SFIXED64, /**< signed int64 (8 bytes) */ PROTOBUF_C_TYPE_SFIXED64, /**< signed int64 (8 bytes) */
PROTOBUF_C_TYPE_UINT32, /**< unsigned int32 */ PROTOBUF_C_TYPE_UINT32, /**< unsigned int32 */
PROTOBUF_C_TYPE_FIXED32, /**< unsigned int32 (4 bytes) */ PROTOBUF_C_TYPE_FIXED32, /**< unsigned int32 (4 bytes) */
PROTOBUF_C_TYPE_UINT64, /**< unsigned int64 */ PROTOBUF_C_TYPE_UINT64, /**< unsigned int64 */
PROTOBUF_C_TYPE_FIXED64, /**< unsigned int64 (8 bytes) */ PROTOBUF_C_TYPE_FIXED64, /**< unsigned int64 (8 bytes) */
PROTOBUF_C_TYPE_FLOAT, /**< float */ PROTOBUF_C_TYPE_FLOAT, /**< float */
PROTOBUF_C_TYPE_DOUBLE, /**< double */ PROTOBUF_C_TYPE_DOUBLE, /**< double */
PROTOBUF_C_TYPE_BOOL, /**< boolean */ PROTOBUF_C_TYPE_BOOL, /**< boolean */
PROTOBUF_C_TYPE_ENUM, /**< enumerated type */ PROTOBUF_C_TYPE_ENUM, /**< enumerated type */
PROTOBUF_C_TYPE_STRING, /**< UTF-8 or ASCII string */ PROTOBUF_C_TYPE_STRING, /**< UTF-8 or ASCII string */
PROTOBUF_C_TYPE_BYTES, /**< arbitrary byte sequence */ PROTOBUF_C_TYPE_BYTES, /**< arbitrary byte sequence */
PROTOBUF_C_TYPE_MESSAGE, /**< nested message */ PROTOBUF_C_TYPE_MESSAGE, /**< nested message */
} ProtobufCType; } ProtobufCType;
/** /**
...@@ -332,11 +332,11 @@ typedef enum { ...@@ -332,11 +332,11 @@ typedef enum {
* https://developers.google.com/protocol-buffers/docs/encoding#structure * https://developers.google.com/protocol-buffers/docs/encoding#structure
*/ */
typedef enum { typedef enum {
PROTOBUF_C_WIRE_TYPE_VARINT = 0, PROTOBUF_C_WIRE_TYPE_VARINT = 0,
PROTOBUF_C_WIRE_TYPE_64BIT = 1, PROTOBUF_C_WIRE_TYPE_64BIT = 1,
PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED = 2, PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED = 2,
/* "Start group" and "end group" wire types are unsupported. */ /* "Start group" and "end group" wire types are unsupported. */
PROTOBUF_C_WIRE_TYPE_32BIT = 5, PROTOBUF_C_WIRE_TYPE_32BIT = 5,
} ProtobufCWireType; } ProtobufCWireType;
struct ProtobufCAllocator; struct ProtobufCAllocator;
...@@ -382,14 +382,14 @@ typedef void (*ProtobufCServiceDestroy)(ProtobufCService *); ...@@ -382,14 +382,14 @@ typedef void (*ProtobufCServiceDestroy)(ProtobufCService *);
* Structure for defining a custom memory allocator. * Structure for defining a custom memory allocator.
*/ */
struct ProtobufCAllocator { struct ProtobufCAllocator {
/** Function to allocate memory. */ /** Function to allocate memory. */
void *(*alloc)(void *allocator_data, size_t size); void *(*alloc)(void *allocator_data, size_t size);
/** Function to free memory. */ /** Function to free memory. */
void (*free)(void *allocator_data, void *pointer); void (*free)(void *allocator_data, void *pointer);
/** Opaque pointer passed to `alloc` and `free` functions. */ /** Opaque pointer passed to `alloc` and `free` functions. */
void *allocator_data; void *allocator_data;
}; };
/** /**
...@@ -400,8 +400,8 @@ struct ProtobufCAllocator { ...@@ -400,8 +400,8 @@ struct ProtobufCAllocator {
* `NUL`-terminated. * `NUL`-terminated.
*/ */
struct ProtobufCBinaryData { struct ProtobufCBinaryData {
size_t len; /**< Number of bytes in the `data` field. */ size_t len; /**< Number of bytes in the `data` field. */
uint8_t *data; /**< Data bytes. */ uint8_t *data; /**< Data bytes. */
}; };
/** /**
...@@ -440,10 +440,8 @@ protobuf_c_message_pack_to_buffer(&message, &tmp); ...@@ -440,10 +440,8 @@ protobuf_c_message_pack_to_buffer(&message, &tmp);
~~~ ~~~
*/ */
struct ProtobufCBuffer { struct ProtobufCBuffer {
/** Append function. Consumes the `len` bytes stored at `data`. */ /** Append function. Consumes the `len` bytes stored at `data`. */
void (*append)(ProtobufCBuffer *buffer, void (*append)(ProtobufCBuffer *buffer, size_t len, const uint8_t *data);
size_t len,
const uint8_t *data);
}; };
/** /**
...@@ -475,142 +473,142 @@ PROTOBUF_C_BUFFER_SIMPLE_CLEAR(&simple); ...@@ -475,142 +473,142 @@ PROTOBUF_C_BUFFER_SIMPLE_CLEAR(&simple);
* \see PROTOBUF_C_BUFFER_SIMPLE_CLEAR * \see PROTOBUF_C_BUFFER_SIMPLE_CLEAR
*/ */
struct ProtobufCBufferSimple { struct ProtobufCBufferSimple {
/** "Base class". */ /** "Base class". */
ProtobufCBuffer base; ProtobufCBuffer base;
/** Number of bytes allocated in `data`. */ /** Number of bytes allocated in `data`. */
size_t alloced; size_t alloced;
/** Number of bytes currently stored in `data`. */ /** Number of bytes currently stored in `data`. */
size_t len; size_t len;
/** Data bytes. */ /** Data bytes. */
uint8_t *data; uint8_t *data;
/** Whether `data` must be freed. */ /** Whether `data` must be freed. */
protobuf_c_boolean must_free_data; protobuf_c_boolean must_free_data;
/** Allocator to use. May be NULL to indicate the system allocator. */ /** Allocator to use. May be NULL to indicate the system allocator. */
ProtobufCAllocator *allocator; ProtobufCAllocator *allocator;
}; };
/** /**
* Describes an enumeration as a whole, with all of its values. * Describes an enumeration as a whole, with all of its values.
*/ */
struct ProtobufCEnumDescriptor { struct ProtobufCEnumDescriptor {
/** Magic value checked to ensure that the API is used correctly. */ /** Magic value checked to ensure that the API is used correctly. */
uint32_t magic; uint32_t magic;
/** The qualified name (e.g., "namespace.Type"). */ /** The qualified name (e.g., "namespace.Type"). */
const char *name; const char *name;
/** The unqualified name as given in the .proto file (e.g., "Type"). */ /** The unqualified name as given in the .proto file (e.g., "Type"). */
const char *short_name; const char *short_name;
/** Identifier used in generated C code. */ /** Identifier used in generated C code. */
const char *c_name; const char *c_name;
/** The dot-separated namespace. */ /** The dot-separated namespace. */
const char *package_name; const char *package_name;
/** Number elements in `values`. */ /** Number elements in `values`. */
unsigned n_values; unsigned n_values;
/** Array of distinct values, sorted by numeric value. */ /** Array of distinct values, sorted by numeric value. */
const ProtobufCEnumValue *values; const ProtobufCEnumValue *values;
/** Number of elements in `values_by_name`. */ /** Number of elements in `values_by_name`. */
unsigned n_value_names; unsigned n_value_names;
/** Array of named values, including aliases, sorted by name. */ /** Array of named values, including aliases, sorted by name. */
const ProtobufCEnumValueIndex *values_by_name; const ProtobufCEnumValueIndex *values_by_name;
/** Number of elements in `value_ranges`. */ /** Number of elements in `value_ranges`. */
unsigned n_value_ranges; unsigned n_value_ranges;
/** Value ranges, for faster lookups by numeric value. */ /** Value ranges, for faster lookups by numeric value. */
const ProtobufCIntRange *value_ranges; const ProtobufCIntRange *value_ranges;
/** Reserved for future use. */ /** Reserved for future use. */
void *reserved1; void *reserved1;
/** Reserved for future use. */ /** Reserved for future use. */
void *reserved2; void *reserved2;
/** Reserved for future use. */ /** Reserved for future use. */
void *reserved3; void *reserved3;
/** Reserved for future use. */ /** Reserved for future use. */
void *reserved4; void *reserved4;
}; };
/** /**
* Represents a single value of an enumeration. * Represents a single value of an enumeration.
*/ */
struct ProtobufCEnumValue { struct ProtobufCEnumValue {
/** The string identifying this value in the .proto file. */ /** The string identifying this value in the .proto file. */
const char *name; const char *name;
/** The string identifying this value in generated C code. */ /** The string identifying this value in generated C code. */
const char *c_name; const char *c_name;
/** The numeric value assigned in the .proto file. */ /** The numeric value assigned in the .proto file. */
int value; int value;
}; };
/** /**
* Used by `ProtobufCEnumDescriptor` to look up enum values. * Used by `ProtobufCEnumDescriptor` to look up enum values.
*/ */
struct ProtobufCEnumValueIndex { struct ProtobufCEnumValueIndex {
/** Name of the enum value. */ /** Name of the enum value. */
const char *name; const char *name;
/** Index into values[] array. */ /** Index into values[] array. */
unsigned index; unsigned index;
}; };
/** /**
* Describes a single field in a message. * Describes a single field in a message.
*/ */
struct ProtobufCFieldDescriptor { struct ProtobufCFieldDescriptor {
/** Name of the field as given in the .proto file. */ /** Name of the field as given in the .proto file. */
const char *name; const char *name;
/** Tag value of the field as given in the .proto file. */ /** Tag value of the field as given in the .proto file. */
uint32_t id; uint32_t id;
/** Whether the field is `REQUIRED`, `OPTIONAL`, or `REPEATED`. */ /** Whether the field is `REQUIRED`, `OPTIONAL`, or `REPEATED`. */
ProtobufCLabel label; ProtobufCLabel label;
/** The type of the field. */ /** The type of the field. */
ProtobufCType type; ProtobufCType type;
/** /**
* The offset in bytes of the message's C structure's quantifier field * The offset in bytes of the message's C structure's quantifier field
* (the `has_MEMBER` field for optional members or the `n_MEMBER` field * (the `has_MEMBER` field for optional members or the `n_MEMBER` field
* for repeated members or the case enum for oneofs). * for repeated members or the case enum for oneofs).
*/ */
unsigned quantifier_offset; unsigned quantifier_offset;
/** /**
* The offset in bytes into the message's C structure for the member * The offset in bytes into the message's C structure for the member
* itself. * itself.
*/ */
unsigned offset; unsigned offset;
/** /**
* A type-specific descriptor. * A type-specific descriptor.
* *
* If `type` is `PROTOBUF_C_TYPE_ENUM`, then `descriptor` points to the * If `type` is `PROTOBUF_C_TYPE_ENUM`, then `descriptor` points to the
* corresponding `ProtobufCEnumDescriptor`. * corresponding `ProtobufCEnumDescriptor`.
* *
* If `type` is `PROTOBUF_C_TYPE_MESSAGE`, then `descriptor` points to * If `type` is `PROTOBUF_C_TYPE_MESSAGE`, then `descriptor` points to
* the corresponding `ProtobufCMessageDescriptor`. * the corresponding `ProtobufCMessageDescriptor`.
* *
* Otherwise this field is NULL. * Otherwise this field is NULL.
*/ */
const void *descriptor; /* for MESSAGE and ENUM types */ const void *descriptor; /* for MESSAGE and ENUM types */
/** The default value for this field, if defined. May be NULL. */ /** The default value for this field, if defined. May be NULL. */
const void *default_value; const void *default_value;
/** /**
* A flag word. Zero or more of the bits defined in the * A flag word. Zero or more of the bits defined in the
* `ProtobufCFieldFlag` enum may be set. * `ProtobufCFieldFlag` enum may be set.
*/ */
uint32_t flags; uint32_t flags;
/** Reserved for future use. */ /** Reserved for future use. */
unsigned reserved_flags; unsigned reserved_flags;
/** Reserved for future use. */ /** Reserved for future use. */
void *reserved2; void *reserved2;
/** Reserved for future use. */ /** Reserved for future use. */
void *reserved3; void *reserved3;
}; };
/** /**
...@@ -622,13 +620,13 @@ struct ProtobufCFieldDescriptor { ...@@ -622,13 +620,13 @@ struct ProtobufCFieldDescriptor {
* sorted. * sorted.
*/ */
struct ProtobufCIntRange { struct ProtobufCIntRange {
int start_value; int start_value;
unsigned orig_index; unsigned orig_index;
/* /*
* NOTE: the number of values in the range can be inferred by looking * NOTE: the number of values in the range can be inferred by looking
* at the next element's orig_index. A dummy element is added to make * at the next element's orig_index. A dummy element is added to make
* this simple. * this simple.
*/ */
}; };
/** /**
...@@ -647,122 +645,120 @@ struct ProtobufCIntRange { ...@@ -647,122 +645,120 @@ struct ProtobufCIntRange {
* like protobuf_c_message_free_unpacked(). * like protobuf_c_message_free_unpacked().
*/ */
struct ProtobufCMessage { struct ProtobufCMessage {
/** The descriptor for this message type. */ /** The descriptor for this message type. */
const ProtobufCMessageDescriptor *descriptor; const ProtobufCMessageDescriptor *descriptor;
/** The number of elements in `unknown_fields`. */ /** The number of elements in `unknown_fields`. */
unsigned n_unknown_fields; unsigned n_unknown_fields;
/** The fields that weren't recognized by the parser. */ /** The fields that weren't recognized by the parser. */
ProtobufCMessageUnknownField *unknown_fields; ProtobufCMessageUnknownField *unknown_fields;
}; };
/** /**
* Describes a message. * Describes a message.
*/ */
struct ProtobufCMessageDescriptor { struct ProtobufCMessageDescriptor {
/** Magic value checked to ensure that the API is used correctly. */ /** Magic value checked to ensure that the API is used correctly. */
uint32_t magic; uint32_t magic;
/** The qualified name (e.g., "namespace.Type"). */ /** The qualified name (e.g., "namespace.Type"). */
const char *name; const char *name;
/** The unqualified name as given in the .proto file (e.g., "Type"). */ /** The unqualified name as given in the .proto file (e.g., "Type"). */
const char *short_name; const char *short_name;
/** Identifier used in generated C code. */ /** Identifier used in generated C code. */
const char *c_name; const char *c_name;
/** The dot-separated namespace. */ /** The dot-separated namespace. */
const char *package_name; const char *package_name;
/** /**
* Size in bytes of the C structure representing an instance of this * Size in bytes of the C structure representing an instance of this
* type of message. * type of message.
*/ */
size_t sizeof_message; size_t sizeof_message;
/** Number of elements in `fields`. */ /** Number of elements in `fields`. */
unsigned n_fields; unsigned n_fields;
/** Field descriptors, sorted by tag number. */ /** Field descriptors, sorted by tag number. */
const ProtobufCFieldDescriptor *fields; const ProtobufCFieldDescriptor *fields;
/** Used for looking up fields by name. */ /** Used for looking up fields by name. */
const unsigned *fields_sorted_by_name; const unsigned *fields_sorted_by_name;
/** Number of elements in `field_ranges`. */ /** Number of elements in `field_ranges`. */
unsigned n_field_ranges; unsigned n_field_ranges;
/** Used for looking up fields by id. */ /** Used for looking up fields by id. */
const ProtobufCIntRange *field_ranges; const ProtobufCIntRange *field_ranges;
/** Message initialisation function. */ /** Message initialisation function. */
ProtobufCMessageInit message_init; ProtobufCMessageInit message_init;
/** Reserved for future use. */ /** Reserved for future use. */
void *reserved1; void *reserved1;
/** Reserved for future use. */ /** Reserved for future use. */
void *reserved2; void *reserved2;
/** Reserved for future use. */ /** Reserved for future use. */
void *reserved3; void *reserved3;
}; };
/** /**
* An unknown message field. * An unknown message field.
*/ */
struct ProtobufCMessageUnknownField { struct ProtobufCMessageUnknownField {
/** The tag number. */ /** The tag number. */
uint32_t tag; uint32_t tag;
/** The wire type of the field. */ /** The wire type of the field. */
ProtobufCWireType wire_type; ProtobufCWireType wire_type;
/** Number of bytes in `data`. */ /** Number of bytes in `data`. */
size_t len; size_t len;
/** Field data. */ /** Field data. */
uint8_t *data; uint8_t *data;
}; };
/** /**
* Method descriptor. * Method descriptor.
*/ */
struct ProtobufCMethodDescriptor { struct ProtobufCMethodDescriptor {
/** Method name. */ /** Method name. */
const char *name; const char *name;
/** Input message descriptor. */ /** Input message descriptor. */
const ProtobufCMessageDescriptor *input; const ProtobufCMessageDescriptor *input;
/** Output message descriptor. */ /** Output message descriptor. */
const ProtobufCMessageDescriptor *output; const ProtobufCMessageDescriptor *output;
}; };
/** /**
* Service. * Service.
*/ */
struct ProtobufCService { struct ProtobufCService {
/** Service descriptor. */ /** Service descriptor. */
const ProtobufCServiceDescriptor *descriptor; const ProtobufCServiceDescriptor *descriptor;
/** Function to invoke the service. */ /** Function to invoke the service. */
void (*invoke)(ProtobufCService *service, void (*invoke)(ProtobufCService *service, unsigned method_index,
unsigned method_index, const ProtobufCMessage *input, ProtobufCClosure closure,
const ProtobufCMessage *input, void *closure_data);
ProtobufCClosure closure, /** Function to destroy the service. */
void *closure_data); void (*destroy)(ProtobufCService *service);
/** Function to destroy the service. */
void (*destroy)(ProtobufCService *service);
}; };
/** /**
* Service descriptor. * Service descriptor.
*/ */
struct ProtobufCServiceDescriptor { struct ProtobufCServiceDescriptor {
/** Magic value checked to ensure that the API is used correctly. */ /** Magic value checked to ensure that the API is used correctly. */
uint32_t magic; uint32_t magic;
/** Service name. */ /** Service name. */
const char *name; const char *name;
/** Short version of service name. */ /** Short version of service name. */
const char *short_name; const char *short_name;
/** C identifier for the service name. */ /** C identifier for the service name. */
const char *c_name; const char *c_name;
/** Package name. */ /** Package name. */
const char *package; const char *package;
/** Number of elements in `methods`. */ /** Number of elements in `methods`. */
unsigned n_methods; unsigned n_methods;
/** Method descriptors, in the order defined in the .proto file. */ /** Method descriptors, in the order defined in the .proto file. */
const ProtobufCMethodDescriptor *methods; const ProtobufCMethodDescriptor *methods;
/** Sort index of methods. */ /** Sort index of methods. */
const unsigned *method_indices_by_name; const unsigned *method_indices_by_name;
}; };
/** /**
...@@ -772,8 +768,7 @@ struct ProtobufCServiceDescriptor { ...@@ -772,8 +768,7 @@ struct ProtobufCServiceDescriptor {
* \return A string containing the version number of protobuf-c. * \return A string containing the version number of protobuf-c.
*/ */
PROTOBUF_C__API PROTOBUF_C__API
const char * const char *protobuf_c_version(void);
protobuf_c_version(void);
/** /**
* Get the version of the protobuf-c library. Note that this is the version of * Get the version of the protobuf-c library. Note that this is the version of
...@@ -783,26 +778,25 @@ protobuf_c_version(void); ...@@ -783,26 +778,25 @@ protobuf_c_version(void);
* protobuf-c, represented in base-10 as (MAJOR*1E6) + (MINOR*1E3) + PATCH. * protobuf-c, represented in base-10 as (MAJOR*1E6) + (MINOR*1E3) + PATCH.
*/ */
PROTOBUF_C__API PROTOBUF_C__API
uint32_t uint32_t protobuf_c_version_number(void);
protobuf_c_version_number(void);
/** /**
* The version of the protobuf-c headers, represented as a string using the same * The version of the protobuf-c headers, represented as a string using the same
* format as protobuf_c_version(). * format as protobuf_c_version().
*/ */
#define PROTOBUF_C_VERSION "1.3.0" #define PROTOBUF_C_VERSION "1.3.0"
/** /**
* The version of the protobuf-c headers, represented as an integer using the * The version of the protobuf-c headers, represented as an integer using the
* same format as protobuf_c_version_number(). * same format as protobuf_c_version_number().
*/ */
#define PROTOBUF_C_VERSION_NUMBER 1003000 #define PROTOBUF_C_VERSION_NUMBER 1003000
/** /**
* The minimum protoc-c version which works with the current version of the * The minimum protoc-c version which works with the current version of the
* protobuf-c headers. * protobuf-c headers.
*/ */
#define PROTOBUF_C_MIN_COMPILER_VERSION 1000000 #define PROTOBUF_C_MIN_COMPILER_VERSION 1000000
/** /**
* Look up a `ProtobufCEnumValue` from a `ProtobufCEnumDescriptor` by name. * Look up a `ProtobufCEnumValue` from a `ProtobufCEnumDescriptor` by name.
...@@ -818,10 +812,8 @@ protobuf_c_version_number(void); ...@@ -818,10 +812,8 @@ protobuf_c_version_number(void);
* If not found or if the optimize_for = CODE_SIZE option was set. * If not found or if the optimize_for = CODE_SIZE option was set.
*/ */
PROTOBUF_C__API PROTOBUF_C__API
const ProtobufCEnumValue * const ProtobufCEnumValue *protobuf_c_enum_descriptor_get_value_by_name(
protobuf_c_enum_descriptor_get_value_by_name( const ProtobufCEnumDescriptor *desc, const char *name);
const ProtobufCEnumDescriptor *desc,
const char *name);
/** /**
* Look up a `ProtobufCEnumValue` from a `ProtobufCEnumDescriptor` by numeric * Look up a `ProtobufCEnumValue` from a `ProtobufCEnumDescriptor` by numeric
...@@ -839,10 +831,8 @@ protobuf_c_enum_descriptor_get_value_by_name( ...@@ -839,10 +831,8 @@ protobuf_c_enum_descriptor_get_value_by_name(
* If not found. * If not found.
*/ */
PROTOBUF_C__API PROTOBUF_C__API
const ProtobufCEnumValue * const ProtobufCEnumValue *protobuf_c_enum_descriptor_get_value(
protobuf_c_enum_descriptor_get_value( const ProtobufCEnumDescriptor *desc, int value);
const ProtobufCEnumDescriptor *desc,
int value);
/** /**
* Look up a `ProtobufCFieldDescriptor` from a `ProtobufCMessageDescriptor` by * Look up a `ProtobufCFieldDescriptor` from a `ProtobufCMessageDescriptor` by
...@@ -858,10 +848,8 @@ protobuf_c_enum_descriptor_get_value( ...@@ -858,10 +848,8 @@ protobuf_c_enum_descriptor_get_value(
* If not found or if the optimize_for = CODE_SIZE option was set. * If not found or if the optimize_for = CODE_SIZE option was set.
*/ */
PROTOBUF_C__API PROTOBUF_C__API
const ProtobufCFieldDescriptor * const ProtobufCFieldDescriptor *protobuf_c_message_descriptor_get_field_by_name(
protobuf_c_message_descriptor_get_field_by_name( const ProtobufCMessageDescriptor *desc, const char *name);
const ProtobufCMessageDescriptor *desc,
const char *name);
/** /**
* Look up a `ProtobufCFieldDescriptor` from a `ProtobufCMessageDescriptor` by * Look up a `ProtobufCFieldDescriptor` from a `ProtobufCMessageDescriptor` by
...@@ -877,10 +865,8 @@ protobuf_c_message_descriptor_get_field_by_name( ...@@ -877,10 +865,8 @@ protobuf_c_message_descriptor_get_field_by_name(
* If not found. * If not found.
*/ */
PROTOBUF_C__API PROTOBUF_C__API
const ProtobufCFieldDescriptor * const ProtobufCFieldDescriptor *protobuf_c_message_descriptor_get_field(
protobuf_c_message_descriptor_get_field( const ProtobufCMessageDescriptor *desc, unsigned value);
const ProtobufCMessageDescriptor *desc,
unsigned value);
/** /**
* Determine the number of bytes required to store the serialised message. * Determine the number of bytes required to store the serialised message.
...@@ -891,9 +877,7 @@ protobuf_c_message_descriptor_get_field( ...@@ -891,9 +877,7 @@ protobuf_c_message_descriptor_get_field(
* Number of bytes. * Number of bytes.
*/ */
PROTOBUF_C__API PROTOBUF_C__API
size_t size_t protobuf_c_message_get_packed_size(const ProtobufCMessage *message);
protobuf_c_message_get_packed_size(const ProtobufCMessage *message);
/** /**
* Unpack a serialised message into an in-memory representation. * Unpack a serialised message into an in-memory representation.
...@@ -913,12 +897,9 @@ protobuf_c_message_get_packed_size(const ProtobufCMessage *message); ...@@ -913,12 +897,9 @@ protobuf_c_message_get_packed_size(const ProtobufCMessage *message);
* If an error occurred during unpacking. * If an error occurred during unpacking.
*/ */
PROTOBUF_C__API PROTOBUF_C__API
ProtobufCMessage * ProtobufCMessage *protobuf_c_message_unpack(
protobuf_c_message_unpack( const ProtobufCMessageDescriptor *descriptor, ProtobufCAllocator *allocator,
const ProtobufCMessageDescriptor *descriptor, size_t len, const uint8_t *data);
ProtobufCAllocator *allocator,
size_t len,
const uint8_t *data);
/** /**
* Free an unpacked message object. * Free an unpacked message object.
...@@ -933,10 +914,8 @@ protobuf_c_message_unpack( ...@@ -933,10 +914,8 @@ protobuf_c_message_unpack(
* specify the default allocator. * specify the default allocator.
*/ */
PROTOBUF_C__API PROTOBUF_C__API
void void protobuf_c_message_free_unpacked(ProtobufCMessage *message,
protobuf_c_message_free_unpacked( ProtobufCAllocator *allocator);
ProtobufCMessage *message,
ProtobufCAllocator *allocator);
/** /**
* Check the validity of a message object. * Check the validity of a message object.
...@@ -950,11 +929,11 @@ protobuf_c_message_free_unpacked( ...@@ -950,11 +929,11 @@ protobuf_c_message_free_unpacked(
* Message is invalid. * Message is invalid.
*/ */
PROTOBUF_C__API PROTOBUF_C__API
protobuf_c_boolean protobuf_c_boolean protobuf_c_message_check(const ProtobufCMessage *);
protobuf_c_message_check(const ProtobufCMessage *);
/** Message initialiser. */ /** Message initialiser. */
#define PROTOBUF_C_MESSAGE_INIT(descriptor) { descriptor, 0, NULL } #define PROTOBUF_C_MESSAGE_INIT(descriptor) \
{ descriptor, 0, NULL }
/** /**
* Initialise a message object from a message descriptor. * Initialise a message object from a message descriptor.
...@@ -965,10 +944,8 @@ protobuf_c_message_check(const ProtobufCMessage *); ...@@ -965,10 +944,8 @@ protobuf_c_message_check(const ProtobufCMessage *);
* Allocated block of memory of size `descriptor->sizeof_message`. * Allocated block of memory of size `descriptor->sizeof_message`.
*/ */
PROTOBUF_C__API PROTOBUF_C__API
void void protobuf_c_message_init(const ProtobufCMessageDescriptor *descriptor,
protobuf_c_message_init( void *message);
const ProtobufCMessageDescriptor *descriptor,
void *message);
/** /**
* Free a service. * Free a service.
...@@ -977,8 +954,7 @@ protobuf_c_message_init( ...@@ -977,8 +954,7 @@ protobuf_c_message_init(
* The service object to free. * The service object to free.
*/ */
PROTOBUF_C__API PROTOBUF_C__API
void void protobuf_c_service_destroy(ProtobufCService *service);
protobuf_c_service_destroy(ProtobufCService *service);
/** /**
* Look up a `ProtobufCMethodDescriptor` by name. * Look up a `ProtobufCMethodDescriptor` by name.
...@@ -996,36 +972,29 @@ protobuf_c_service_destroy(ProtobufCService *service); ...@@ -996,36 +972,29 @@ protobuf_c_service_destroy(ProtobufCService *service);
PROTOBUF_C__API PROTOBUF_C__API
const ProtobufCMethodDescriptor * const ProtobufCMethodDescriptor *
protobuf_c_service_descriptor_get_method_by_name( protobuf_c_service_descriptor_get_method_by_name(
const ProtobufCServiceDescriptor *desc, const ProtobufCServiceDescriptor *desc, const char *name);
const char *name);
/** /**
* Initialise a `ProtobufCBufferSimple` object. * Initialise a `ProtobufCBufferSimple` object.
*/ */
#define PROTOBUF_C_BUFFER_SIMPLE_INIT(array_of_bytes) \ #define PROTOBUF_C_BUFFER_SIMPLE_INIT(array_of_bytes) \
{ \ { \
{ protobuf_c_buffer_simple_append }, \ {protobuf_c_buffer_simple_append}, sizeof(array_of_bytes), 0, \
sizeof(array_of_bytes), \ (array_of_bytes), 0, NULL \
0, \ }
(array_of_bytes), \
0, \
NULL \
}
/** /**
* Clear a `ProtobufCBufferSimple` object, freeing any allocated memory. * Clear a `ProtobufCBufferSimple` object, freeing any allocated memory.
*/ */
#define PROTOBUF_C_BUFFER_SIMPLE_CLEAR(simp_buf) \ #define PROTOBUF_C_BUFFER_SIMPLE_CLEAR(simp_buf) \
do { \ do { \
if ((simp_buf)->must_free_data) { \ if ((simp_buf)->must_free_data) { \
if ((simp_buf)->allocator != NULL) \ if ((simp_buf)->allocator != NULL) \
(simp_buf)->allocator->free( \ (simp_buf)->allocator->free((simp_buf)->allocator, (simp_buf)->data); \
(simp_buf)->allocator, \ else \
(simp_buf)->data); \ free((simp_buf)->data); \
else \ } \
free((simp_buf)->data); \ } while (0)
} \
} while (0)
/** /**
* The `append` method for `ProtobufCBufferSimple`. * The `append` method for `ProtobufCBufferSimple`.
...@@ -1039,27 +1008,20 @@ do { \ ...@@ -1039,27 +1008,20 @@ do { \
* Data to append. * Data to append.
*/ */
PROTOBUF_C__API PROTOBUF_C__API
void void protobuf_c_buffer_simple_append(ProtobufCBuffer *buffer, size_t len,
protobuf_c_buffer_simple_append( const unsigned char *data);
ProtobufCBuffer *buffer,
size_t len,
const unsigned char *data);
PROTOBUF_C__API PROTOBUF_C__API
void void protobuf_c_service_generated_init(
protobuf_c_service_generated_init( ProtobufCService *service, const ProtobufCServiceDescriptor *descriptor,
ProtobufCService *service, ProtobufCServiceDestroy destroy);
const ProtobufCServiceDescriptor *descriptor,
ProtobufCServiceDestroy destroy);
PROTOBUF_C__API PROTOBUF_C__API
void void protobuf_c_service_invoke_internal(ProtobufCService *service,
protobuf_c_service_invoke_internal( unsigned method_index,
ProtobufCService *service, const ProtobufCMessage *input,
unsigned method_index, ProtobufCClosure closure,
const ProtobufCMessage *input, void *closure_data);
ProtobufCClosure closure,
void *closure_data);
/**@}*/ /**@}*/
......
...@@ -16,8 +16,8 @@ limitations under the License. */ ...@@ -16,8 +16,8 @@ limitations under the License. */
#include <map> #include <map>
#include <string> #include <string>
#include <vector>
#include <unordered_set> #include <unordered_set>
#include <vector>
#include "framework/attribute.h" #include "framework/attribute.h"
#include "framework/scope.h" #include "framework/scope.h"
......
...@@ -15,8 +15,8 @@ limitations under the License. */ ...@@ -15,8 +15,8 @@ limitations under the License. */
#pragma once #pragma once
#include <unordered_map> #include <unordered_map>
#include "common/log.h"
#include "common/enforce.h" #include "common/enforce.h"
#include "common/log.h"
#include "common/variant.h" #include "common/variant.h"
#include "framework/framework.pb-c.h" #include "framework/framework.pb-c.h"
...@@ -27,7 +27,6 @@ class BlockDesc; ...@@ -27,7 +27,6 @@ class BlockDesc;
class Attribute { class Attribute {
public: public:
/* /*
* PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__INT = 0, * PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__INT = 0,
PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__FLOAT = 1, PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__FLOAT = 1,
...@@ -42,7 +41,8 @@ class Attribute { ...@@ -42,7 +41,8 @@ class Attribute {
PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE) PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE)
* *
* */ * */
static Attribute GetAttrValue(PaddleMobile__Framework__Proto__OpDesc__Attr *attr_desc) { static Attribute GetAttrValue(
PaddleMobile__Framework__Proto__OpDesc__Attr *attr_desc) {
// std::cout << "begin get attr value" << std::endl; // std::cout << "begin get attr value" << std::endl;
Attribute attr; Attribute attr;
switch (attr_desc->type) { switch (attr_desc->type) {
......
...@@ -7,1537 +7,1397 @@ ...@@ -7,1537 +7,1397 @@
#endif #endif
#include "framework.pb-c.h" #include "framework.pb-c.h"
void paddle_mobile__framework__proto__op_desc__attr__init void paddle_mobile__framework__proto__op_desc__attr__init(
(PaddleMobile__Framework__Proto__OpDesc__Attr *message) PaddleMobile__Framework__Proto__OpDesc__Attr *message) {
{ static const PaddleMobile__Framework__Proto__OpDesc__Attr init_value =
static const PaddleMobile__Framework__Proto__OpDesc__Attr init_value = PADDLE_MOBILE__FRAMEWORK__PROTO__OP_DESC__ATTR__INIT; PADDLE_MOBILE__FRAMEWORK__PROTO__OP_DESC__ATTR__INIT;
*message = init_value; *message = init_value;
} }
void paddle_mobile__framework__proto__op_desc__var__init void paddle_mobile__framework__proto__op_desc__var__init(
(PaddleMobile__Framework__Proto__OpDesc__Var *message) PaddleMobile__Framework__Proto__OpDesc__Var *message) {
{ static const PaddleMobile__Framework__Proto__OpDesc__Var init_value =
static const PaddleMobile__Framework__Proto__OpDesc__Var init_value = PADDLE_MOBILE__FRAMEWORK__PROTO__OP_DESC__VAR__INIT; PADDLE_MOBILE__FRAMEWORK__PROTO__OP_DESC__VAR__INIT;
*message = init_value; *message = init_value;
} }
void paddle_mobile__framework__proto__op_desc__init void paddle_mobile__framework__proto__op_desc__init(
(PaddleMobile__Framework__Proto__OpDesc *message) PaddleMobile__Framework__Proto__OpDesc *message) {
{ static const PaddleMobile__Framework__Proto__OpDesc init_value =
static const PaddleMobile__Framework__Proto__OpDesc init_value = PADDLE_MOBILE__FRAMEWORK__PROTO__OP_DESC__INIT; PADDLE_MOBILE__FRAMEWORK__PROTO__OP_DESC__INIT;
*message = init_value; *message = init_value;
} }
size_t paddle_mobile__framework__proto__op_desc__get_packed_size size_t paddle_mobile__framework__proto__op_desc__get_packed_size(
(const PaddleMobile__Framework__Proto__OpDesc *message) const PaddleMobile__Framework__Proto__OpDesc *message) {
{ assert(message->base.descriptor ==
assert(message->base.descriptor == &paddle_mobile__framework__proto__op_desc__descriptor); &paddle_mobile__framework__proto__op_desc__descriptor);
return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); return protobuf_c_message_get_packed_size(
(const ProtobufCMessage *)(message));
} }
PaddleMobile__Framework__Proto__OpDesc * PaddleMobile__Framework__Proto__OpDesc *
paddle_mobile__framework__proto__op_desc__unpack paddle_mobile__framework__proto__op_desc__unpack(ProtobufCAllocator *allocator,
(ProtobufCAllocator *allocator, size_t len,
size_t len, const uint8_t *data) {
const uint8_t *data) return (PaddleMobile__Framework__Proto__OpDesc *)protobuf_c_message_unpack(
{ &paddle_mobile__framework__proto__op_desc__descriptor, allocator, len,
return (PaddleMobile__Framework__Proto__OpDesc *) data);
protobuf_c_message_unpack (&paddle_mobile__framework__proto__op_desc__descriptor,
allocator, len, data);
} }
void paddle_mobile__framework__proto__op_desc__free_unpacked void paddle_mobile__framework__proto__op_desc__free_unpacked(
(PaddleMobile__Framework__Proto__OpDesc *message, PaddleMobile__Framework__Proto__OpDesc *message,
ProtobufCAllocator *allocator) ProtobufCAllocator *allocator) {
{ if (!message) return;
if(!message) assert(message->base.descriptor ==
return; &paddle_mobile__framework__proto__op_desc__descriptor);
assert(message->base.descriptor == &paddle_mobile__framework__proto__op_desc__descriptor); protobuf_c_message_free_unpacked((ProtobufCMessage *)message, allocator);
protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
} }
void paddle_mobile__framework__proto__op_proto__var__init void paddle_mobile__framework__proto__op_proto__var__init(
(PaddleMobile__Framework__Proto__OpProto__Var *message) PaddleMobile__Framework__Proto__OpProto__Var *message) {
{ static const PaddleMobile__Framework__Proto__OpProto__Var init_value =
static const PaddleMobile__Framework__Proto__OpProto__Var init_value = PADDLE_MOBILE__FRAMEWORK__PROTO__OP_PROTO__VAR__INIT; PADDLE_MOBILE__FRAMEWORK__PROTO__OP_PROTO__VAR__INIT;
*message = init_value; *message = init_value;
} }
void paddle_mobile__framework__proto__op_proto__attr__init void paddle_mobile__framework__proto__op_proto__attr__init(
(PaddleMobile__Framework__Proto__OpProto__Attr *message) PaddleMobile__Framework__Proto__OpProto__Attr *message) {
{ static const PaddleMobile__Framework__Proto__OpProto__Attr init_value =
static const PaddleMobile__Framework__Proto__OpProto__Attr init_value = PADDLE_MOBILE__FRAMEWORK__PROTO__OP_PROTO__ATTR__INIT; PADDLE_MOBILE__FRAMEWORK__PROTO__OP_PROTO__ATTR__INIT;
*message = init_value; *message = init_value;
} }
void paddle_mobile__framework__proto__op_proto__init void paddle_mobile__framework__proto__op_proto__init(
(PaddleMobile__Framework__Proto__OpProto *message) PaddleMobile__Framework__Proto__OpProto *message) {
{ static const PaddleMobile__Framework__Proto__OpProto init_value =
static const PaddleMobile__Framework__Proto__OpProto init_value = PADDLE_MOBILE__FRAMEWORK__PROTO__OP_PROTO__INIT; PADDLE_MOBILE__FRAMEWORK__PROTO__OP_PROTO__INIT;
*message = init_value; *message = init_value;
} }
size_t paddle_mobile__framework__proto__op_proto__get_packed_size size_t paddle_mobile__framework__proto__op_proto__get_packed_size(
(const PaddleMobile__Framework__Proto__OpProto *message) const PaddleMobile__Framework__Proto__OpProto *message) {
{ assert(message->base.descriptor ==
assert(message->base.descriptor == &paddle_mobile__framework__proto__op_proto__descriptor); &paddle_mobile__framework__proto__op_proto__descriptor);
return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); return protobuf_c_message_get_packed_size(
(const ProtobufCMessage *)(message));
} }
PaddleMobile__Framework__Proto__OpProto * PaddleMobile__Framework__Proto__OpProto *
paddle_mobile__framework__proto__op_proto__unpack paddle_mobile__framework__proto__op_proto__unpack(ProtobufCAllocator *allocator,
(ProtobufCAllocator *allocator, size_t len,
size_t len, const uint8_t *data) {
const uint8_t *data) return (PaddleMobile__Framework__Proto__OpProto *)protobuf_c_message_unpack(
{ &paddle_mobile__framework__proto__op_proto__descriptor, allocator, len,
return (PaddleMobile__Framework__Proto__OpProto *) data);
protobuf_c_message_unpack (&paddle_mobile__framework__proto__op_proto__descriptor,
allocator, len, data);
} }
void paddle_mobile__framework__proto__op_proto__free_unpacked void paddle_mobile__framework__proto__op_proto__free_unpacked(
(PaddleMobile__Framework__Proto__OpProto *message, PaddleMobile__Framework__Proto__OpProto *message,
ProtobufCAllocator *allocator) ProtobufCAllocator *allocator) {
{ if (!message) return;
if(!message) assert(message->base.descriptor ==
return; &paddle_mobile__framework__proto__op_proto__descriptor);
assert(message->base.descriptor == &paddle_mobile__framework__proto__op_proto__descriptor); protobuf_c_message_free_unpacked((ProtobufCMessage *)message, allocator);
protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
} }
void paddle_mobile__framework__proto__var_type__tensor_desc__init void paddle_mobile__framework__proto__var_type__tensor_desc__init(
(PaddleMobile__Framework__Proto__VarType__TensorDesc *message) PaddleMobile__Framework__Proto__VarType__TensorDesc *message) {
{ static const PaddleMobile__Framework__Proto__VarType__TensorDesc init_value =
static const PaddleMobile__Framework__Proto__VarType__TensorDesc init_value = PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TENSOR_DESC__INIT; PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TENSOR_DESC__INIT;
*message = init_value; *message = init_value;
} }
void paddle_mobile__framework__proto__var_type__lo_dtensor_desc__init void paddle_mobile__framework__proto__var_type__lo_dtensor_desc__init(
(PaddleMobile__Framework__Proto__VarType__LoDTensorDesc *message) PaddleMobile__Framework__Proto__VarType__LoDTensorDesc *message) {
{ static const PaddleMobile__Framework__Proto__VarType__LoDTensorDesc
static const PaddleMobile__Framework__Proto__VarType__LoDTensorDesc init_value = PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__LO_DTENSOR_DESC__INIT; init_value =
PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__LO_DTENSOR_DESC__INIT;
*message = init_value; *message = init_value;
} }
void paddle_mobile__framework__proto__var_type__lo_dtensor_array_desc__init void paddle_mobile__framework__proto__var_type__lo_dtensor_array_desc__init(
(PaddleMobile__Framework__Proto__VarType__LoDTensorArrayDesc *message) PaddleMobile__Framework__Proto__VarType__LoDTensorArrayDesc *message) {
{ static const PaddleMobile__Framework__Proto__VarType__LoDTensorArrayDesc
static const PaddleMobile__Framework__Proto__VarType__LoDTensorArrayDesc init_value = PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__LO_DTENSOR_ARRAY_DESC__INIT; init_value =
PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__LO_DTENSOR_ARRAY_DESC__INIT;
*message = init_value; *message = init_value;
} }
void paddle_mobile__framework__proto__var_type__reader_desc__init void paddle_mobile__framework__proto__var_type__reader_desc__init(
(PaddleMobile__Framework__Proto__VarType__ReaderDesc *message) PaddleMobile__Framework__Proto__VarType__ReaderDesc *message) {
{ static const PaddleMobile__Framework__Proto__VarType__ReaderDesc init_value =
static const PaddleMobile__Framework__Proto__VarType__ReaderDesc init_value = PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__READER_DESC__INIT; PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__READER_DESC__INIT;
*message = init_value; *message = init_value;
} }
void paddle_mobile__framework__proto__var_type__channel_desc__init void paddle_mobile__framework__proto__var_type__channel_desc__init(
(PaddleMobile__Framework__Proto__VarType__ChannelDesc *message) PaddleMobile__Framework__Proto__VarType__ChannelDesc *message) {
{ static const PaddleMobile__Framework__Proto__VarType__ChannelDesc init_value =
static const PaddleMobile__Framework__Proto__VarType__ChannelDesc init_value = PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__CHANNEL_DESC__INIT; PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__CHANNEL_DESC__INIT;
*message = init_value; *message = init_value;
} }
void paddle_mobile__framework__proto__var_type__tuple__init void paddle_mobile__framework__proto__var_type__tuple__init(
(PaddleMobile__Framework__Proto__VarType__Tuple *message) PaddleMobile__Framework__Proto__VarType__Tuple *message) {
{ static const PaddleMobile__Framework__Proto__VarType__Tuple init_value =
static const PaddleMobile__Framework__Proto__VarType__Tuple init_value = PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TUPLE__INIT; PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TUPLE__INIT;
*message = init_value; *message = init_value;
} }
void paddle_mobile__framework__proto__var_type__init void paddle_mobile__framework__proto__var_type__init(
(PaddleMobile__Framework__Proto__VarType *message) PaddleMobile__Framework__Proto__VarType *message) {
{ static const PaddleMobile__Framework__Proto__VarType init_value =
static const PaddleMobile__Framework__Proto__VarType init_value = PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__INIT; PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__INIT;
*message = init_value; *message = init_value;
} }
size_t paddle_mobile__framework__proto__var_type__get_packed_size size_t paddle_mobile__framework__proto__var_type__get_packed_size(
(const PaddleMobile__Framework__Proto__VarType *message) const PaddleMobile__Framework__Proto__VarType *message) {
{ assert(message->base.descriptor ==
assert(message->base.descriptor == &paddle_mobile__framework__proto__var_type__descriptor); &paddle_mobile__framework__proto__var_type__descriptor);
return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); return protobuf_c_message_get_packed_size(
(const ProtobufCMessage *)(message));
} }
PaddleMobile__Framework__Proto__VarType * PaddleMobile__Framework__Proto__VarType *
paddle_mobile__framework__proto__var_type__unpack paddle_mobile__framework__proto__var_type__unpack(ProtobufCAllocator *allocator,
(ProtobufCAllocator *allocator, size_t len,
size_t len, const uint8_t *data) {
const uint8_t *data) return (PaddleMobile__Framework__Proto__VarType *)protobuf_c_message_unpack(
{ &paddle_mobile__framework__proto__var_type__descriptor, allocator, len,
return (PaddleMobile__Framework__Proto__VarType *) data);
protobuf_c_message_unpack (&paddle_mobile__framework__proto__var_type__descriptor,
allocator, len, data);
} }
void paddle_mobile__framework__proto__var_type__free_unpacked void paddle_mobile__framework__proto__var_type__free_unpacked(
(PaddleMobile__Framework__Proto__VarType *message, PaddleMobile__Framework__Proto__VarType *message,
ProtobufCAllocator *allocator) ProtobufCAllocator *allocator) {
{ if (!message) return;
if(!message) assert(message->base.descriptor ==
return; &paddle_mobile__framework__proto__var_type__descriptor);
assert(message->base.descriptor == &paddle_mobile__framework__proto__var_type__descriptor); protobuf_c_message_free_unpacked((ProtobufCMessage *)message, allocator);
protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
} }
void paddle_mobile__framework__proto__var_desc__init void paddle_mobile__framework__proto__var_desc__init(
(PaddleMobile__Framework__Proto__VarDesc *message) PaddleMobile__Framework__Proto__VarDesc *message) {
{ static const PaddleMobile__Framework__Proto__VarDesc init_value =
static const PaddleMobile__Framework__Proto__VarDesc init_value = PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_DESC__INIT; PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_DESC__INIT;
*message = init_value; *message = init_value;
} }
size_t paddle_mobile__framework__proto__var_desc__get_packed_size size_t paddle_mobile__framework__proto__var_desc__get_packed_size(
(const PaddleMobile__Framework__Proto__VarDesc *message) const PaddleMobile__Framework__Proto__VarDesc *message) {
{ assert(message->base.descriptor ==
assert(message->base.descriptor == &paddle_mobile__framework__proto__var_desc__descriptor); &paddle_mobile__framework__proto__var_desc__descriptor);
return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); return protobuf_c_message_get_packed_size(
(const ProtobufCMessage *)(message));
} }
PaddleMobile__Framework__Proto__VarDesc * PaddleMobile__Framework__Proto__VarDesc *
paddle_mobile__framework__proto__var_desc__unpack paddle_mobile__framework__proto__var_desc__unpack(ProtobufCAllocator *allocator,
(ProtobufCAllocator *allocator, size_t len,
size_t len, const uint8_t *data) {
const uint8_t *data) return (PaddleMobile__Framework__Proto__VarDesc *)protobuf_c_message_unpack(
{ &paddle_mobile__framework__proto__var_desc__descriptor, allocator, len,
return (PaddleMobile__Framework__Proto__VarDesc *) data);
protobuf_c_message_unpack (&paddle_mobile__framework__proto__var_desc__descriptor,
allocator, len, data);
} }
void paddle_mobile__framework__proto__var_desc__free_unpacked void paddle_mobile__framework__proto__var_desc__free_unpacked(
(PaddleMobile__Framework__Proto__VarDesc *message, PaddleMobile__Framework__Proto__VarDesc *message,
ProtobufCAllocator *allocator) ProtobufCAllocator *allocator) {
{ if (!message) return;
if(!message) assert(message->base.descriptor ==
return; &paddle_mobile__framework__proto__var_desc__descriptor);
assert(message->base.descriptor == &paddle_mobile__framework__proto__var_desc__descriptor); protobuf_c_message_free_unpacked((ProtobufCMessage *)message, allocator);
protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
} }
void paddle_mobile__framework__proto__block_desc__init void paddle_mobile__framework__proto__block_desc__init(
(PaddleMobile__Framework__Proto__BlockDesc *message) PaddleMobile__Framework__Proto__BlockDesc *message) {
{ static const PaddleMobile__Framework__Proto__BlockDesc init_value =
static const PaddleMobile__Framework__Proto__BlockDesc init_value = PADDLE_MOBILE__FRAMEWORK__PROTO__BLOCK_DESC__INIT; PADDLE_MOBILE__FRAMEWORK__PROTO__BLOCK_DESC__INIT;
*message = init_value; *message = init_value;
} }
size_t paddle_mobile__framework__proto__block_desc__get_packed_size size_t paddle_mobile__framework__proto__block_desc__get_packed_size(
(const PaddleMobile__Framework__Proto__BlockDesc *message) const PaddleMobile__Framework__Proto__BlockDesc *message) {
{ assert(message->base.descriptor ==
assert(message->base.descriptor == &paddle_mobile__framework__proto__block_desc__descriptor); &paddle_mobile__framework__proto__block_desc__descriptor);
return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); return protobuf_c_message_get_packed_size(
(const ProtobufCMessage *)(message));
} }
PaddleMobile__Framework__Proto__BlockDesc * PaddleMobile__Framework__Proto__BlockDesc *
paddle_mobile__framework__proto__block_desc__unpack paddle_mobile__framework__proto__block_desc__unpack(
(ProtobufCAllocator *allocator, ProtobufCAllocator *allocator, size_t len, const uint8_t *data) {
size_t len, return (PaddleMobile__Framework__Proto__BlockDesc *)protobuf_c_message_unpack(
const uint8_t *data) &paddle_mobile__framework__proto__block_desc__descriptor, allocator, len,
{ data);
return (PaddleMobile__Framework__Proto__BlockDesc *)
protobuf_c_message_unpack (&paddle_mobile__framework__proto__block_desc__descriptor,
allocator, len, data);
} }
void paddle_mobile__framework__proto__block_desc__free_unpacked void paddle_mobile__framework__proto__block_desc__free_unpacked(
(PaddleMobile__Framework__Proto__BlockDesc *message, PaddleMobile__Framework__Proto__BlockDesc *message,
ProtobufCAllocator *allocator) ProtobufCAllocator *allocator) {
{ if (!message) return;
if(!message) assert(message->base.descriptor ==
return; &paddle_mobile__framework__proto__block_desc__descriptor);
assert(message->base.descriptor == &paddle_mobile__framework__proto__block_desc__descriptor); protobuf_c_message_free_unpacked((ProtobufCMessage *)message, allocator);
protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
} }
void paddle_mobile__framework__proto__program_desc__init void paddle_mobile__framework__proto__program_desc__init(
(PaddleMobile__Framework__Proto__ProgramDesc *message) PaddleMobile__Framework__Proto__ProgramDesc *message) {
{ static const PaddleMobile__Framework__Proto__ProgramDesc init_value =
static const PaddleMobile__Framework__Proto__ProgramDesc init_value = PADDLE_MOBILE__FRAMEWORK__PROTO__PROGRAM_DESC__INIT; PADDLE_MOBILE__FRAMEWORK__PROTO__PROGRAM_DESC__INIT;
*message = init_value; *message = init_value;
} }
size_t paddle_mobile__framework__proto__program_desc__get_packed_size size_t paddle_mobile__framework__proto__program_desc__get_packed_size(
(const PaddleMobile__Framework__Proto__ProgramDesc *message) const PaddleMobile__Framework__Proto__ProgramDesc *message) {
{ assert(message->base.descriptor ==
assert(message->base.descriptor == &paddle_mobile__framework__proto__program_desc__descriptor); &paddle_mobile__framework__proto__program_desc__descriptor);
return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); return protobuf_c_message_get_packed_size(
(const ProtobufCMessage *)(message));
} }
PaddleMobile__Framework__Proto__ProgramDesc * PaddleMobile__Framework__Proto__ProgramDesc *
paddle_mobile__framework__proto__program_desc__unpack paddle_mobile__framework__proto__program_desc__unpack(
(ProtobufCAllocator *allocator, ProtobufCAllocator *allocator, size_t len, const uint8_t *data) {
size_t len,
const uint8_t *data)
{
return (PaddleMobile__Framework__Proto__ProgramDesc *) return (PaddleMobile__Framework__Proto__ProgramDesc *)
protobuf_c_message_unpack (&paddle_mobile__framework__proto__program_desc__descriptor, protobuf_c_message_unpack(
allocator, len, data); &paddle_mobile__framework__proto__program_desc__descriptor, allocator,
len, data);
} }
void paddle_mobile__framework__proto__program_desc__free_unpacked void paddle_mobile__framework__proto__program_desc__free_unpacked(
(PaddleMobile__Framework__Proto__ProgramDesc *message, PaddleMobile__Framework__Proto__ProgramDesc *message,
ProtobufCAllocator *allocator) ProtobufCAllocator *allocator) {
{ if (!message) return;
if(!message) assert(message->base.descriptor ==
return; &paddle_mobile__framework__proto__program_desc__descriptor);
assert(message->base.descriptor == &paddle_mobile__framework__proto__program_desc__descriptor); protobuf_c_message_free_unpacked((ProtobufCMessage *)message, allocator);
protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
} }
static const ProtobufCFieldDescriptor paddle_mobile__framework__proto__op_desc__attr__field_descriptors[12] = static const ProtobufCFieldDescriptor
{ paddle_mobile__framework__proto__op_desc__attr__field_descriptors[12] = {
{ {
"name", "name", 1, PROTOBUF_C_LABEL_REQUIRED, PROTOBUF_C_TYPE_STRING,
1, 0, /* quantifier_offset */
PROTOBUF_C_LABEL_REQUIRED, offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, name), NULL,
PROTOBUF_C_TYPE_STRING, NULL, 0, /* flags */
0, /* quantifier_offset */ 0, NULL, NULL /* reserved1,reserved2, etc */
offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, name), },
NULL, {
NULL, "type", 2, PROTOBUF_C_LABEL_REQUIRED, PROTOBUF_C_TYPE_ENUM,
0, /* flags */ 0, /* quantifier_offset */
0,NULL,NULL /* reserved1,reserved2, etc */ offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, type),
}, &paddle_mobile__framework__proto__attr_type__descriptor, NULL,
{ 0, /* flags */
"type", 0, NULL, NULL /* reserved1,reserved2, etc */
2, },
PROTOBUF_C_LABEL_REQUIRED, {
PROTOBUF_C_TYPE_ENUM, "i", 3, PROTOBUF_C_LABEL_OPTIONAL, PROTOBUF_C_TYPE_INT32,
0, /* quantifier_offset */ offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, has_i),
offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, type), offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, i), NULL,
&paddle_mobile__framework__proto__attr_type__descriptor, NULL, 0, /* flags */
NULL, 0, NULL, NULL /* reserved1,reserved2, etc */
0, /* flags */ },
0,NULL,NULL /* reserved1,reserved2, etc */ {
}, "f", 4, PROTOBUF_C_LABEL_OPTIONAL, PROTOBUF_C_TYPE_FLOAT,
{ offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, has_f),
"i", offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, f), NULL,
3, NULL, 0, /* flags */
PROTOBUF_C_LABEL_OPTIONAL, 0, NULL, NULL /* reserved1,reserved2, etc */
PROTOBUF_C_TYPE_INT32, },
offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, has_i), {
offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, i), "s", 5, PROTOBUF_C_LABEL_OPTIONAL, PROTOBUF_C_TYPE_STRING,
NULL, 0, /* quantifier_offset */
NULL, offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, s), NULL,
0, /* flags */ NULL, 0, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */ 0, NULL, NULL /* reserved1,reserved2, etc */
}, },
{ {
"f", "ints", 6, PROTOBUF_C_LABEL_REPEATED, PROTOBUF_C_TYPE_INT32,
4, offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, n_ints),
PROTOBUF_C_LABEL_OPTIONAL, offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, ints), NULL,
PROTOBUF_C_TYPE_FLOAT, NULL, 0, /* flags */
offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, has_f), 0, NULL, NULL /* reserved1,reserved2, etc */
offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, f), },
NULL, {
NULL, "floats", 7, PROTOBUF_C_LABEL_REPEATED, PROTOBUF_C_TYPE_FLOAT,
0, /* flags */ offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, n_floats),
0,NULL,NULL /* reserved1,reserved2, etc */ offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, floats),
}, NULL, NULL, 0, /* flags */
{ 0, NULL, NULL /* reserved1,reserved2, etc */
"s", },
5, {
PROTOBUF_C_LABEL_OPTIONAL, "strings", 8, PROTOBUF_C_LABEL_REPEATED, PROTOBUF_C_TYPE_STRING,
PROTOBUF_C_TYPE_STRING, offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, n_strings),
0, /* quantifier_offset */ offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, strings),
offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, s), NULL, NULL, 0, /* flags */
NULL, 0, NULL, NULL /* reserved1,reserved2, etc */
NULL, },
0, /* flags */ {
0,NULL,NULL /* reserved1,reserved2, etc */ "b", 10, PROTOBUF_C_LABEL_OPTIONAL, PROTOBUF_C_TYPE_BOOL,
}, offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, has_b),
{ offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, b), NULL,
"ints", NULL, 0, /* flags */
6, 0, NULL, NULL /* reserved1,reserved2, etc */
PROTOBUF_C_LABEL_REPEATED, },
PROTOBUF_C_TYPE_INT32, {
offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, n_ints), "bools", 11, PROTOBUF_C_LABEL_REPEATED, PROTOBUF_C_TYPE_BOOL,
offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, ints), offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, n_bools),
NULL, offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, bools), NULL,
NULL, NULL, 0, /* flags */
0, /* flags */ 0, NULL, NULL /* reserved1,reserved2, etc */
0,NULL,NULL /* reserved1,reserved2, etc */ },
}, {
{ "block_idx", 12, PROTOBUF_C_LABEL_OPTIONAL, PROTOBUF_C_TYPE_INT32,
"floats", offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr,
7, has_block_idx),
PROTOBUF_C_LABEL_REPEATED, offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, block_idx),
PROTOBUF_C_TYPE_FLOAT, NULL, NULL, 0, /* flags */
offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, n_floats), 0, NULL, NULL /* reserved1,reserved2, etc */
offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, floats), },
NULL, {
NULL, "l", 13, PROTOBUF_C_LABEL_OPTIONAL, PROTOBUF_C_TYPE_INT64,
0, /* flags */ offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, has_l),
0,NULL,NULL /* reserved1,reserved2, etc */ offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, l), NULL,
}, NULL, 0, /* flags */
{ 0, NULL, NULL /* reserved1,reserved2, etc */
"strings", },
8, };
PROTOBUF_C_LABEL_REPEATED, static const unsigned
PROTOBUF_C_TYPE_STRING, paddle_mobile__framework__proto__op_desc__attr__field_indices_by_name[] = {
offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, n_strings), 8, /* field[8] = b */
offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, strings), 10, /* field[10] = block_idx */
NULL, 9, /* field[9] = bools */
NULL, 3, /* field[3] = f */
0, /* flags */ 6, /* field[6] = floats */
0,NULL,NULL /* reserved1,reserved2, etc */ 2, /* field[2] = i */
}, 5, /* field[5] = ints */
{ 11, /* field[11] = l */
"b", 0, /* field[0] = name */
10, 4, /* field[4] = s */
PROTOBUF_C_LABEL_OPTIONAL, 7, /* field[7] = strings */
PROTOBUF_C_TYPE_BOOL, 1, /* field[1] = type */
offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, has_b), };
offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, b), static const ProtobufCIntRange
NULL, paddle_mobile__framework__proto__op_desc__attr__number_ranges[2 + 1] = {
NULL, {1, 0}, {10, 8}, {0, 12}};
0, /* flags */ const ProtobufCMessageDescriptor
0,NULL,NULL /* reserved1,reserved2, etc */ paddle_mobile__framework__proto__op_desc__attr__descriptor = {
}, PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
{ "paddle_mobile.framework.proto.OpDesc.Attr",
"bools", "Attr",
11, "PaddleMobile__Framework__Proto__OpDesc__Attr",
PROTOBUF_C_LABEL_REPEATED, "paddle_mobile.framework.proto",
PROTOBUF_C_TYPE_BOOL, sizeof(PaddleMobile__Framework__Proto__OpDesc__Attr),
offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, n_bools), 12,
offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, bools), paddle_mobile__framework__proto__op_desc__attr__field_descriptors,
NULL, paddle_mobile__framework__proto__op_desc__attr__field_indices_by_name,
NULL, 2,
0, /* flags */ paddle_mobile__framework__proto__op_desc__attr__number_ranges,
0,NULL,NULL /* reserved1,reserved2, etc */ (ProtobufCMessageInit)
}, paddle_mobile__framework__proto__op_desc__attr__init,
{ NULL,
"block_idx", NULL,
12, NULL /* reserved[123] */
PROTOBUF_C_LABEL_OPTIONAL, };
PROTOBUF_C_TYPE_INT32, static const ProtobufCFieldDescriptor
offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, has_block_idx), paddle_mobile__framework__proto__op_desc__var__field_descriptors[2] = {
offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, block_idx), {
NULL, "parameter", 1, PROTOBUF_C_LABEL_REQUIRED, PROTOBUF_C_TYPE_STRING,
NULL, 0, /* quantifier_offset */
0, /* flags */ offsetof(PaddleMobile__Framework__Proto__OpDesc__Var, parameter),
0,NULL,NULL /* reserved1,reserved2, etc */ NULL, NULL, 0, /* flags */
}, 0, NULL, NULL /* reserved1,reserved2, etc */
{ },
"l", {
13, "arguments", 2, PROTOBUF_C_LABEL_REPEATED, PROTOBUF_C_TYPE_STRING,
PROTOBUF_C_LABEL_OPTIONAL, offsetof(PaddleMobile__Framework__Proto__OpDesc__Var, n_arguments),
PROTOBUF_C_TYPE_INT64, offsetof(PaddleMobile__Framework__Proto__OpDesc__Var, arguments),
offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, has_l), NULL, NULL, 0, /* flags */
offsetof(PaddleMobile__Framework__Proto__OpDesc__Attr, l), 0, NULL, NULL /* reserved1,reserved2, etc */
NULL, },
NULL, };
0, /* flags */ static const unsigned
0,NULL,NULL /* reserved1,reserved2, etc */ paddle_mobile__framework__proto__op_desc__var__field_indices_by_name[] = {
}, 1, /* field[1] = arguments */
}; 0, /* field[0] = parameter */
static const unsigned paddle_mobile__framework__proto__op_desc__attr__field_indices_by_name[] = { };
8, /* field[8] = b */ static const ProtobufCIntRange
10, /* field[10] = block_idx */ paddle_mobile__framework__proto__op_desc__var__number_ranges[1 + 1] = {
9, /* field[9] = bools */ {1, 0}, {0, 2}};
3, /* field[3] = f */ const ProtobufCMessageDescriptor
6, /* field[6] = floats */ paddle_mobile__framework__proto__op_desc__var__descriptor = {
2, /* field[2] = i */ PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
5, /* field[5] = ints */ "paddle_mobile.framework.proto.OpDesc.Var",
11, /* field[11] = l */ "Var",
0, /* field[0] = name */ "PaddleMobile__Framework__Proto__OpDesc__Var",
4, /* field[4] = s */ "paddle_mobile.framework.proto",
7, /* field[7] = strings */ sizeof(PaddleMobile__Framework__Proto__OpDesc__Var),
1, /* field[1] = type */ 2,
}; paddle_mobile__framework__proto__op_desc__var__field_descriptors,
static const ProtobufCIntRange paddle_mobile__framework__proto__op_desc__attr__number_ranges[2 + 1] = paddle_mobile__framework__proto__op_desc__var__field_indices_by_name,
{ 1,
{ 1, 0 }, paddle_mobile__framework__proto__op_desc__var__number_ranges,
{ 10, 8 }, (ProtobufCMessageInit)
{ 0, 12 } paddle_mobile__framework__proto__op_desc__var__init,
}; NULL,
const ProtobufCMessageDescriptor paddle_mobile__framework__proto__op_desc__attr__descriptor = NULL,
{ NULL /* reserved[123] */
PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, };
"paddle_mobile.framework.proto.OpDesc.Attr", static const protobuf_c_boolean
"Attr", paddle_mobile__framework__proto__op_desc__is_target__default_value = 0;
"PaddleMobile__Framework__Proto__OpDesc__Attr", static const ProtobufCFieldDescriptor
"paddle_mobile.framework.proto", paddle_mobile__framework__proto__op_desc__field_descriptors[5] = {
sizeof(PaddleMobile__Framework__Proto__OpDesc__Attr), {
12, "inputs", 1, PROTOBUF_C_LABEL_REPEATED, PROTOBUF_C_TYPE_MESSAGE,
paddle_mobile__framework__proto__op_desc__attr__field_descriptors, offsetof(PaddleMobile__Framework__Proto__OpDesc, n_inputs),
paddle_mobile__framework__proto__op_desc__attr__field_indices_by_name, offsetof(PaddleMobile__Framework__Proto__OpDesc, inputs),
2, paddle_mobile__framework__proto__op_desc__attr__number_ranges, &paddle_mobile__framework__proto__op_desc__var__descriptor, NULL,
(ProtobufCMessageInit) paddle_mobile__framework__proto__op_desc__attr__init, 0, /* flags */
NULL,NULL,NULL /* reserved[123] */ 0, NULL, NULL /* reserved1,reserved2, etc */
}; },
static const ProtobufCFieldDescriptor paddle_mobile__framework__proto__op_desc__var__field_descriptors[2] = {
{ "outputs", 2, PROTOBUF_C_LABEL_REPEATED, PROTOBUF_C_TYPE_MESSAGE,
{ offsetof(PaddleMobile__Framework__Proto__OpDesc, n_outputs),
"parameter", offsetof(PaddleMobile__Framework__Proto__OpDesc, outputs),
1, &paddle_mobile__framework__proto__op_desc__var__descriptor, NULL,
PROTOBUF_C_LABEL_REQUIRED, 0, /* flags */
PROTOBUF_C_TYPE_STRING, 0, NULL, NULL /* reserved1,reserved2, etc */
0, /* quantifier_offset */ },
offsetof(PaddleMobile__Framework__Proto__OpDesc__Var, parameter), {
NULL, "type", 3, PROTOBUF_C_LABEL_REQUIRED, PROTOBUF_C_TYPE_STRING,
NULL, 0, /* quantifier_offset */
0, /* flags */ offsetof(PaddleMobile__Framework__Proto__OpDesc, type), NULL, NULL,
0,NULL,NULL /* reserved1,reserved2, etc */ 0, /* flags */
}, 0, NULL, NULL /* reserved1,reserved2, etc */
{ },
"arguments", {
2, "attrs", 4, PROTOBUF_C_LABEL_REPEATED, PROTOBUF_C_TYPE_MESSAGE,
PROTOBUF_C_LABEL_REPEATED, offsetof(PaddleMobile__Framework__Proto__OpDesc, n_attrs),
PROTOBUF_C_TYPE_STRING, offsetof(PaddleMobile__Framework__Proto__OpDesc, attrs),
offsetof(PaddleMobile__Framework__Proto__OpDesc__Var, n_arguments), &paddle_mobile__framework__proto__op_desc__attr__descriptor, NULL,
offsetof(PaddleMobile__Framework__Proto__OpDesc__Var, arguments), 0, /* flags */
NULL, 0, NULL, NULL /* reserved1,reserved2, etc */
NULL, },
0, /* flags */ {
0,NULL,NULL /* reserved1,reserved2, etc */ "is_target", 5, PROTOBUF_C_LABEL_OPTIONAL, PROTOBUF_C_TYPE_BOOL,
}, offsetof(PaddleMobile__Framework__Proto__OpDesc, has_is_target),
}; offsetof(PaddleMobile__Framework__Proto__OpDesc, is_target), NULL,
static const unsigned paddle_mobile__framework__proto__op_desc__var__field_indices_by_name[] = { &paddle_mobile__framework__proto__op_desc__is_target__default_value,
1, /* field[1] = arguments */ 0, /* flags */
0, /* field[0] = parameter */ 0, NULL, NULL /* reserved1,reserved2, etc */
}; },
static const ProtobufCIntRange paddle_mobile__framework__proto__op_desc__var__number_ranges[1 + 1] = };
{ static const unsigned
{ 1, 0 }, paddle_mobile__framework__proto__op_desc__field_indices_by_name[] = {
{ 0, 2 } 3, /* field[3] = attrs */
}; 0, /* field[0] = inputs */
const ProtobufCMessageDescriptor paddle_mobile__framework__proto__op_desc__var__descriptor = 4, /* field[4] = is_target */
{ 1, /* field[1] = outputs */
PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, 2, /* field[2] = type */
"paddle_mobile.framework.proto.OpDesc.Var", };
"Var", static const ProtobufCIntRange
"PaddleMobile__Framework__Proto__OpDesc__Var", paddle_mobile__framework__proto__op_desc__number_ranges[1 + 1] = {{1, 0},
"paddle_mobile.framework.proto", {0, 5}};
sizeof(PaddleMobile__Framework__Proto__OpDesc__Var), const ProtobufCMessageDescriptor
2, paddle_mobile__framework__proto__op_desc__descriptor = {
paddle_mobile__framework__proto__op_desc__var__field_descriptors, PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
paddle_mobile__framework__proto__op_desc__var__field_indices_by_name, "paddle_mobile.framework.proto.OpDesc",
1, paddle_mobile__framework__proto__op_desc__var__number_ranges, "OpDesc",
(ProtobufCMessageInit) paddle_mobile__framework__proto__op_desc__var__init, "PaddleMobile__Framework__Proto__OpDesc",
NULL,NULL,NULL /* reserved[123] */ "paddle_mobile.framework.proto",
}; sizeof(PaddleMobile__Framework__Proto__OpDesc),
static const protobuf_c_boolean paddle_mobile__framework__proto__op_desc__is_target__default_value = 0; 5,
static const ProtobufCFieldDescriptor paddle_mobile__framework__proto__op_desc__field_descriptors[5] = paddle_mobile__framework__proto__op_desc__field_descriptors,
{ paddle_mobile__framework__proto__op_desc__field_indices_by_name,
{ 1,
"inputs", paddle_mobile__framework__proto__op_desc__number_ranges,
1, (ProtobufCMessageInit)paddle_mobile__framework__proto__op_desc__init,
PROTOBUF_C_LABEL_REPEATED, NULL,
PROTOBUF_C_TYPE_MESSAGE, NULL,
offsetof(PaddleMobile__Framework__Proto__OpDesc, n_inputs), NULL /* reserved[123] */
offsetof(PaddleMobile__Framework__Proto__OpDesc, inputs), };
&paddle_mobile__framework__proto__op_desc__var__descriptor, static const protobuf_c_boolean
NULL, paddle_mobile__framework__proto__op_proto__var__duplicable__default_value =
0, /* flags */ 0;
0,NULL,NULL /* reserved1,reserved2, etc */ static const protobuf_c_boolean
}, paddle_mobile__framework__proto__op_proto__var__intermediate__default_value =
{ 0;
"outputs", static const protobuf_c_boolean
2, paddle_mobile__framework__proto__op_proto__var__dispensable__default_value =
PROTOBUF_C_LABEL_REPEATED, 0;
PROTOBUF_C_TYPE_MESSAGE, static const ProtobufCFieldDescriptor
offsetof(PaddleMobile__Framework__Proto__OpDesc, n_outputs), paddle_mobile__framework__proto__op_proto__var__field_descriptors[5] = {
offsetof(PaddleMobile__Framework__Proto__OpDesc, outputs), {
&paddle_mobile__framework__proto__op_desc__var__descriptor, "name", 1, PROTOBUF_C_LABEL_REQUIRED, PROTOBUF_C_TYPE_STRING,
NULL, 0, /* quantifier_offset */
0, /* flags */ offsetof(PaddleMobile__Framework__Proto__OpProto__Var, name), NULL,
0,NULL,NULL /* reserved1,reserved2, etc */ NULL, 0, /* flags */
}, 0, NULL, NULL /* reserved1,reserved2, etc */
{ },
"type", {
3, "comment", 2, PROTOBUF_C_LABEL_REQUIRED, PROTOBUF_C_TYPE_STRING,
PROTOBUF_C_LABEL_REQUIRED, 0, /* quantifier_offset */
PROTOBUF_C_TYPE_STRING, offsetof(PaddleMobile__Framework__Proto__OpProto__Var, comment),
0, /* quantifier_offset */ NULL, NULL, 0, /* flags */
offsetof(PaddleMobile__Framework__Proto__OpDesc, type), 0, NULL, NULL /* reserved1,reserved2, etc */
NULL, },
NULL, {
0, /* flags */ "duplicable", 3, PROTOBUF_C_LABEL_OPTIONAL, PROTOBUF_C_TYPE_BOOL,
0,NULL,NULL /* reserved1,reserved2, etc */ offsetof(PaddleMobile__Framework__Proto__OpProto__Var,
}, has_duplicable),
{ offsetof(PaddleMobile__Framework__Proto__OpProto__Var, duplicable),
"attrs", NULL,
4, &paddle_mobile__framework__proto__op_proto__var__duplicable__default_value,
PROTOBUF_C_LABEL_REPEATED, 0, /* flags */
PROTOBUF_C_TYPE_MESSAGE, 0, NULL, NULL /* reserved1,reserved2, etc */
offsetof(PaddleMobile__Framework__Proto__OpDesc, n_attrs), },
offsetof(PaddleMobile__Framework__Proto__OpDesc, attrs), {
&paddle_mobile__framework__proto__op_desc__attr__descriptor, "intermediate", 4, PROTOBUF_C_LABEL_OPTIONAL, PROTOBUF_C_TYPE_BOOL,
NULL, offsetof(PaddleMobile__Framework__Proto__OpProto__Var,
0, /* flags */ has_intermediate),
0,NULL,NULL /* reserved1,reserved2, etc */ offsetof(PaddleMobile__Framework__Proto__OpProto__Var,
}, intermediate),
{ NULL,
"is_target", &paddle_mobile__framework__proto__op_proto__var__intermediate__default_value,
5, 0, /* flags */
PROTOBUF_C_LABEL_OPTIONAL, 0, NULL, NULL /* reserved1,reserved2, etc */
PROTOBUF_C_TYPE_BOOL, },
offsetof(PaddleMobile__Framework__Proto__OpDesc, has_is_target), {
offsetof(PaddleMobile__Framework__Proto__OpDesc, is_target), "dispensable", 5, PROTOBUF_C_LABEL_OPTIONAL, PROTOBUF_C_TYPE_BOOL,
NULL, offsetof(PaddleMobile__Framework__Proto__OpProto__Var,
&paddle_mobile__framework__proto__op_desc__is_target__default_value, has_dispensable),
0, /* flags */ offsetof(PaddleMobile__Framework__Proto__OpProto__Var, dispensable),
0,NULL,NULL /* reserved1,reserved2, etc */ NULL,
}, &paddle_mobile__framework__proto__op_proto__var__dispensable__default_value,
}; 0, /* flags */
static const unsigned paddle_mobile__framework__proto__op_desc__field_indices_by_name[] = { 0, NULL, NULL /* reserved1,reserved2, etc */
3, /* field[3] = attrs */ },
0, /* field[0] = inputs */ };
4, /* field[4] = is_target */ static const unsigned
1, /* field[1] = outputs */ paddle_mobile__framework__proto__op_proto__var__field_indices_by_name[] = {
2, /* field[2] = type */ 1, /* field[1] = comment */
}; 4, /* field[4] = dispensable */
static const ProtobufCIntRange paddle_mobile__framework__proto__op_desc__number_ranges[1 + 1] = 2, /* field[2] = duplicable */
{ 3, /* field[3] = intermediate */
{ 1, 0 }, 0, /* field[0] = name */
{ 0, 5 } };
}; static const ProtobufCIntRange
const ProtobufCMessageDescriptor paddle_mobile__framework__proto__op_desc__descriptor = paddle_mobile__framework__proto__op_proto__var__number_ranges[1 + 1] = {
{ {1, 0}, {0, 5}};
PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, const ProtobufCMessageDescriptor
"paddle_mobile.framework.proto.OpDesc", paddle_mobile__framework__proto__op_proto__var__descriptor = {
"OpDesc", PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
"PaddleMobile__Framework__Proto__OpDesc", "paddle_mobile.framework.proto.OpProto.Var",
"paddle_mobile.framework.proto", "Var",
sizeof(PaddleMobile__Framework__Proto__OpDesc), "PaddleMobile__Framework__Proto__OpProto__Var",
5, "paddle_mobile.framework.proto",
paddle_mobile__framework__proto__op_desc__field_descriptors, sizeof(PaddleMobile__Framework__Proto__OpProto__Var),
paddle_mobile__framework__proto__op_desc__field_indices_by_name, 5,
1, paddle_mobile__framework__proto__op_desc__number_ranges, paddle_mobile__framework__proto__op_proto__var__field_descriptors,
(ProtobufCMessageInit) paddle_mobile__framework__proto__op_desc__init, paddle_mobile__framework__proto__op_proto__var__field_indices_by_name,
NULL,NULL,NULL /* reserved[123] */ 1,
}; paddle_mobile__framework__proto__op_proto__var__number_ranges,
static const protobuf_c_boolean paddle_mobile__framework__proto__op_proto__var__duplicable__default_value = 0; (ProtobufCMessageInit)
static const protobuf_c_boolean paddle_mobile__framework__proto__op_proto__var__intermediate__default_value = 0; paddle_mobile__framework__proto__op_proto__var__init,
static const protobuf_c_boolean paddle_mobile__framework__proto__op_proto__var__dispensable__default_value = 0; NULL,
static const ProtobufCFieldDescriptor paddle_mobile__framework__proto__op_proto__var__field_descriptors[5] = NULL,
{ NULL /* reserved[123] */
{ };
"name", static const protobuf_c_boolean
1, paddle_mobile__framework__proto__op_proto__attr__generated__default_value =
PROTOBUF_C_LABEL_REQUIRED, 0;
PROTOBUF_C_TYPE_STRING, static const ProtobufCFieldDescriptor
0, /* quantifier_offset */ paddle_mobile__framework__proto__op_proto__attr__field_descriptors[4] = {
offsetof(PaddleMobile__Framework__Proto__OpProto__Var, name), {
NULL, "name", 1, PROTOBUF_C_LABEL_REQUIRED, PROTOBUF_C_TYPE_STRING,
NULL, 0, /* quantifier_offset */
0, /* flags */ offsetof(PaddleMobile__Framework__Proto__OpProto__Attr, name), NULL,
0,NULL,NULL /* reserved1,reserved2, etc */ NULL, 0, /* flags */
}, 0, NULL, NULL /* reserved1,reserved2, etc */
{ },
"comment", {
2, "type", 2, PROTOBUF_C_LABEL_REQUIRED, PROTOBUF_C_TYPE_ENUM,
PROTOBUF_C_LABEL_REQUIRED, 0, /* quantifier_offset */
PROTOBUF_C_TYPE_STRING, offsetof(PaddleMobile__Framework__Proto__OpProto__Attr, type),
0, /* quantifier_offset */ &paddle_mobile__framework__proto__attr_type__descriptor, NULL,
offsetof(PaddleMobile__Framework__Proto__OpProto__Var, comment), 0, /* flags */
NULL, 0, NULL, NULL /* reserved1,reserved2, etc */
NULL, },
0, /* flags */ {
0,NULL,NULL /* reserved1,reserved2, etc */ "comment", 3, PROTOBUF_C_LABEL_REQUIRED, PROTOBUF_C_TYPE_STRING,
}, 0, /* quantifier_offset */
{ offsetof(PaddleMobile__Framework__Proto__OpProto__Attr, comment),
"duplicable", NULL, NULL, 0, /* flags */
3, 0, NULL, NULL /* reserved1,reserved2, etc */
PROTOBUF_C_LABEL_OPTIONAL, },
PROTOBUF_C_TYPE_BOOL, {
offsetof(PaddleMobile__Framework__Proto__OpProto__Var, has_duplicable), "generated", 4, PROTOBUF_C_LABEL_OPTIONAL, PROTOBUF_C_TYPE_BOOL,
offsetof(PaddleMobile__Framework__Proto__OpProto__Var, duplicable), offsetof(PaddleMobile__Framework__Proto__OpProto__Attr,
NULL, has_generated),
&paddle_mobile__framework__proto__op_proto__var__duplicable__default_value, offsetof(PaddleMobile__Framework__Proto__OpProto__Attr, generated),
0, /* flags */ NULL,
0,NULL,NULL /* reserved1,reserved2, etc */ &paddle_mobile__framework__proto__op_proto__attr__generated__default_value,
}, 0, /* flags */
{ 0, NULL, NULL /* reserved1,reserved2, etc */
"intermediate", },
4, };
PROTOBUF_C_LABEL_OPTIONAL, static const unsigned
PROTOBUF_C_TYPE_BOOL, paddle_mobile__framework__proto__op_proto__attr__field_indices_by_name[] = {
offsetof(PaddleMobile__Framework__Proto__OpProto__Var, has_intermediate), 2, /* field[2] = comment */
offsetof(PaddleMobile__Framework__Proto__OpProto__Var, intermediate), 3, /* field[3] = generated */
NULL, 0, /* field[0] = name */
&paddle_mobile__framework__proto__op_proto__var__intermediate__default_value, 1, /* field[1] = type */
0, /* flags */ };
0,NULL,NULL /* reserved1,reserved2, etc */ static const ProtobufCIntRange
}, paddle_mobile__framework__proto__op_proto__attr__number_ranges[1 + 1] = {
{ {1, 0}, {0, 4}};
"dispensable", const ProtobufCMessageDescriptor
5, paddle_mobile__framework__proto__op_proto__attr__descriptor = {
PROTOBUF_C_LABEL_OPTIONAL, PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
PROTOBUF_C_TYPE_BOOL, "paddle_mobile.framework.proto.OpProto.Attr",
offsetof(PaddleMobile__Framework__Proto__OpProto__Var, has_dispensable), "Attr",
offsetof(PaddleMobile__Framework__Proto__OpProto__Var, dispensable), "PaddleMobile__Framework__Proto__OpProto__Attr",
NULL, "paddle_mobile.framework.proto",
&paddle_mobile__framework__proto__op_proto__var__dispensable__default_value, sizeof(PaddleMobile__Framework__Proto__OpProto__Attr),
0, /* flags */ 4,
0,NULL,NULL /* reserved1,reserved2, etc */ paddle_mobile__framework__proto__op_proto__attr__field_descriptors,
}, paddle_mobile__framework__proto__op_proto__attr__field_indices_by_name,
}; 1,
static const unsigned paddle_mobile__framework__proto__op_proto__var__field_indices_by_name[] = { paddle_mobile__framework__proto__op_proto__attr__number_ranges,
1, /* field[1] = comment */ (ProtobufCMessageInit)
4, /* field[4] = dispensable */ paddle_mobile__framework__proto__op_proto__attr__init,
2, /* field[2] = duplicable */ NULL,
3, /* field[3] = intermediate */ NULL,
0, /* field[0] = name */ NULL /* reserved[123] */
}; };
static const ProtobufCIntRange paddle_mobile__framework__proto__op_proto__var__number_ranges[1 + 1] = static const ProtobufCFieldDescriptor
{ paddle_mobile__framework__proto__op_proto__field_descriptors[5] = {
{ 1, 0 }, {
{ 0, 5 } "type", 1, PROTOBUF_C_LABEL_REQUIRED, PROTOBUF_C_TYPE_STRING,
}; 0, /* quantifier_offset */
const ProtobufCMessageDescriptor paddle_mobile__framework__proto__op_proto__var__descriptor = offsetof(PaddleMobile__Framework__Proto__OpProto, type), NULL, NULL,
{ 0, /* flags */
PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, 0, NULL, NULL /* reserved1,reserved2, etc */
"paddle_mobile.framework.proto.OpProto.Var", },
"Var", {
"PaddleMobile__Framework__Proto__OpProto__Var", "inputs", 2, PROTOBUF_C_LABEL_REPEATED, PROTOBUF_C_TYPE_MESSAGE,
"paddle_mobile.framework.proto", offsetof(PaddleMobile__Framework__Proto__OpProto, n_inputs),
sizeof(PaddleMobile__Framework__Proto__OpProto__Var), offsetof(PaddleMobile__Framework__Proto__OpProto, inputs),
5, &paddle_mobile__framework__proto__op_proto__var__descriptor, NULL,
paddle_mobile__framework__proto__op_proto__var__field_descriptors, 0, /* flags */
paddle_mobile__framework__proto__op_proto__var__field_indices_by_name, 0, NULL, NULL /* reserved1,reserved2, etc */
1, paddle_mobile__framework__proto__op_proto__var__number_ranges, },
(ProtobufCMessageInit) paddle_mobile__framework__proto__op_proto__var__init, {
NULL,NULL,NULL /* reserved[123] */ "outputs", 3, PROTOBUF_C_LABEL_REPEATED, PROTOBUF_C_TYPE_MESSAGE,
}; offsetof(PaddleMobile__Framework__Proto__OpProto, n_outputs),
static const protobuf_c_boolean paddle_mobile__framework__proto__op_proto__attr__generated__default_value = 0; offsetof(PaddleMobile__Framework__Proto__OpProto, outputs),
static const ProtobufCFieldDescriptor paddle_mobile__framework__proto__op_proto__attr__field_descriptors[4] = &paddle_mobile__framework__proto__op_proto__var__descriptor, NULL,
{ 0, /* flags */
{ 0, NULL, NULL /* reserved1,reserved2, etc */
"name", },
1, {
PROTOBUF_C_LABEL_REQUIRED, "attrs", 4, PROTOBUF_C_LABEL_REPEATED, PROTOBUF_C_TYPE_MESSAGE,
PROTOBUF_C_TYPE_STRING, offsetof(PaddleMobile__Framework__Proto__OpProto, n_attrs),
0, /* quantifier_offset */ offsetof(PaddleMobile__Framework__Proto__OpProto, attrs),
offsetof(PaddleMobile__Framework__Proto__OpProto__Attr, name), &paddle_mobile__framework__proto__op_proto__attr__descriptor, NULL,
NULL, 0, /* flags */
NULL, 0, NULL, NULL /* reserved1,reserved2, etc */
0, /* flags */ },
0,NULL,NULL /* reserved1,reserved2, etc */ {
}, "comment", 5, PROTOBUF_C_LABEL_REQUIRED, PROTOBUF_C_TYPE_STRING,
{ 0, /* quantifier_offset */
"type", offsetof(PaddleMobile__Framework__Proto__OpProto, comment), NULL,
2, NULL, 0, /* flags */
PROTOBUF_C_LABEL_REQUIRED, 0, NULL, NULL /* reserved1,reserved2, etc */
PROTOBUF_C_TYPE_ENUM, },
0, /* quantifier_offset */ };
offsetof(PaddleMobile__Framework__Proto__OpProto__Attr, type), static const unsigned
&paddle_mobile__framework__proto__attr_type__descriptor, paddle_mobile__framework__proto__op_proto__field_indices_by_name[] = {
NULL, 3, /* field[3] = attrs */
0, /* flags */ 4, /* field[4] = comment */
0,NULL,NULL /* reserved1,reserved2, etc */ 1, /* field[1] = inputs */
}, 2, /* field[2] = outputs */
{ 0, /* field[0] = type */
"comment", };
3, static const ProtobufCIntRange
PROTOBUF_C_LABEL_REQUIRED, paddle_mobile__framework__proto__op_proto__number_ranges[1 + 1] = {{1, 0},
PROTOBUF_C_TYPE_STRING, {0, 5}};
0, /* quantifier_offset */ const ProtobufCMessageDescriptor
offsetof(PaddleMobile__Framework__Proto__OpProto__Attr, comment), paddle_mobile__framework__proto__op_proto__descriptor = {
NULL, PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
NULL, "paddle_mobile.framework.proto.OpProto",
0, /* flags */ "OpProto",
0,NULL,NULL /* reserved1,reserved2, etc */ "PaddleMobile__Framework__Proto__OpProto",
}, "paddle_mobile.framework.proto",
{ sizeof(PaddleMobile__Framework__Proto__OpProto),
"generated", 5,
4, paddle_mobile__framework__proto__op_proto__field_descriptors,
PROTOBUF_C_LABEL_OPTIONAL, paddle_mobile__framework__proto__op_proto__field_indices_by_name,
PROTOBUF_C_TYPE_BOOL, 1,
offsetof(PaddleMobile__Framework__Proto__OpProto__Attr, has_generated), paddle_mobile__framework__proto__op_proto__number_ranges,
offsetof(PaddleMobile__Framework__Proto__OpProto__Attr, generated), (ProtobufCMessageInit)paddle_mobile__framework__proto__op_proto__init,
NULL, NULL,
&paddle_mobile__framework__proto__op_proto__attr__generated__default_value, NULL,
0, /* flags */ NULL /* reserved[123] */
0,NULL,NULL /* reserved1,reserved2, etc */ };
}, static const ProtobufCFieldDescriptor
}; paddle_mobile__framework__proto__var_type__tensor_desc__field_descriptors
static const unsigned paddle_mobile__framework__proto__op_proto__attr__field_indices_by_name[] = { [2] = {
2, /* field[2] = comment */ {
3, /* field[3] = generated */ "data_type", 1, PROTOBUF_C_LABEL_REQUIRED, PROTOBUF_C_TYPE_ENUM,
0, /* field[0] = name */ 0, /* quantifier_offset */
1, /* field[1] = type */ offsetof(PaddleMobile__Framework__Proto__VarType__TensorDesc,
}; data_type),
static const ProtobufCIntRange paddle_mobile__framework__proto__op_proto__attr__number_ranges[1 + 1] = &paddle_mobile__framework__proto__var_type__type__descriptor,
{ NULL, 0, /* flags */
{ 1, 0 }, 0, NULL, NULL /* reserved1,reserved2, etc */
{ 0, 4 } },
}; {
const ProtobufCMessageDescriptor paddle_mobile__framework__proto__op_proto__attr__descriptor = "dims", 2, PROTOBUF_C_LABEL_REPEATED, PROTOBUF_C_TYPE_INT64,
{ offsetof(PaddleMobile__Framework__Proto__VarType__TensorDesc,
PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, n_dims),
"paddle_mobile.framework.proto.OpProto.Attr", offsetof(PaddleMobile__Framework__Proto__VarType__TensorDesc,
"Attr", dims),
"PaddleMobile__Framework__Proto__OpProto__Attr", NULL, NULL, 0, /* flags */
"paddle_mobile.framework.proto", 0, NULL, NULL /* reserved1,reserved2, etc */
sizeof(PaddleMobile__Framework__Proto__OpProto__Attr), },
4, };
paddle_mobile__framework__proto__op_proto__attr__field_descriptors, static const unsigned
paddle_mobile__framework__proto__op_proto__attr__field_indices_by_name, paddle_mobile__framework__proto__var_type__tensor_desc__field_indices_by_name
1, paddle_mobile__framework__proto__op_proto__attr__number_ranges, [] = {
(ProtobufCMessageInit) paddle_mobile__framework__proto__op_proto__attr__init, 0, /* field[0] = data_type */
NULL,NULL,NULL /* reserved[123] */ 1, /* field[1] = dims */
}; };
static const ProtobufCFieldDescriptor paddle_mobile__framework__proto__op_proto__field_descriptors[5] = static const ProtobufCIntRange
{ paddle_mobile__framework__proto__var_type__tensor_desc__number_ranges[1 +
{ 1] = {
"type", {1, 0}, {0, 2}};
1, const ProtobufCMessageDescriptor
PROTOBUF_C_LABEL_REQUIRED, paddle_mobile__framework__proto__var_type__tensor_desc__descriptor = {
PROTOBUF_C_TYPE_STRING, PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
0, /* quantifier_offset */ "paddle_mobile.framework.proto.VarType.TensorDesc",
offsetof(PaddleMobile__Framework__Proto__OpProto, type), "TensorDesc",
NULL, "PaddleMobile__Framework__Proto__VarType__TensorDesc",
NULL, "paddle_mobile.framework.proto",
0, /* flags */ sizeof(PaddleMobile__Framework__Proto__VarType__TensorDesc),
0,NULL,NULL /* reserved1,reserved2, etc */ 2,
}, paddle_mobile__framework__proto__var_type__tensor_desc__field_descriptors,
{ paddle_mobile__framework__proto__var_type__tensor_desc__field_indices_by_name,
"inputs", 1,
2, paddle_mobile__framework__proto__var_type__tensor_desc__number_ranges,
PROTOBUF_C_LABEL_REPEATED, (ProtobufCMessageInit)
PROTOBUF_C_TYPE_MESSAGE, paddle_mobile__framework__proto__var_type__tensor_desc__init,
offsetof(PaddleMobile__Framework__Proto__OpProto, n_inputs), NULL,
offsetof(PaddleMobile__Framework__Proto__OpProto, inputs), NULL,
&paddle_mobile__framework__proto__op_proto__var__descriptor, NULL /* reserved[123] */
NULL, };
0, /* flags */ static const int32_t
0,NULL,NULL /* reserved1,reserved2, etc */ paddle_mobile__framework__proto__var_type__lo_dtensor_desc__lod_level__default_value =
}, 0;
{ static const ProtobufCFieldDescriptor
"outputs", paddle_mobile__framework__proto__var_type__lo_dtensor_desc__field_descriptors
3, [2] = {
PROTOBUF_C_LABEL_REPEATED, {
PROTOBUF_C_TYPE_MESSAGE, "tensor", 1, PROTOBUF_C_LABEL_REQUIRED, PROTOBUF_C_TYPE_MESSAGE,
offsetof(PaddleMobile__Framework__Proto__OpProto, n_outputs), 0, /* quantifier_offset */
offsetof(PaddleMobile__Framework__Proto__OpProto, outputs), offsetof(PaddleMobile__Framework__Proto__VarType__LoDTensorDesc,
&paddle_mobile__framework__proto__op_proto__var__descriptor, tensor),
NULL, &paddle_mobile__framework__proto__var_type__tensor_desc__descriptor,
0, /* flags */ NULL, 0, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */ 0, NULL, NULL /* reserved1,reserved2, etc */
}, },
{ {
"attrs", "lod_level", 2, PROTOBUF_C_LABEL_OPTIONAL,
4, PROTOBUF_C_TYPE_INT32,
PROTOBUF_C_LABEL_REPEATED, offsetof(PaddleMobile__Framework__Proto__VarType__LoDTensorDesc,
PROTOBUF_C_TYPE_MESSAGE, has_lod_level),
offsetof(PaddleMobile__Framework__Proto__OpProto, n_attrs), offsetof(PaddleMobile__Framework__Proto__VarType__LoDTensorDesc,
offsetof(PaddleMobile__Framework__Proto__OpProto, attrs), lod_level),
&paddle_mobile__framework__proto__op_proto__attr__descriptor, NULL,
NULL, &paddle_mobile__framework__proto__var_type__lo_dtensor_desc__lod_level__default_value,
0, /* flags */ 0, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */ 0, NULL, NULL /* reserved1,reserved2, etc */
}, },
{ };
"comment", static const unsigned
5, paddle_mobile__framework__proto__var_type__lo_dtensor_desc__field_indices_by_name
PROTOBUF_C_LABEL_REQUIRED, [] = {
PROTOBUF_C_TYPE_STRING, 1, /* field[1] = lod_level */
0, /* quantifier_offset */ 0, /* field[0] = tensor */
offsetof(PaddleMobile__Framework__Proto__OpProto, comment), };
NULL, static const ProtobufCIntRange
NULL, paddle_mobile__framework__proto__var_type__lo_dtensor_desc__number_ranges
0, /* flags */ [1 + 1] = {{1, 0}, {0, 2}};
0,NULL,NULL /* reserved1,reserved2, etc */ const ProtobufCMessageDescriptor
}, paddle_mobile__framework__proto__var_type__lo_dtensor_desc__descriptor = {
}; PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
static const unsigned paddle_mobile__framework__proto__op_proto__field_indices_by_name[] = { "paddle_mobile.framework.proto.VarType.LoDTensorDesc",
3, /* field[3] = attrs */ "LoDTensorDesc",
4, /* field[4] = comment */ "PaddleMobile__Framework__Proto__VarType__LoDTensorDesc",
1, /* field[1] = inputs */ "paddle_mobile.framework.proto",
2, /* field[2] = outputs */ sizeof(PaddleMobile__Framework__Proto__VarType__LoDTensorDesc),
0, /* field[0] = type */ 2,
}; paddle_mobile__framework__proto__var_type__lo_dtensor_desc__field_descriptors,
static const ProtobufCIntRange paddle_mobile__framework__proto__op_proto__number_ranges[1 + 1] = paddle_mobile__framework__proto__var_type__lo_dtensor_desc__field_indices_by_name,
{ 1,
{ 1, 0 }, paddle_mobile__framework__proto__var_type__lo_dtensor_desc__number_ranges,
{ 0, 5 } (ProtobufCMessageInit)
}; paddle_mobile__framework__proto__var_type__lo_dtensor_desc__init,
const ProtobufCMessageDescriptor paddle_mobile__framework__proto__op_proto__descriptor = NULL,
{ NULL,
PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, NULL /* reserved[123] */
"paddle_mobile.framework.proto.OpProto", };
"OpProto", static const int32_t
"PaddleMobile__Framework__Proto__OpProto", paddle_mobile__framework__proto__var_type__lo_dtensor_array_desc__lod_level__default_value =
"paddle_mobile.framework.proto", 0;
sizeof(PaddleMobile__Framework__Proto__OpProto), static const ProtobufCFieldDescriptor
5, paddle_mobile__framework__proto__var_type__lo_dtensor_array_desc__field_descriptors
paddle_mobile__framework__proto__op_proto__field_descriptors, [2] = {
paddle_mobile__framework__proto__op_proto__field_indices_by_name, {
1, paddle_mobile__framework__proto__op_proto__number_ranges, "tensor", 1, PROTOBUF_C_LABEL_REQUIRED, PROTOBUF_C_TYPE_MESSAGE,
(ProtobufCMessageInit) paddle_mobile__framework__proto__op_proto__init, 0, /* quantifier_offset */
NULL,NULL,NULL /* reserved[123] */ offsetof(
}; PaddleMobile__Framework__Proto__VarType__LoDTensorArrayDesc,
static const ProtobufCFieldDescriptor paddle_mobile__framework__proto__var_type__tensor_desc__field_descriptors[2] = tensor),
{ &paddle_mobile__framework__proto__var_type__tensor_desc__descriptor,
{ NULL, 0, /* flags */
"data_type", 0, NULL, NULL /* reserved1,reserved2, etc */
1, },
PROTOBUF_C_LABEL_REQUIRED, {
PROTOBUF_C_TYPE_ENUM, "lod_level", 2, PROTOBUF_C_LABEL_OPTIONAL,
0, /* quantifier_offset */ PROTOBUF_C_TYPE_INT32,
offsetof(PaddleMobile__Framework__Proto__VarType__TensorDesc, data_type), offsetof(
&paddle_mobile__framework__proto__var_type__type__descriptor, PaddleMobile__Framework__Proto__VarType__LoDTensorArrayDesc,
NULL, has_lod_level),
0, /* flags */ offsetof(
0,NULL,NULL /* reserved1,reserved2, etc */ PaddleMobile__Framework__Proto__VarType__LoDTensorArrayDesc,
}, lod_level),
{ NULL,
"dims", &paddle_mobile__framework__proto__var_type__lo_dtensor_array_desc__lod_level__default_value,
2, 0, /* flags */
PROTOBUF_C_LABEL_REPEATED, 0, NULL, NULL /* reserved1,reserved2, etc */
PROTOBUF_C_TYPE_INT64, },
offsetof(PaddleMobile__Framework__Proto__VarType__TensorDesc, n_dims), };
offsetof(PaddleMobile__Framework__Proto__VarType__TensorDesc, dims), static const unsigned
NULL, paddle_mobile__framework__proto__var_type__lo_dtensor_array_desc__field_indices_by_name
NULL, [] = {
0, /* flags */ 1, /* field[1] = lod_level */
0,NULL,NULL /* reserved1,reserved2, etc */ 0, /* field[0] = tensor */
}, };
}; static const ProtobufCIntRange
static const unsigned paddle_mobile__framework__proto__var_type__tensor_desc__field_indices_by_name[] = { paddle_mobile__framework__proto__var_type__lo_dtensor_array_desc__number_ranges
0, /* field[0] = data_type */ [1 + 1] = {{1, 0}, {0, 2}};
1, /* field[1] = dims */ const ProtobufCMessageDescriptor
}; paddle_mobile__framework__proto__var_type__lo_dtensor_array_desc__descriptor = {
static const ProtobufCIntRange paddle_mobile__framework__proto__var_type__tensor_desc__number_ranges[1 + 1] = PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
{ "paddle_mobile.framework.proto.VarType.LoDTensorArrayDesc",
{ 1, 0 }, "LoDTensorArrayDesc",
{ 0, 2 } "PaddleMobile__Framework__Proto__VarType__LoDTensorArrayDesc",
}; "paddle_mobile.framework.proto",
const ProtobufCMessageDescriptor paddle_mobile__framework__proto__var_type__tensor_desc__descriptor = sizeof(PaddleMobile__Framework__Proto__VarType__LoDTensorArrayDesc),
{ 2,
PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, paddle_mobile__framework__proto__var_type__lo_dtensor_array_desc__field_descriptors,
"paddle_mobile.framework.proto.VarType.TensorDesc", paddle_mobile__framework__proto__var_type__lo_dtensor_array_desc__field_indices_by_name,
"TensorDesc", 1,
"PaddleMobile__Framework__Proto__VarType__TensorDesc", paddle_mobile__framework__proto__var_type__lo_dtensor_array_desc__number_ranges,
"paddle_mobile.framework.proto", (ProtobufCMessageInit)
sizeof(PaddleMobile__Framework__Proto__VarType__TensorDesc), paddle_mobile__framework__proto__var_type__lo_dtensor_array_desc__init,
2, NULL,
paddle_mobile__framework__proto__var_type__tensor_desc__field_descriptors, NULL,
paddle_mobile__framework__proto__var_type__tensor_desc__field_indices_by_name, NULL /* reserved[123] */
1, paddle_mobile__framework__proto__var_type__tensor_desc__number_ranges, };
(ProtobufCMessageInit) paddle_mobile__framework__proto__var_type__tensor_desc__init, static const ProtobufCFieldDescriptor
NULL,NULL,NULL /* reserved[123] */ paddle_mobile__framework__proto__var_type__reader_desc__field_descriptors[1] = {
}; {
static const int32_t paddle_mobile__framework__proto__var_type__lo_dtensor_desc__lod_level__default_value = 0; "lod_tensor", 1, PROTOBUF_C_LABEL_REPEATED, PROTOBUF_C_TYPE_MESSAGE,
static const ProtobufCFieldDescriptor paddle_mobile__framework__proto__var_type__lo_dtensor_desc__field_descriptors[2] = offsetof(PaddleMobile__Framework__Proto__VarType__ReaderDesc,
{ n_lod_tensor),
{ offsetof(PaddleMobile__Framework__Proto__VarType__ReaderDesc,
"tensor", lod_tensor),
1, &paddle_mobile__framework__proto__var_type__lo_dtensor_desc__descriptor,
PROTOBUF_C_LABEL_REQUIRED, NULL, 0, /* flags */
PROTOBUF_C_TYPE_MESSAGE, 0, NULL, NULL /* reserved1,reserved2, etc */
0, /* quantifier_offset */ },
offsetof(PaddleMobile__Framework__Proto__VarType__LoDTensorDesc, tensor), };
&paddle_mobile__framework__proto__var_type__tensor_desc__descriptor, static const unsigned
NULL, paddle_mobile__framework__proto__var_type__reader_desc__field_indices_by_name
0, /* flags */ [] = {
0,NULL,NULL /* reserved1,reserved2, etc */ 0, /* field[0] = lod_tensor */
}, };
{ static const ProtobufCIntRange
"lod_level", paddle_mobile__framework__proto__var_type__reader_desc__number_ranges[1 +
2, 1] = {
PROTOBUF_C_LABEL_OPTIONAL, {1, 0}, {0, 1}};
PROTOBUF_C_TYPE_INT32, const ProtobufCMessageDescriptor
offsetof(PaddleMobile__Framework__Proto__VarType__LoDTensorDesc, has_lod_level), paddle_mobile__framework__proto__var_type__reader_desc__descriptor = {
offsetof(PaddleMobile__Framework__Proto__VarType__LoDTensorDesc, lod_level), PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
NULL, "paddle_mobile.framework.proto.VarType.ReaderDesc",
&paddle_mobile__framework__proto__var_type__lo_dtensor_desc__lod_level__default_value, "ReaderDesc",
0, /* flags */ "PaddleMobile__Framework__Proto__VarType__ReaderDesc",
0,NULL,NULL /* reserved1,reserved2, etc */ "paddle_mobile.framework.proto",
}, sizeof(PaddleMobile__Framework__Proto__VarType__ReaderDesc),
}; 1,
static const unsigned paddle_mobile__framework__proto__var_type__lo_dtensor_desc__field_indices_by_name[] = { paddle_mobile__framework__proto__var_type__reader_desc__field_descriptors,
1, /* field[1] = lod_level */ paddle_mobile__framework__proto__var_type__reader_desc__field_indices_by_name,
0, /* field[0] = tensor */ 1,
}; paddle_mobile__framework__proto__var_type__reader_desc__number_ranges,
static const ProtobufCIntRange paddle_mobile__framework__proto__var_type__lo_dtensor_desc__number_ranges[1 + 1] = (ProtobufCMessageInit)
{ paddle_mobile__framework__proto__var_type__reader_desc__init,
{ 1, 0 }, NULL,
{ 0, 2 } NULL,
}; NULL /* reserved[123] */
const ProtobufCMessageDescriptor paddle_mobile__framework__proto__var_type__lo_dtensor_desc__descriptor = };
{ static const ProtobufCFieldDescriptor
PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, paddle_mobile__framework__proto__var_type__channel_desc__field_descriptors
"paddle_mobile.framework.proto.VarType.LoDTensorDesc", [2] = {
"LoDTensorDesc", {
"PaddleMobile__Framework__Proto__VarType__LoDTensorDesc", "data_type", 1, PROTOBUF_C_LABEL_REQUIRED, PROTOBUF_C_TYPE_ENUM,
"paddle_mobile.framework.proto", 0, /* quantifier_offset */
sizeof(PaddleMobile__Framework__Proto__VarType__LoDTensorDesc), offsetof(PaddleMobile__Framework__Proto__VarType__ChannelDesc,
2, data_type),
paddle_mobile__framework__proto__var_type__lo_dtensor_desc__field_descriptors, &paddle_mobile__framework__proto__var_type__type__descriptor,
paddle_mobile__framework__proto__var_type__lo_dtensor_desc__field_indices_by_name, NULL, 0, /* flags */
1, paddle_mobile__framework__proto__var_type__lo_dtensor_desc__number_ranges, 0, NULL, NULL /* reserved1,reserved2, etc */
(ProtobufCMessageInit) paddle_mobile__framework__proto__var_type__lo_dtensor_desc__init, },
NULL,NULL,NULL /* reserved[123] */ {
}; "capacity", 2, PROTOBUF_C_LABEL_REQUIRED, PROTOBUF_C_TYPE_INT64,
static const int32_t paddle_mobile__framework__proto__var_type__lo_dtensor_array_desc__lod_level__default_value = 0; 0, /* quantifier_offset */
static const ProtobufCFieldDescriptor paddle_mobile__framework__proto__var_type__lo_dtensor_array_desc__field_descriptors[2] = offsetof(PaddleMobile__Framework__Proto__VarType__ChannelDesc,
{ capacity),
{ NULL, NULL, 0, /* flags */
"tensor", 0, NULL, NULL /* reserved1,reserved2, etc */
1, },
PROTOBUF_C_LABEL_REQUIRED, };
PROTOBUF_C_TYPE_MESSAGE, static const unsigned
0, /* quantifier_offset */ paddle_mobile__framework__proto__var_type__channel_desc__field_indices_by_name
offsetof(PaddleMobile__Framework__Proto__VarType__LoDTensorArrayDesc, tensor), [] = {
&paddle_mobile__framework__proto__var_type__tensor_desc__descriptor, 1, /* field[1] = capacity */
NULL, 0, /* field[0] = data_type */
0, /* flags */ };
0,NULL,NULL /* reserved1,reserved2, etc */ static const ProtobufCIntRange
}, paddle_mobile__framework__proto__var_type__channel_desc__number_ranges[1 +
{ 1] =
"lod_level", {{1, 0}, {0, 2}};
2, const ProtobufCMessageDescriptor
PROTOBUF_C_LABEL_OPTIONAL, paddle_mobile__framework__proto__var_type__channel_desc__descriptor = {
PROTOBUF_C_TYPE_INT32, PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
offsetof(PaddleMobile__Framework__Proto__VarType__LoDTensorArrayDesc, has_lod_level), "paddle_mobile.framework.proto.VarType.ChannelDesc",
offsetof(PaddleMobile__Framework__Proto__VarType__LoDTensorArrayDesc, lod_level), "ChannelDesc",
NULL, "PaddleMobile__Framework__Proto__VarType__ChannelDesc",
&paddle_mobile__framework__proto__var_type__lo_dtensor_array_desc__lod_level__default_value, "paddle_mobile.framework.proto",
0, /* flags */ sizeof(PaddleMobile__Framework__Proto__VarType__ChannelDesc),
0,NULL,NULL /* reserved1,reserved2, etc */ 2,
}, paddle_mobile__framework__proto__var_type__channel_desc__field_descriptors,
}; paddle_mobile__framework__proto__var_type__channel_desc__field_indices_by_name,
static const unsigned paddle_mobile__framework__proto__var_type__lo_dtensor_array_desc__field_indices_by_name[] = { 1,
1, /* field[1] = lod_level */ paddle_mobile__framework__proto__var_type__channel_desc__number_ranges,
0, /* field[0] = tensor */ (ProtobufCMessageInit)
}; paddle_mobile__framework__proto__var_type__channel_desc__init,
static const ProtobufCIntRange paddle_mobile__framework__proto__var_type__lo_dtensor_array_desc__number_ranges[1 + 1] = NULL,
{ NULL,
{ 1, 0 }, NULL /* reserved[123] */
{ 0, 2 } };
}; static const ProtobufCFieldDescriptor
const ProtobufCMessageDescriptor paddle_mobile__framework__proto__var_type__lo_dtensor_array_desc__descriptor = paddle_mobile__framework__proto__var_type__tuple__field_descriptors[1] = {
{ {
PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, "element_type", 1, PROTOBUF_C_LABEL_REPEATED, PROTOBUF_C_TYPE_ENUM,
"paddle_mobile.framework.proto.VarType.LoDTensorArrayDesc", offsetof(PaddleMobile__Framework__Proto__VarType__Tuple,
"LoDTensorArrayDesc", n_element_type),
"PaddleMobile__Framework__Proto__VarType__LoDTensorArrayDesc", offsetof(PaddleMobile__Framework__Proto__VarType__Tuple,
"paddle_mobile.framework.proto", element_type),
sizeof(PaddleMobile__Framework__Proto__VarType__LoDTensorArrayDesc), &paddle_mobile__framework__proto__var_type__type__descriptor, NULL,
2, 0, /* flags */
paddle_mobile__framework__proto__var_type__lo_dtensor_array_desc__field_descriptors, 0, NULL, NULL /* reserved1,reserved2, etc */
paddle_mobile__framework__proto__var_type__lo_dtensor_array_desc__field_indices_by_name, },
1, paddle_mobile__framework__proto__var_type__lo_dtensor_array_desc__number_ranges, };
(ProtobufCMessageInit) paddle_mobile__framework__proto__var_type__lo_dtensor_array_desc__init, static const unsigned
NULL,NULL,NULL /* reserved[123] */ paddle_mobile__framework__proto__var_type__tuple__field_indices_by_name[] =
}; {
static const ProtobufCFieldDescriptor paddle_mobile__framework__proto__var_type__reader_desc__field_descriptors[1] = 0, /* field[0] = element_type */
{ };
{ static const ProtobufCIntRange
"lod_tensor", paddle_mobile__framework__proto__var_type__tuple__number_ranges[1 + 1] = {
1, {1, 0}, {0, 1}};
PROTOBUF_C_LABEL_REPEATED, const ProtobufCMessageDescriptor
PROTOBUF_C_TYPE_MESSAGE, paddle_mobile__framework__proto__var_type__tuple__descriptor = {
offsetof(PaddleMobile__Framework__Proto__VarType__ReaderDesc, n_lod_tensor), PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
offsetof(PaddleMobile__Framework__Proto__VarType__ReaderDesc, lod_tensor), "paddle_mobile.framework.proto.VarType.Tuple",
&paddle_mobile__framework__proto__var_type__lo_dtensor_desc__descriptor, "Tuple",
NULL, "PaddleMobile__Framework__Proto__VarType__Tuple",
0, /* flags */ "paddle_mobile.framework.proto",
0,NULL,NULL /* reserved1,reserved2, etc */ sizeof(PaddleMobile__Framework__Proto__VarType__Tuple),
}, 1,
}; paddle_mobile__framework__proto__var_type__tuple__field_descriptors,
static const unsigned paddle_mobile__framework__proto__var_type__reader_desc__field_indices_by_name[] = { paddle_mobile__framework__proto__var_type__tuple__field_indices_by_name,
0, /* field[0] = lod_tensor */ 1,
}; paddle_mobile__framework__proto__var_type__tuple__number_ranges,
static const ProtobufCIntRange paddle_mobile__framework__proto__var_type__reader_desc__number_ranges[1 + 1] = (ProtobufCMessageInit)
{ paddle_mobile__framework__proto__var_type__tuple__init,
{ 1, 0 }, NULL,
{ 0, 1 } NULL,
}; NULL /* reserved[123] */
const ProtobufCMessageDescriptor paddle_mobile__framework__proto__var_type__reader_desc__descriptor = };
{ static const ProtobufCEnumValue
PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, paddle_mobile__framework__proto__var_type__type__enum_values_by_number[19] =
"paddle_mobile.framework.proto.VarType.ReaderDesc", {
"ReaderDesc", {"BOOL", "PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__BOOL",
"PaddleMobile__Framework__Proto__VarType__ReaderDesc", 0},
"paddle_mobile.framework.proto", {"INT16", "PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__INT16",
sizeof(PaddleMobile__Framework__Proto__VarType__ReaderDesc), 1},
1, {"INT32", "PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__INT32",
paddle_mobile__framework__proto__var_type__reader_desc__field_descriptors, 2},
paddle_mobile__framework__proto__var_type__reader_desc__field_indices_by_name, {"INT64", "PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__INT64",
1, paddle_mobile__framework__proto__var_type__reader_desc__number_ranges, 3},
(ProtobufCMessageInit) paddle_mobile__framework__proto__var_type__reader_desc__init, {"FP16", "PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__FP16",
NULL,NULL,NULL /* reserved[123] */ 4},
}; {"FP32", "PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__FP32",
static const ProtobufCFieldDescriptor paddle_mobile__framework__proto__var_type__channel_desc__field_descriptors[2] = 5},
{ {"FP64", "PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__FP64",
{ 6},
"data_type", {"LOD_TENSOR",
1, "PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__LOD_TENSOR", 7},
PROTOBUF_C_LABEL_REQUIRED, {"SELECTED_ROWS",
PROTOBUF_C_TYPE_ENUM, "PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__SELECTED_ROWS",
0, /* quantifier_offset */ 8},
offsetof(PaddleMobile__Framework__Proto__VarType__ChannelDesc, data_type), {"FEED_MINIBATCH",
&paddle_mobile__framework__proto__var_type__type__descriptor, "PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__FEED_MINIBATCH",
NULL, 9},
0, /* flags */ {"FETCH_LIST",
0,NULL,NULL /* reserved1,reserved2, etc */ "PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__FETCH_LIST", 10},
}, {"STEP_SCOPES",
{ "PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__STEP_SCOPES",
"capacity", 11},
2, {"LOD_RANK_TABLE",
PROTOBUF_C_LABEL_REQUIRED, "PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__LOD_RANK_TABLE",
PROTOBUF_C_TYPE_INT64, 12},
0, /* quantifier_offset */ {"LOD_TENSOR_ARRAY",
offsetof(PaddleMobile__Framework__Proto__VarType__ChannelDesc, capacity), "PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__LOD_TENSOR_"
NULL, "ARRAY",
NULL, 13},
0, /* flags */ {"PLACE_LIST",
0,NULL,NULL /* reserved1,reserved2, etc */ "PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__PLACE_LIST", 14},
}, {"READER",
}; "PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__READER", 15},
static const unsigned paddle_mobile__framework__proto__var_type__channel_desc__field_indices_by_name[] = { {"CHANNEL",
1, /* field[1] = capacity */ "PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__CHANNEL", 16},
0, /* field[0] = data_type */ {"RAW", "PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__RAW", 17},
}; {"TUPLE", "PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__TUPLE",
static const ProtobufCIntRange paddle_mobile__framework__proto__var_type__channel_desc__number_ranges[1 + 1] = 18},
{ };
{ 1, 0 }, static const ProtobufCIntRange
{ 0, 2 } paddle_mobile__framework__proto__var_type__type__value_ranges[] = {{0, 0},
}; {0, 19}};
const ProtobufCMessageDescriptor paddle_mobile__framework__proto__var_type__channel_desc__descriptor = static const ProtobufCEnumValueIndex
{ paddle_mobile__framework__proto__var_type__type__enum_values_by_name[19] = {
PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, {"BOOL", 0},
"paddle_mobile.framework.proto.VarType.ChannelDesc", {"CHANNEL", 16},
"ChannelDesc", {"FEED_MINIBATCH", 9},
"PaddleMobile__Framework__Proto__VarType__ChannelDesc", {"FETCH_LIST", 10},
"paddle_mobile.framework.proto", {"FP16", 4},
sizeof(PaddleMobile__Framework__Proto__VarType__ChannelDesc), {"FP32", 5},
2, {"FP64", 6},
paddle_mobile__framework__proto__var_type__channel_desc__field_descriptors, {"INT16", 1},
paddle_mobile__framework__proto__var_type__channel_desc__field_indices_by_name, {"INT32", 2},
1, paddle_mobile__framework__proto__var_type__channel_desc__number_ranges, {"INT64", 3},
(ProtobufCMessageInit) paddle_mobile__framework__proto__var_type__channel_desc__init, {"LOD_RANK_TABLE", 12},
NULL,NULL,NULL /* reserved[123] */ {"LOD_TENSOR", 7},
}; {"LOD_TENSOR_ARRAY", 13},
static const ProtobufCFieldDescriptor paddle_mobile__framework__proto__var_type__tuple__field_descriptors[1] = {"PLACE_LIST", 14},
{ {"RAW", 17},
{ {"READER", 15},
"element_type", {"SELECTED_ROWS", 8},
1, {"STEP_SCOPES", 11},
PROTOBUF_C_LABEL_REPEATED, {"TUPLE", 18},
PROTOBUF_C_TYPE_ENUM, };
offsetof(PaddleMobile__Framework__Proto__VarType__Tuple, n_element_type), const ProtobufCEnumDescriptor
offsetof(PaddleMobile__Framework__Proto__VarType__Tuple, element_type), paddle_mobile__framework__proto__var_type__type__descriptor = {
&paddle_mobile__framework__proto__var_type__type__descriptor, PROTOBUF_C__ENUM_DESCRIPTOR_MAGIC,
NULL, "paddle_mobile.framework.proto.VarType.Type",
0, /* flags */ "Type",
0,NULL,NULL /* reserved1,reserved2, etc */ "PaddleMobile__Framework__Proto__VarType__Type",
}, "paddle_mobile.framework.proto",
}; 19,
static const unsigned paddle_mobile__framework__proto__var_type__tuple__field_indices_by_name[] = { paddle_mobile__framework__proto__var_type__type__enum_values_by_number,
0, /* field[0] = element_type */ 19,
}; paddle_mobile__framework__proto__var_type__type__enum_values_by_name,
static const ProtobufCIntRange paddle_mobile__framework__proto__var_type__tuple__number_ranges[1 + 1] = 1,
{ paddle_mobile__framework__proto__var_type__type__value_ranges,
{ 1, 0 }, NULL,
{ 0, 1 } NULL,
}; NULL,
const ProtobufCMessageDescriptor paddle_mobile__framework__proto__var_type__tuple__descriptor = NULL /* reserved[1234] */
{ };
PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, static const ProtobufCFieldDescriptor
"paddle_mobile.framework.proto.VarType.Tuple", paddle_mobile__framework__proto__var_type__field_descriptors[7] = {
"Tuple", {
"PaddleMobile__Framework__Proto__VarType__Tuple", "type", 1, PROTOBUF_C_LABEL_REQUIRED, PROTOBUF_C_TYPE_ENUM,
"paddle_mobile.framework.proto", 0, /* quantifier_offset */
sizeof(PaddleMobile__Framework__Proto__VarType__Tuple), offsetof(PaddleMobile__Framework__Proto__VarType, type),
1, &paddle_mobile__framework__proto__var_type__type__descriptor, NULL,
paddle_mobile__framework__proto__var_type__tuple__field_descriptors, 0, /* flags */
paddle_mobile__framework__proto__var_type__tuple__field_indices_by_name, 0, NULL, NULL /* reserved1,reserved2, etc */
1, paddle_mobile__framework__proto__var_type__tuple__number_ranges, },
(ProtobufCMessageInit) paddle_mobile__framework__proto__var_type__tuple__init, {
NULL,NULL,NULL /* reserved[123] */ "selected_rows", 2, PROTOBUF_C_LABEL_OPTIONAL,
}; PROTOBUF_C_TYPE_MESSAGE, 0, /* quantifier_offset */
static const ProtobufCEnumValue paddle_mobile__framework__proto__var_type__type__enum_values_by_number[19] = offsetof(PaddleMobile__Framework__Proto__VarType, selected_rows),
{ &paddle_mobile__framework__proto__var_type__tensor_desc__descriptor,
{ "BOOL", "PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__BOOL", 0 }, NULL, 0, /* flags */
{ "INT16", "PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__INT16", 1 }, 0, NULL, NULL /* reserved1,reserved2, etc */
{ "INT32", "PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__INT32", 2 }, },
{ "INT64", "PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__INT64", 3 }, {
{ "FP16", "PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__FP16", 4 }, "lod_tensor", 3, PROTOBUF_C_LABEL_OPTIONAL, PROTOBUF_C_TYPE_MESSAGE,
{ "FP32", "PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__FP32", 5 }, 0, /* quantifier_offset */
{ "FP64", "PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__FP64", 6 }, offsetof(PaddleMobile__Framework__Proto__VarType, lod_tensor),
{ "LOD_TENSOR", "PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__LOD_TENSOR", 7 }, &paddle_mobile__framework__proto__var_type__lo_dtensor_desc__descriptor,
{ "SELECTED_ROWS", "PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__SELECTED_ROWS", 8 }, NULL, 0, /* flags */
{ "FEED_MINIBATCH", "PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__FEED_MINIBATCH", 9 }, 0, NULL, NULL /* reserved1,reserved2, etc */
{ "FETCH_LIST", "PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__FETCH_LIST", 10 }, },
{ "STEP_SCOPES", "PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__STEP_SCOPES", 11 }, {
{ "LOD_RANK_TABLE", "PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__LOD_RANK_TABLE", 12 }, "tensor_array", 4, PROTOBUF_C_LABEL_OPTIONAL,
{ "LOD_TENSOR_ARRAY", "PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__LOD_TENSOR_ARRAY", 13 }, PROTOBUF_C_TYPE_MESSAGE, 0, /* quantifier_offset */
{ "PLACE_LIST", "PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__PLACE_LIST", 14 }, offsetof(PaddleMobile__Framework__Proto__VarType, tensor_array),
{ "READER", "PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__READER", 15 }, &paddle_mobile__framework__proto__var_type__lo_dtensor_array_desc__descriptor,
{ "CHANNEL", "PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__CHANNEL", 16 }, NULL, 0, /* flags */
{ "RAW", "PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__RAW", 17 }, 0, NULL, NULL /* reserved1,reserved2, etc */
{ "TUPLE", "PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__TUPLE", 18 }, },
}; {
static const ProtobufCIntRange paddle_mobile__framework__proto__var_type__type__value_ranges[] = { "reader", 5, PROTOBUF_C_LABEL_OPTIONAL, PROTOBUF_C_TYPE_MESSAGE,
{0, 0},{0, 19} 0, /* quantifier_offset */
}; offsetof(PaddleMobile__Framework__Proto__VarType, reader),
static const ProtobufCEnumValueIndex paddle_mobile__framework__proto__var_type__type__enum_values_by_name[19] = &paddle_mobile__framework__proto__var_type__reader_desc__descriptor,
{ NULL, 0, /* flags */
{ "BOOL", 0 }, 0, NULL, NULL /* reserved1,reserved2, etc */
{ "CHANNEL", 16 }, },
{ "FEED_MINIBATCH", 9 }, {
{ "FETCH_LIST", 10 }, "channel", 6, PROTOBUF_C_LABEL_OPTIONAL, PROTOBUF_C_TYPE_MESSAGE,
{ "FP16", 4 }, 0, /* quantifier_offset */
{ "FP32", 5 }, offsetof(PaddleMobile__Framework__Proto__VarType, channel),
{ "FP64", 6 }, &paddle_mobile__framework__proto__var_type__channel_desc__descriptor,
{ "INT16", 1 }, NULL, 0, /* flags */
{ "INT32", 2 }, 0, NULL, NULL /* reserved1,reserved2, etc */
{ "INT64", 3 }, },
{ "LOD_RANK_TABLE", 12 }, {
{ "LOD_TENSOR", 7 }, "tuple", 7, PROTOBUF_C_LABEL_OPTIONAL, PROTOBUF_C_TYPE_MESSAGE,
{ "LOD_TENSOR_ARRAY", 13 }, 0, /* quantifier_offset */
{ "PLACE_LIST", 14 }, offsetof(PaddleMobile__Framework__Proto__VarType, tuple),
{ "RAW", 17 }, &paddle_mobile__framework__proto__var_type__tuple__descriptor, NULL,
{ "READER", 15 }, 0, /* flags */
{ "SELECTED_ROWS", 8 }, 0, NULL, NULL /* reserved1,reserved2, etc */
{ "STEP_SCOPES", 11 }, },
{ "TUPLE", 18 }, };
}; static const unsigned
const ProtobufCEnumDescriptor paddle_mobile__framework__proto__var_type__type__descriptor = paddle_mobile__framework__proto__var_type__field_indices_by_name[] = {
{ 5, /* field[5] = channel */
PROTOBUF_C__ENUM_DESCRIPTOR_MAGIC, 2, /* field[2] = lod_tensor */
"paddle_mobile.framework.proto.VarType.Type", 4, /* field[4] = reader */
"Type", 1, /* field[1] = selected_rows */
"PaddleMobile__Framework__Proto__VarType__Type", 3, /* field[3] = tensor_array */
"paddle_mobile.framework.proto", 6, /* field[6] = tuple */
19, 0, /* field[0] = type */
paddle_mobile__framework__proto__var_type__type__enum_values_by_number, };
19, static const ProtobufCIntRange
paddle_mobile__framework__proto__var_type__type__enum_values_by_name, paddle_mobile__framework__proto__var_type__number_ranges[1 + 1] = {{1, 0},
1, {0, 7}};
paddle_mobile__framework__proto__var_type__type__value_ranges, const ProtobufCMessageDescriptor
NULL,NULL,NULL,NULL /* reserved[1234] */ paddle_mobile__framework__proto__var_type__descriptor = {
}; PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
static const ProtobufCFieldDescriptor paddle_mobile__framework__proto__var_type__field_descriptors[7] = "paddle_mobile.framework.proto.VarType",
{ "VarType",
{ "PaddleMobile__Framework__Proto__VarType",
"type", "paddle_mobile.framework.proto",
1, sizeof(PaddleMobile__Framework__Proto__VarType),
PROTOBUF_C_LABEL_REQUIRED, 7,
PROTOBUF_C_TYPE_ENUM, paddle_mobile__framework__proto__var_type__field_descriptors,
0, /* quantifier_offset */ paddle_mobile__framework__proto__var_type__field_indices_by_name,
offsetof(PaddleMobile__Framework__Proto__VarType, type), 1,
&paddle_mobile__framework__proto__var_type__type__descriptor, paddle_mobile__framework__proto__var_type__number_ranges,
NULL, (ProtobufCMessageInit)paddle_mobile__framework__proto__var_type__init,
0, /* flags */ NULL,
0,NULL,NULL /* reserved1,reserved2, etc */ NULL,
}, NULL /* reserved[123] */
{ };
"selected_rows", static const protobuf_c_boolean
2, paddle_mobile__framework__proto__var_desc__persistable__default_value = 0;
PROTOBUF_C_LABEL_OPTIONAL, static const ProtobufCFieldDescriptor
PROTOBUF_C_TYPE_MESSAGE, paddle_mobile__framework__proto__var_desc__field_descriptors[3] = {
0, /* quantifier_offset */ {
offsetof(PaddleMobile__Framework__Proto__VarType, selected_rows), "name", 1, PROTOBUF_C_LABEL_REQUIRED, PROTOBUF_C_TYPE_STRING,
&paddle_mobile__framework__proto__var_type__tensor_desc__descriptor, 0, /* quantifier_offset */
NULL, offsetof(PaddleMobile__Framework__Proto__VarDesc, name), NULL, NULL,
0, /* flags */ 0, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */ 0, NULL, NULL /* reserved1,reserved2, etc */
}, },
{ {
"lod_tensor", "type", 2, PROTOBUF_C_LABEL_REQUIRED, PROTOBUF_C_TYPE_MESSAGE,
3, 0, /* quantifier_offset */
PROTOBUF_C_LABEL_OPTIONAL, offsetof(PaddleMobile__Framework__Proto__VarDesc, type),
PROTOBUF_C_TYPE_MESSAGE, &paddle_mobile__framework__proto__var_type__descriptor, NULL,
0, /* quantifier_offset */ 0, /* flags */
offsetof(PaddleMobile__Framework__Proto__VarType, lod_tensor), 0, NULL, NULL /* reserved1,reserved2, etc */
&paddle_mobile__framework__proto__var_type__lo_dtensor_desc__descriptor, },
NULL, {
0, /* flags */ "persistable", 3, PROTOBUF_C_LABEL_OPTIONAL, PROTOBUF_C_TYPE_BOOL,
0,NULL,NULL /* reserved1,reserved2, etc */ offsetof(PaddleMobile__Framework__Proto__VarDesc, has_persistable),
}, offsetof(PaddleMobile__Framework__Proto__VarDesc, persistable),
{ NULL,
"tensor_array", &paddle_mobile__framework__proto__var_desc__persistable__default_value,
4, 0, /* flags */
PROTOBUF_C_LABEL_OPTIONAL, 0, NULL, NULL /* reserved1,reserved2, etc */
PROTOBUF_C_TYPE_MESSAGE, },
0, /* quantifier_offset */ };
offsetof(PaddleMobile__Framework__Proto__VarType, tensor_array), static const unsigned
&paddle_mobile__framework__proto__var_type__lo_dtensor_array_desc__descriptor, paddle_mobile__framework__proto__var_desc__field_indices_by_name[] = {
NULL, 0, /* field[0] = name */
0, /* flags */ 2, /* field[2] = persistable */
0,NULL,NULL /* reserved1,reserved2, etc */ 1, /* field[1] = type */
}, };
{ static const ProtobufCIntRange
"reader", paddle_mobile__framework__proto__var_desc__number_ranges[1 + 1] = {{1, 0},
5, {0, 3}};
PROTOBUF_C_LABEL_OPTIONAL, const ProtobufCMessageDescriptor
PROTOBUF_C_TYPE_MESSAGE, paddle_mobile__framework__proto__var_desc__descriptor = {
0, /* quantifier_offset */ PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
offsetof(PaddleMobile__Framework__Proto__VarType, reader), "paddle_mobile.framework.proto.VarDesc",
&paddle_mobile__framework__proto__var_type__reader_desc__descriptor, "VarDesc",
NULL, "PaddleMobile__Framework__Proto__VarDesc",
0, /* flags */ "paddle_mobile.framework.proto",
0,NULL,NULL /* reserved1,reserved2, etc */ sizeof(PaddleMobile__Framework__Proto__VarDesc),
}, 3,
{ paddle_mobile__framework__proto__var_desc__field_descriptors,
"channel", paddle_mobile__framework__proto__var_desc__field_indices_by_name,
6, 1,
PROTOBUF_C_LABEL_OPTIONAL, paddle_mobile__framework__proto__var_desc__number_ranges,
PROTOBUF_C_TYPE_MESSAGE, (ProtobufCMessageInit)paddle_mobile__framework__proto__var_desc__init,
0, /* quantifier_offset */ NULL,
offsetof(PaddleMobile__Framework__Proto__VarType, channel), NULL,
&paddle_mobile__framework__proto__var_type__channel_desc__descriptor, NULL /* reserved[123] */
NULL, };
0, /* flags */ static const int32_t
0,NULL,NULL /* reserved1,reserved2, etc */ paddle_mobile__framework__proto__block_desc__forward_block_idx__default_value =
}, -1;
{ static const ProtobufCFieldDescriptor
"tuple", paddle_mobile__framework__proto__block_desc__field_descriptors[5] = {
7, {
PROTOBUF_C_LABEL_OPTIONAL, "idx", 1, PROTOBUF_C_LABEL_REQUIRED, PROTOBUF_C_TYPE_INT32,
PROTOBUF_C_TYPE_MESSAGE, 0, /* quantifier_offset */
0, /* quantifier_offset */ offsetof(PaddleMobile__Framework__Proto__BlockDesc, idx), NULL,
offsetof(PaddleMobile__Framework__Proto__VarType, tuple), NULL, 0, /* flags */
&paddle_mobile__framework__proto__var_type__tuple__descriptor, 0, NULL, NULL /* reserved1,reserved2, etc */
NULL, },
0, /* flags */ {
0,NULL,NULL /* reserved1,reserved2, etc */ "parent_idx", 2, PROTOBUF_C_LABEL_REQUIRED, PROTOBUF_C_TYPE_INT32,
}, 0, /* quantifier_offset */
}; offsetof(PaddleMobile__Framework__Proto__BlockDesc, parent_idx),
static const unsigned paddle_mobile__framework__proto__var_type__field_indices_by_name[] = { NULL, NULL, 0, /* flags */
5, /* field[5] = channel */ 0, NULL, NULL /* reserved1,reserved2, etc */
2, /* field[2] = lod_tensor */ },
4, /* field[4] = reader */ {
1, /* field[1] = selected_rows */ "vars", 3, PROTOBUF_C_LABEL_REPEATED, PROTOBUF_C_TYPE_MESSAGE,
3, /* field[3] = tensor_array */ offsetof(PaddleMobile__Framework__Proto__BlockDesc, n_vars),
6, /* field[6] = tuple */ offsetof(PaddleMobile__Framework__Proto__BlockDesc, vars),
0, /* field[0] = type */ &paddle_mobile__framework__proto__var_desc__descriptor, NULL,
}; 0, /* flags */
static const ProtobufCIntRange paddle_mobile__framework__proto__var_type__number_ranges[1 + 1] = 0, NULL, NULL /* reserved1,reserved2, etc */
{ },
{ 1, 0 }, {
{ 0, 7 } "ops", 4, PROTOBUF_C_LABEL_REPEATED, PROTOBUF_C_TYPE_MESSAGE,
}; offsetof(PaddleMobile__Framework__Proto__BlockDesc, n_ops),
const ProtobufCMessageDescriptor paddle_mobile__framework__proto__var_type__descriptor = offsetof(PaddleMobile__Framework__Proto__BlockDesc, ops),
{ &paddle_mobile__framework__proto__op_desc__descriptor, NULL,
PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, 0, /* flags */
"paddle_mobile.framework.proto.VarType", 0, NULL, NULL /* reserved1,reserved2, etc */
"VarType", },
"PaddleMobile__Framework__Proto__VarType", {
"paddle_mobile.framework.proto", "forward_block_idx", 5, PROTOBUF_C_LABEL_OPTIONAL,
sizeof(PaddleMobile__Framework__Proto__VarType), PROTOBUF_C_TYPE_INT32,
7, offsetof(PaddleMobile__Framework__Proto__BlockDesc,
paddle_mobile__framework__proto__var_type__field_descriptors, has_forward_block_idx),
paddle_mobile__framework__proto__var_type__field_indices_by_name, offsetof(PaddleMobile__Framework__Proto__BlockDesc,
1, paddle_mobile__framework__proto__var_type__number_ranges, forward_block_idx),
(ProtobufCMessageInit) paddle_mobile__framework__proto__var_type__init, NULL,
NULL,NULL,NULL /* reserved[123] */ &paddle_mobile__framework__proto__block_desc__forward_block_idx__default_value,
}; 0, /* flags */
static const protobuf_c_boolean paddle_mobile__framework__proto__var_desc__persistable__default_value = 0; 0, NULL, NULL /* reserved1,reserved2, etc */
static const ProtobufCFieldDescriptor paddle_mobile__framework__proto__var_desc__field_descriptors[3] = },
{ };
{ static const unsigned
"name", paddle_mobile__framework__proto__block_desc__field_indices_by_name[] = {
1, 4, /* field[4] = forward_block_idx */
PROTOBUF_C_LABEL_REQUIRED, 0, /* field[0] = idx */
PROTOBUF_C_TYPE_STRING, 3, /* field[3] = ops */
0, /* quantifier_offset */ 1, /* field[1] = parent_idx */
offsetof(PaddleMobile__Framework__Proto__VarDesc, name), 2, /* field[2] = vars */
NULL, };
NULL, static const ProtobufCIntRange
0, /* flags */ paddle_mobile__framework__proto__block_desc__number_ranges[1 + 1] = {
0,NULL,NULL /* reserved1,reserved2, etc */ {1, 0}, {0, 5}};
}, const ProtobufCMessageDescriptor
{ paddle_mobile__framework__proto__block_desc__descriptor = {
"type", PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
2, "paddle_mobile.framework.proto.BlockDesc",
PROTOBUF_C_LABEL_REQUIRED, "BlockDesc",
PROTOBUF_C_TYPE_MESSAGE, "PaddleMobile__Framework__Proto__BlockDesc",
0, /* quantifier_offset */ "paddle_mobile.framework.proto",
offsetof(PaddleMobile__Framework__Proto__VarDesc, type), sizeof(PaddleMobile__Framework__Proto__BlockDesc),
&paddle_mobile__framework__proto__var_type__descriptor, 5,
NULL, paddle_mobile__framework__proto__block_desc__field_descriptors,
0, /* flags */ paddle_mobile__framework__proto__block_desc__field_indices_by_name,
0,NULL,NULL /* reserved1,reserved2, etc */ 1,
}, paddle_mobile__framework__proto__block_desc__number_ranges,
{ (ProtobufCMessageInit)paddle_mobile__framework__proto__block_desc__init,
"persistable", NULL,
3, NULL,
PROTOBUF_C_LABEL_OPTIONAL, NULL /* reserved[123] */
PROTOBUF_C_TYPE_BOOL, };
offsetof(PaddleMobile__Framework__Proto__VarDesc, has_persistable), static const ProtobufCFieldDescriptor
offsetof(PaddleMobile__Framework__Proto__VarDesc, persistable), paddle_mobile__framework__proto__program_desc__field_descriptors[1] = {
NULL, {
&paddle_mobile__framework__proto__var_desc__persistable__default_value, "blocks", 1, PROTOBUF_C_LABEL_REPEATED, PROTOBUF_C_TYPE_MESSAGE,
0, /* flags */ offsetof(PaddleMobile__Framework__Proto__ProgramDesc, n_blocks),
0,NULL,NULL /* reserved1,reserved2, etc */ offsetof(PaddleMobile__Framework__Proto__ProgramDesc, blocks),
}, &paddle_mobile__framework__proto__block_desc__descriptor, NULL,
}; 0, /* flags */
static const unsigned paddle_mobile__framework__proto__var_desc__field_indices_by_name[] = { 0, NULL, NULL /* reserved1,reserved2, etc */
0, /* field[0] = name */ },
2, /* field[2] = persistable */ };
1, /* field[1] = type */ static const unsigned
}; paddle_mobile__framework__proto__program_desc__field_indices_by_name[] = {
static const ProtobufCIntRange paddle_mobile__framework__proto__var_desc__number_ranges[1 + 1] = 0, /* field[0] = blocks */
{ };
{ 1, 0 }, static const ProtobufCIntRange
{ 0, 3 } paddle_mobile__framework__proto__program_desc__number_ranges[1 + 1] = {
}; {1, 0}, {0, 1}};
const ProtobufCMessageDescriptor paddle_mobile__framework__proto__var_desc__descriptor = const ProtobufCMessageDescriptor
{ paddle_mobile__framework__proto__program_desc__descriptor = {
PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
"paddle_mobile.framework.proto.VarDesc", "paddle_mobile.framework.proto.ProgramDesc",
"VarDesc", "ProgramDesc",
"PaddleMobile__Framework__Proto__VarDesc", "PaddleMobile__Framework__Proto__ProgramDesc",
"paddle_mobile.framework.proto", "paddle_mobile.framework.proto",
sizeof(PaddleMobile__Framework__Proto__VarDesc), sizeof(PaddleMobile__Framework__Proto__ProgramDesc),
3, 1,
paddle_mobile__framework__proto__var_desc__field_descriptors, paddle_mobile__framework__proto__program_desc__field_descriptors,
paddle_mobile__framework__proto__var_desc__field_indices_by_name, paddle_mobile__framework__proto__program_desc__field_indices_by_name,
1, paddle_mobile__framework__proto__var_desc__number_ranges, 1,
(ProtobufCMessageInit) paddle_mobile__framework__proto__var_desc__init, paddle_mobile__framework__proto__program_desc__number_ranges,
NULL,NULL,NULL /* reserved[123] */ (ProtobufCMessageInit)
}; paddle_mobile__framework__proto__program_desc__init,
static const int32_t paddle_mobile__framework__proto__block_desc__forward_block_idx__default_value = -1; NULL,
static const ProtobufCFieldDescriptor paddle_mobile__framework__proto__block_desc__field_descriptors[5] = NULL,
{ NULL /* reserved[123] */
{ };
"idx", static const ProtobufCEnumValue
1, paddle_mobile__framework__proto__attr_type__enum_values_by_number[10] = {
PROTOBUF_C_LABEL_REQUIRED, {"INT", "PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__INT", 0},
PROTOBUF_C_TYPE_INT32, {"FLOAT", "PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__FLOAT", 1},
0, /* quantifier_offset */ {"STRING", "PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__STRING", 2},
offsetof(PaddleMobile__Framework__Proto__BlockDesc, idx), {"INTS", "PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__INTS", 3},
NULL, {"FLOATS", "PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__FLOATS", 4},
NULL, {"STRINGS", "PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__STRINGS", 5},
0, /* flags */ {"BOOLEAN", "PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__BOOLEAN", 6},
0,NULL,NULL /* reserved1,reserved2, etc */ {"BOOLEANS", "PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__BOOLEANS", 7},
}, {"BLOCK", "PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__BLOCK", 8},
{ {"LONG", "PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__LONG", 9},
"parent_idx", };
2, static const ProtobufCIntRange
PROTOBUF_C_LABEL_REQUIRED, paddle_mobile__framework__proto__attr_type__value_ranges[] = {{0, 0},
PROTOBUF_C_TYPE_INT32, {0, 10}};
0, /* quantifier_offset */ static const ProtobufCEnumValueIndex
offsetof(PaddleMobile__Framework__Proto__BlockDesc, parent_idx), paddle_mobile__framework__proto__attr_type__enum_values_by_name[10] = {
NULL, {"BLOCK", 8}, {"BOOLEAN", 6}, {"BOOLEANS", 7}, {"FLOAT", 1},
NULL, {"FLOATS", 4}, {"INT", 0}, {"INTS", 3}, {"LONG", 9},
0, /* flags */ {"STRING", 2}, {"STRINGS", 5},
0,NULL,NULL /* reserved1,reserved2, etc */ };
}, const ProtobufCEnumDescriptor
{ paddle_mobile__framework__proto__attr_type__descriptor = {
"vars", PROTOBUF_C__ENUM_DESCRIPTOR_MAGIC,
3, "paddle_mobile.framework.proto.AttrType",
PROTOBUF_C_LABEL_REPEATED, "AttrType",
PROTOBUF_C_TYPE_MESSAGE, "PaddleMobile__Framework__Proto__AttrType",
offsetof(PaddleMobile__Framework__Proto__BlockDesc, n_vars), "paddle_mobile.framework.proto",
offsetof(PaddleMobile__Framework__Proto__BlockDesc, vars), 10,
&paddle_mobile__framework__proto__var_desc__descriptor, paddle_mobile__framework__proto__attr_type__enum_values_by_number,
NULL, 10,
0, /* flags */ paddle_mobile__framework__proto__attr_type__enum_values_by_name,
0,NULL,NULL /* reserved1,reserved2, etc */ 1,
}, paddle_mobile__framework__proto__attr_type__value_ranges,
{ NULL,
"ops", NULL,
4, NULL,
PROTOBUF_C_LABEL_REPEATED, NULL /* reserved[1234] */
PROTOBUF_C_TYPE_MESSAGE,
offsetof(PaddleMobile__Framework__Proto__BlockDesc, n_ops),
offsetof(PaddleMobile__Framework__Proto__BlockDesc, ops),
&paddle_mobile__framework__proto__op_desc__descriptor,
NULL,
0, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */
},
{
"forward_block_idx",
5,
PROTOBUF_C_LABEL_OPTIONAL,
PROTOBUF_C_TYPE_INT32,
offsetof(PaddleMobile__Framework__Proto__BlockDesc, has_forward_block_idx),
offsetof(PaddleMobile__Framework__Proto__BlockDesc, forward_block_idx),
NULL,
&paddle_mobile__framework__proto__block_desc__forward_block_idx__default_value,
0, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */
},
};
static const unsigned paddle_mobile__framework__proto__block_desc__field_indices_by_name[] = {
4, /* field[4] = forward_block_idx */
0, /* field[0] = idx */
3, /* field[3] = ops */
1, /* field[1] = parent_idx */
2, /* field[2] = vars */
};
static const ProtobufCIntRange paddle_mobile__framework__proto__block_desc__number_ranges[1 + 1] =
{
{ 1, 0 },
{ 0, 5 }
};
const ProtobufCMessageDescriptor paddle_mobile__framework__proto__block_desc__descriptor =
{
PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
"paddle_mobile.framework.proto.BlockDesc",
"BlockDesc",
"PaddleMobile__Framework__Proto__BlockDesc",
"paddle_mobile.framework.proto",
sizeof(PaddleMobile__Framework__Proto__BlockDesc),
5,
paddle_mobile__framework__proto__block_desc__field_descriptors,
paddle_mobile__framework__proto__block_desc__field_indices_by_name,
1, paddle_mobile__framework__proto__block_desc__number_ranges,
(ProtobufCMessageInit) paddle_mobile__framework__proto__block_desc__init,
NULL,NULL,NULL /* reserved[123] */
};
static const ProtobufCFieldDescriptor paddle_mobile__framework__proto__program_desc__field_descriptors[1] =
{
{
"blocks",
1,
PROTOBUF_C_LABEL_REPEATED,
PROTOBUF_C_TYPE_MESSAGE,
offsetof(PaddleMobile__Framework__Proto__ProgramDesc, n_blocks),
offsetof(PaddleMobile__Framework__Proto__ProgramDesc, blocks),
&paddle_mobile__framework__proto__block_desc__descriptor,
NULL,
0, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */
},
};
static const unsigned paddle_mobile__framework__proto__program_desc__field_indices_by_name[] = {
0, /* field[0] = blocks */
};
static const ProtobufCIntRange paddle_mobile__framework__proto__program_desc__number_ranges[1 + 1] =
{
{ 1, 0 },
{ 0, 1 }
};
const ProtobufCMessageDescriptor paddle_mobile__framework__proto__program_desc__descriptor =
{
PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
"paddle_mobile.framework.proto.ProgramDesc",
"ProgramDesc",
"PaddleMobile__Framework__Proto__ProgramDesc",
"paddle_mobile.framework.proto",
sizeof(PaddleMobile__Framework__Proto__ProgramDesc),
1,
paddle_mobile__framework__proto__program_desc__field_descriptors,
paddle_mobile__framework__proto__program_desc__field_indices_by_name,
1, paddle_mobile__framework__proto__program_desc__number_ranges,
(ProtobufCMessageInit) paddle_mobile__framework__proto__program_desc__init,
NULL,NULL,NULL /* reserved[123] */
};
static const ProtobufCEnumValue paddle_mobile__framework__proto__attr_type__enum_values_by_number[10] =
{
{ "INT", "PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__INT", 0 },
{ "FLOAT", "PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__FLOAT", 1 },
{ "STRING", "PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__STRING", 2 },
{ "INTS", "PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__INTS", 3 },
{ "FLOATS", "PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__FLOATS", 4 },
{ "STRINGS", "PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__STRINGS", 5 },
{ "BOOLEAN", "PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__BOOLEAN", 6 },
{ "BOOLEANS", "PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__BOOLEANS", 7 },
{ "BLOCK", "PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__BLOCK", 8 },
{ "LONG", "PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__LONG", 9 },
};
static const ProtobufCIntRange paddle_mobile__framework__proto__attr_type__value_ranges[] = {
{0, 0},{0, 10}
};
static const ProtobufCEnumValueIndex paddle_mobile__framework__proto__attr_type__enum_values_by_name[10] =
{
{ "BLOCK", 8 },
{ "BOOLEAN", 6 },
{ "BOOLEANS", 7 },
{ "FLOAT", 1 },
{ "FLOATS", 4 },
{ "INT", 0 },
{ "INTS", 3 },
{ "LONG", 9 },
{ "STRING", 2 },
{ "STRINGS", 5 },
};
const ProtobufCEnumDescriptor paddle_mobile__framework__proto__attr_type__descriptor =
{
PROTOBUF_C__ENUM_DESCRIPTOR_MAGIC,
"paddle_mobile.framework.proto.AttrType",
"AttrType",
"PaddleMobile__Framework__Proto__AttrType",
"paddle_mobile.framework.proto",
10,
paddle_mobile__framework__proto__attr_type__enum_values_by_number,
10,
paddle_mobile__framework__proto__attr_type__enum_values_by_name,
1,
paddle_mobile__framework__proto__attr_type__value_ranges,
NULL,NULL,NULL,NULL /* reserved[1234] */
}; };
...@@ -14,24 +14,38 @@ PROTOBUF_C__BEGIN_DECLS ...@@ -14,24 +14,38 @@ PROTOBUF_C__BEGIN_DECLS
# 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. # 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 #endif
typedef struct _PaddleMobile__Framework__Proto__OpDesc
typedef struct _PaddleMobile__Framework__Proto__OpDesc PaddleMobile__Framework__Proto__OpDesc; PaddleMobile__Framework__Proto__OpDesc;
typedef struct _PaddleMobile__Framework__Proto__OpDesc__Attr PaddleMobile__Framework__Proto__OpDesc__Attr; typedef struct _PaddleMobile__Framework__Proto__OpDesc__Attr
typedef struct _PaddleMobile__Framework__Proto__OpDesc__Var PaddleMobile__Framework__Proto__OpDesc__Var; PaddleMobile__Framework__Proto__OpDesc__Attr;
typedef struct _PaddleMobile__Framework__Proto__OpProto PaddleMobile__Framework__Proto__OpProto; typedef struct _PaddleMobile__Framework__Proto__OpDesc__Var
typedef struct _PaddleMobile__Framework__Proto__OpProto__Var PaddleMobile__Framework__Proto__OpProto__Var; PaddleMobile__Framework__Proto__OpDesc__Var;
typedef struct _PaddleMobile__Framework__Proto__OpProto__Attr PaddleMobile__Framework__Proto__OpProto__Attr; typedef struct _PaddleMobile__Framework__Proto__OpProto
typedef struct _PaddleMobile__Framework__Proto__VarType PaddleMobile__Framework__Proto__VarType; PaddleMobile__Framework__Proto__OpProto;
typedef struct _PaddleMobile__Framework__Proto__VarType__TensorDesc PaddleMobile__Framework__Proto__VarType__TensorDesc; typedef struct _PaddleMobile__Framework__Proto__OpProto__Var
typedef struct _PaddleMobile__Framework__Proto__VarType__LoDTensorDesc PaddleMobile__Framework__Proto__VarType__LoDTensorDesc; PaddleMobile__Framework__Proto__OpProto__Var;
typedef struct _PaddleMobile__Framework__Proto__VarType__LoDTensorArrayDesc PaddleMobile__Framework__Proto__VarType__LoDTensorArrayDesc; typedef struct _PaddleMobile__Framework__Proto__OpProto__Attr
typedef struct _PaddleMobile__Framework__Proto__VarType__ReaderDesc PaddleMobile__Framework__Proto__VarType__ReaderDesc; PaddleMobile__Framework__Proto__OpProto__Attr;
typedef struct _PaddleMobile__Framework__Proto__VarType__ChannelDesc PaddleMobile__Framework__Proto__VarType__ChannelDesc; typedef struct _PaddleMobile__Framework__Proto__VarType
typedef struct _PaddleMobile__Framework__Proto__VarType__Tuple PaddleMobile__Framework__Proto__VarType__Tuple; PaddleMobile__Framework__Proto__VarType;
typedef struct _PaddleMobile__Framework__Proto__VarDesc PaddleMobile__Framework__Proto__VarDesc; typedef struct _PaddleMobile__Framework__Proto__VarType__TensorDesc
typedef struct _PaddleMobile__Framework__Proto__BlockDesc PaddleMobile__Framework__Proto__BlockDesc; PaddleMobile__Framework__Proto__VarType__TensorDesc;
typedef struct _PaddleMobile__Framework__Proto__ProgramDesc PaddleMobile__Framework__Proto__ProgramDesc; typedef struct _PaddleMobile__Framework__Proto__VarType__LoDTensorDesc
PaddleMobile__Framework__Proto__VarType__LoDTensorDesc;
typedef struct _PaddleMobile__Framework__Proto__VarType__LoDTensorArrayDesc
PaddleMobile__Framework__Proto__VarType__LoDTensorArrayDesc;
typedef struct _PaddleMobile__Framework__Proto__VarType__ReaderDesc
PaddleMobile__Framework__Proto__VarType__ReaderDesc;
typedef struct _PaddleMobile__Framework__Proto__VarType__ChannelDesc
PaddleMobile__Framework__Proto__VarType__ChannelDesc;
typedef struct _PaddleMobile__Framework__Proto__VarType__Tuple
PaddleMobile__Framework__Proto__VarType__Tuple;
typedef struct _PaddleMobile__Framework__Proto__VarDesc
PaddleMobile__Framework__Proto__VarDesc;
typedef struct _PaddleMobile__Framework__Proto__BlockDesc
PaddleMobile__Framework__Proto__BlockDesc;
typedef struct _PaddleMobile__Framework__Proto__ProgramDesc
PaddleMobile__Framework__Proto__ProgramDesc;
/* --- enums --- */ /* --- enums --- */
...@@ -65,8 +79,9 @@ typedef enum _PaddleMobile__Framework__Proto__VarType__Type { ...@@ -65,8 +79,9 @@ typedef enum _PaddleMobile__Framework__Proto__VarType__Type {
* in operators like nccl_op * in operators like nccl_op
*/ */
PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__RAW = 17, PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__RAW = 17,
PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__TUPLE = 18 PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__TUPLE =
PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE) 18 PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(
PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE)
} PaddleMobile__Framework__Proto__VarType__Type; } PaddleMobile__Framework__Proto__VarType__Type;
typedef enum _PaddleMobile__Framework__Proto__AttrType { typedef enum _PaddleMobile__Framework__Proto__AttrType {
PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__INT = 0, PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__INT = 0,
...@@ -78,14 +93,14 @@ typedef enum _PaddleMobile__Framework__Proto__AttrType { ...@@ -78,14 +93,14 @@ typedef enum _PaddleMobile__Framework__Proto__AttrType {
PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__BOOLEAN = 6, PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__BOOLEAN = 6,
PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__BOOLEANS = 7, PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__BOOLEANS = 7,
PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__BLOCK = 8, PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__BLOCK = 8,
PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__LONG = 9 PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__LONG =
PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE) 9 PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(
PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE)
} PaddleMobile__Framework__Proto__AttrType; } PaddleMobile__Framework__Proto__AttrType;
/* --- messages --- */ /* --- messages --- */
struct _PaddleMobile__Framework__Proto__OpDesc__Attr struct _PaddleMobile__Framework__Proto__OpDesc__Attr {
{
ProtobufCMessage base; ProtobufCMessage base;
char *name; char *name;
PaddleMobile__Framework__Proto__AttrType type; PaddleMobile__Framework__Proto__AttrType type;
...@@ -109,29 +124,32 @@ struct _PaddleMobile__Framework__Proto__OpDesc__Attr ...@@ -109,29 +124,32 @@ struct _PaddleMobile__Framework__Proto__OpDesc__Attr
protobuf_c_boolean has_l; protobuf_c_boolean has_l;
int64_t l; int64_t l;
}; };
#define PADDLE_MOBILE__FRAMEWORK__PROTO__OP_DESC__ATTR__INIT \ #define PADDLE_MOBILE__FRAMEWORK__PROTO__OP_DESC__ATTR__INIT \
{ PROTOBUF_C_MESSAGE_INIT (&paddle_mobile__framework__proto__op_desc__attr__descriptor) \ { \
, NULL, PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__INT, 0, 0, 0, 0, NULL, 0,NULL, 0,NULL, 0,NULL, 0, 0, 0,NULL, 0, 0, 0, 0 } PROTOBUF_C_MESSAGE_INIT( \
&paddle_mobile__framework__proto__op_desc__attr__descriptor) \
, NULL, PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__INT, 0, 0, 0, 0, NULL, \
struct _PaddleMobile__Framework__Proto__OpDesc__Var 0, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0, 0, 0, 0 \
{ }
struct _PaddleMobile__Framework__Proto__OpDesc__Var {
ProtobufCMessage base; ProtobufCMessage base;
char *parameter; char *parameter;
size_t n_arguments; size_t n_arguments;
char **arguments; char **arguments;
}; };
#define PADDLE_MOBILE__FRAMEWORK__PROTO__OP_DESC__VAR__INIT \ #define PADDLE_MOBILE__FRAMEWORK__PROTO__OP_DESC__VAR__INIT \
{ PROTOBUF_C_MESSAGE_INIT (&paddle_mobile__framework__proto__op_desc__var__descriptor) \ { \
, NULL, 0,NULL } PROTOBUF_C_MESSAGE_INIT( \
&paddle_mobile__framework__proto__op_desc__var__descriptor) \
, NULL, 0, NULL \
}
/* /*
* OpDesc describes an instance of a C++ framework::OperatorBase * OpDesc describes an instance of a C++ framework::OperatorBase
* derived class type. * derived class type.
*/ */
struct _PaddleMobile__Framework__Proto__OpDesc struct _PaddleMobile__Framework__Proto__OpDesc {
{
ProtobufCMessage base; ProtobufCMessage base;
char *type; char *type;
size_t n_inputs; size_t n_inputs;
...@@ -143,16 +161,17 @@ struct _PaddleMobile__Framework__Proto__OpDesc ...@@ -143,16 +161,17 @@ struct _PaddleMobile__Framework__Proto__OpDesc
protobuf_c_boolean has_is_target; protobuf_c_boolean has_is_target;
protobuf_c_boolean is_target; protobuf_c_boolean is_target;
}; };
#define PADDLE_MOBILE__FRAMEWORK__PROTO__OP_DESC__INIT \ #define PADDLE_MOBILE__FRAMEWORK__PROTO__OP_DESC__INIT \
{ PROTOBUF_C_MESSAGE_INIT (&paddle_mobile__framework__proto__op_desc__descriptor) \ { \
, NULL, 0,NULL, 0,NULL, 0,NULL, 0, 0 } PROTOBUF_C_MESSAGE_INIT( \
&paddle_mobile__framework__proto__op_desc__descriptor) \
, NULL, 0, NULL, 0, NULL, 0, NULL, 0, 0 \
}
/* /*
* VarProto describes the C++ type framework::Variable. * VarProto describes the C++ type framework::Variable.
*/ */
struct _PaddleMobile__Framework__Proto__OpProto__Var struct _PaddleMobile__Framework__Proto__OpProto__Var {
{
ProtobufCMessage base; ProtobufCMessage base;
char *name; char *name;
char *comment; char *comment;
...@@ -163,16 +182,17 @@ struct _PaddleMobile__Framework__Proto__OpProto__Var ...@@ -163,16 +182,17 @@ struct _PaddleMobile__Framework__Proto__OpProto__Var
protobuf_c_boolean has_dispensable; protobuf_c_boolean has_dispensable;
protobuf_c_boolean dispensable; protobuf_c_boolean dispensable;
}; };
#define PADDLE_MOBILE__FRAMEWORK__PROTO__OP_PROTO__VAR__INIT \ #define PADDLE_MOBILE__FRAMEWORK__PROTO__OP_PROTO__VAR__INIT \
{ PROTOBUF_C_MESSAGE_INIT (&paddle_mobile__framework__proto__op_proto__var__descriptor) \ { \
, NULL, NULL, 0, 0, 0, 0, 0, 0 } PROTOBUF_C_MESSAGE_INIT( \
&paddle_mobile__framework__proto__op_proto__var__descriptor) \
, NULL, NULL, 0, 0, 0, 0, 0, 0 \
}
/* /*
* AttrProto describes the C++ type Attribute. * AttrProto describes the C++ type Attribute.
*/ */
struct _PaddleMobile__Framework__Proto__OpProto__Attr struct _PaddleMobile__Framework__Proto__OpProto__Attr {
{
ProtobufCMessage base; ProtobufCMessage base;
char *name; char *name;
PaddleMobile__Framework__Proto__AttrType type; PaddleMobile__Framework__Proto__AttrType type;
...@@ -185,16 +205,17 @@ struct _PaddleMobile__Framework__Proto__OpProto__Attr ...@@ -185,16 +205,17 @@ struct _PaddleMobile__Framework__Proto__OpProto__Attr
protobuf_c_boolean has_generated; protobuf_c_boolean has_generated;
protobuf_c_boolean generated; protobuf_c_boolean generated;
}; };
#define PADDLE_MOBILE__FRAMEWORK__PROTO__OP_PROTO__ATTR__INIT \ #define PADDLE_MOBILE__FRAMEWORK__PROTO__OP_PROTO__ATTR__INIT \
{ PROTOBUF_C_MESSAGE_INIT (&paddle_mobile__framework__proto__op_proto__attr__descriptor) \ { \
, NULL, PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__INT, NULL, 0, 0 } PROTOBUF_C_MESSAGE_INIT( \
&paddle_mobile__framework__proto__op_proto__attr__descriptor) \
, NULL, PADDLE_MOBILE__FRAMEWORK__PROTO__ATTR_TYPE__INT, NULL, 0, 0 \
}
/* /*
* OpProto describes a C++ framework::OperatorBase derived class. * OpProto describes a C++ framework::OperatorBase derived class.
*/ */
struct _PaddleMobile__Framework__Proto__OpProto struct _PaddleMobile__Framework__Proto__OpProto {
{
ProtobufCMessage base; ProtobufCMessage base;
char *type; char *type;
size_t n_inputs; size_t n_inputs;
...@@ -205,13 +226,14 @@ struct _PaddleMobile__Framework__Proto__OpProto ...@@ -205,13 +226,14 @@ struct _PaddleMobile__Framework__Proto__OpProto
PaddleMobile__Framework__Proto__OpProto__Attr **attrs; PaddleMobile__Framework__Proto__OpProto__Attr **attrs;
char *comment; char *comment;
}; };
#define PADDLE_MOBILE__FRAMEWORK__PROTO__OP_PROTO__INIT \ #define PADDLE_MOBILE__FRAMEWORK__PROTO__OP_PROTO__INIT \
{ PROTOBUF_C_MESSAGE_INIT (&paddle_mobile__framework__proto__op_proto__descriptor) \ { \
, NULL, 0,NULL, 0,NULL, 0,NULL, NULL } PROTOBUF_C_MESSAGE_INIT( \
&paddle_mobile__framework__proto__op_proto__descriptor) \
, NULL, 0, NULL, 0, NULL, 0, NULL, NULL \
struct _PaddleMobile__Framework__Proto__VarType__TensorDesc }
{
struct _PaddleMobile__Framework__Proto__VarType__TensorDesc {
ProtobufCMessage base; ProtobufCMessage base;
/* /*
* Should only be PODType. Is enforced in C++ * Should only be PODType. Is enforced in C++
...@@ -223,70 +245,76 @@ struct _PaddleMobile__Framework__Proto__VarType__TensorDesc ...@@ -223,70 +245,76 @@ struct _PaddleMobile__Framework__Proto__VarType__TensorDesc
size_t n_dims; size_t n_dims;
int64_t *dims; int64_t *dims;
}; };
#define PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TENSOR_DESC__INIT \ #define PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TENSOR_DESC__INIT \
{ PROTOBUF_C_MESSAGE_INIT (&paddle_mobile__framework__proto__var_type__tensor_desc__descriptor) \ { \
, PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__BOOL, 0,NULL } PROTOBUF_C_MESSAGE_INIT( \
&paddle_mobile__framework__proto__var_type__tensor_desc__descriptor) \
, PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__BOOL, 0, NULL \
struct _PaddleMobile__Framework__Proto__VarType__LoDTensorDesc }
{
struct _PaddleMobile__Framework__Proto__VarType__LoDTensorDesc {
ProtobufCMessage base; ProtobufCMessage base;
PaddleMobile__Framework__Proto__VarType__TensorDesc *tensor; PaddleMobile__Framework__Proto__VarType__TensorDesc *tensor;
protobuf_c_boolean has_lod_level; protobuf_c_boolean has_lod_level;
int32_t lod_level; int32_t lod_level;
}; };
#define PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__LO_DTENSOR_DESC__INIT \ #define PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__LO_DTENSOR_DESC__INIT \
{ PROTOBUF_C_MESSAGE_INIT (&paddle_mobile__framework__proto__var_type__lo_dtensor_desc__descriptor) \ { \
, NULL, 0, 0 } PROTOBUF_C_MESSAGE_INIT( \
&paddle_mobile__framework__proto__var_type__lo_dtensor_desc__descriptor) \
, NULL, 0, 0 \
struct _PaddleMobile__Framework__Proto__VarType__LoDTensorArrayDesc }
{
struct _PaddleMobile__Framework__Proto__VarType__LoDTensorArrayDesc {
ProtobufCMessage base; ProtobufCMessage base;
PaddleMobile__Framework__Proto__VarType__TensorDesc *tensor; PaddleMobile__Framework__Proto__VarType__TensorDesc *tensor;
protobuf_c_boolean has_lod_level; protobuf_c_boolean has_lod_level;
int32_t lod_level; int32_t lod_level;
}; };
#define PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__LO_DTENSOR_ARRAY_DESC__INIT \ #define PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__LO_DTENSOR_ARRAY_DESC__INIT \
{ PROTOBUF_C_MESSAGE_INIT (&paddle_mobile__framework__proto__var_type__lo_dtensor_array_desc__descriptor) \ { \
, NULL, 0, 0 } PROTOBUF_C_MESSAGE_INIT( \
&paddle_mobile__framework__proto__var_type__lo_dtensor_array_desc__descriptor) \
, NULL, 0, 0 \
struct _PaddleMobile__Framework__Proto__VarType__ReaderDesc }
{
struct _PaddleMobile__Framework__Proto__VarType__ReaderDesc {
ProtobufCMessage base; ProtobufCMessage base;
size_t n_lod_tensor; size_t n_lod_tensor;
PaddleMobile__Framework__Proto__VarType__LoDTensorDesc **lod_tensor; PaddleMobile__Framework__Proto__VarType__LoDTensorDesc **lod_tensor;
}; };
#define PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__READER_DESC__INIT \ #define PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__READER_DESC__INIT \
{ PROTOBUF_C_MESSAGE_INIT (&paddle_mobile__framework__proto__var_type__reader_desc__descriptor) \ { \
, 0,NULL } PROTOBUF_C_MESSAGE_INIT( \
&paddle_mobile__framework__proto__var_type__reader_desc__descriptor) \
, 0, NULL \
struct _PaddleMobile__Framework__Proto__VarType__ChannelDesc }
{
struct _PaddleMobile__Framework__Proto__VarType__ChannelDesc {
ProtobufCMessage base; ProtobufCMessage base;
PaddleMobile__Framework__Proto__VarType__Type data_type; PaddleMobile__Framework__Proto__VarType__Type data_type;
int64_t capacity; int64_t capacity;
}; };
#define PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__CHANNEL_DESC__INIT \ #define PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__CHANNEL_DESC__INIT \
{ PROTOBUF_C_MESSAGE_INIT (&paddle_mobile__framework__proto__var_type__channel_desc__descriptor) \ { \
, PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__BOOL, 0 } PROTOBUF_C_MESSAGE_INIT( \
&paddle_mobile__framework__proto__var_type__channel_desc__descriptor) \
, PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__BOOL, 0 \
struct _PaddleMobile__Framework__Proto__VarType__Tuple }
{
struct _PaddleMobile__Framework__Proto__VarType__Tuple {
ProtobufCMessage base; ProtobufCMessage base;
size_t n_element_type; size_t n_element_type;
PaddleMobile__Framework__Proto__VarType__Type *element_type; PaddleMobile__Framework__Proto__VarType__Type *element_type;
}; };
#define PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TUPLE__INIT \ #define PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TUPLE__INIT \
{ PROTOBUF_C_MESSAGE_INIT (&paddle_mobile__framework__proto__var_type__tuple__descriptor) \ { \
, 0,NULL } PROTOBUF_C_MESSAGE_INIT( \
&paddle_mobile__framework__proto__var_type__tuple__descriptor) \
, 0, NULL \
struct _PaddleMobile__Framework__Proto__VarType }
{
struct _PaddleMobile__Framework__Proto__VarType {
ProtobufCMessage base; ProtobufCMessage base;
PaddleMobile__Framework__Proto__VarType__Type type; PaddleMobile__Framework__Proto__VarType__Type type;
PaddleMobile__Framework__Proto__VarType__TensorDesc *selected_rows; PaddleMobile__Framework__Proto__VarType__TensorDesc *selected_rows;
...@@ -296,26 +324,29 @@ struct _PaddleMobile__Framework__Proto__VarType ...@@ -296,26 +324,29 @@ struct _PaddleMobile__Framework__Proto__VarType
PaddleMobile__Framework__Proto__VarType__ChannelDesc *channel; PaddleMobile__Framework__Proto__VarType__ChannelDesc *channel;
PaddleMobile__Framework__Proto__VarType__Tuple *tuple; PaddleMobile__Framework__Proto__VarType__Tuple *tuple;
}; };
#define PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__INIT \ #define PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__INIT \
{ PROTOBUF_C_MESSAGE_INIT (&paddle_mobile__framework__proto__var_type__descriptor) \ { \
, PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__BOOL, NULL, NULL, NULL, NULL, NULL, NULL } PROTOBUF_C_MESSAGE_INIT( \
&paddle_mobile__framework__proto__var_type__descriptor) \
, PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__BOOL, NULL, NULL, NULL, \
struct _PaddleMobile__Framework__Proto__VarDesc NULL, NULL, NULL \
{ }
struct _PaddleMobile__Framework__Proto__VarDesc {
ProtobufCMessage base; ProtobufCMessage base;
char *name; char *name;
PaddleMobile__Framework__Proto__VarType *type; PaddleMobile__Framework__Proto__VarType *type;
protobuf_c_boolean has_persistable; protobuf_c_boolean has_persistable;
protobuf_c_boolean persistable; protobuf_c_boolean persistable;
}; };
#define PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_DESC__INIT \ #define PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_DESC__INIT \
{ PROTOBUF_C_MESSAGE_INIT (&paddle_mobile__framework__proto__var_desc__descriptor) \ { \
, NULL, NULL, 0, 0 } PROTOBUF_C_MESSAGE_INIT( \
&paddle_mobile__framework__proto__var_desc__descriptor) \
, NULL, NULL, 0, 0 \
struct _PaddleMobile__Framework__Proto__BlockDesc }
{
struct _PaddleMobile__Framework__Proto__BlockDesc {
ProtobufCMessage base; ProtobufCMessage base;
int32_t idx; int32_t idx;
int32_t parent_idx; int32_t parent_idx;
...@@ -326,10 +357,12 @@ struct _PaddleMobile__Framework__Proto__BlockDesc ...@@ -326,10 +357,12 @@ struct _PaddleMobile__Framework__Proto__BlockDesc
protobuf_c_boolean has_forward_block_idx; protobuf_c_boolean has_forward_block_idx;
int32_t forward_block_idx; int32_t forward_block_idx;
}; };
#define PADDLE_MOBILE__FRAMEWORK__PROTO__BLOCK_DESC__INIT \ #define PADDLE_MOBILE__FRAMEWORK__PROTO__BLOCK_DESC__INIT \
{ PROTOBUF_C_MESSAGE_INIT (&paddle_mobile__framework__proto__block_desc__descriptor) \ { \
, 0, 0, 0,NULL, 0,NULL, 0, -1 } PROTOBUF_C_MESSAGE_INIT( \
&paddle_mobile__framework__proto__block_desc__descriptor) \
, 0, 0, 0, NULL, 0, NULL, 0, -1 \
}
/* /*
* Please refer to * Please refer to
...@@ -338,203 +371,209 @@ struct _PaddleMobile__Framework__Proto__BlockDesc ...@@ -338,203 +371,209 @@ struct _PaddleMobile__Framework__Proto__BlockDesc
* TODO(panyx0718): A model can have multiple programs. Need a * TODO(panyx0718): A model can have multiple programs. Need a
* way to distinguish them. Maybe ID or name? * way to distinguish them. Maybe ID or name?
*/ */
struct _PaddleMobile__Framework__Proto__ProgramDesc struct _PaddleMobile__Framework__Proto__ProgramDesc {
{
ProtobufCMessage base; ProtobufCMessage base;
size_t n_blocks; size_t n_blocks;
PaddleMobile__Framework__Proto__BlockDesc **blocks; PaddleMobile__Framework__Proto__BlockDesc **blocks;
}; };
#define PADDLE_MOBILE__FRAMEWORK__PROTO__PROGRAM_DESC__INIT \ #define PADDLE_MOBILE__FRAMEWORK__PROTO__PROGRAM_DESC__INIT \
{ PROTOBUF_C_MESSAGE_INIT (&paddle_mobile__framework__proto__program_desc__descriptor) \ { \
, 0,NULL } PROTOBUF_C_MESSAGE_INIT( \
&paddle_mobile__framework__proto__program_desc__descriptor) \
, 0, NULL \
}
/* PaddleMobile__Framework__Proto__OpDesc__Attr methods */ /* PaddleMobile__Framework__Proto__OpDesc__Attr methods */
void paddle_mobile__framework__proto__op_desc__attr__init void paddle_mobile__framework__proto__op_desc__attr__init(
(PaddleMobile__Framework__Proto__OpDesc__Attr *message); PaddleMobile__Framework__Proto__OpDesc__Attr *message);
/* PaddleMobile__Framework__Proto__OpDesc__Var methods */ /* PaddleMobile__Framework__Proto__OpDesc__Var methods */
void paddle_mobile__framework__proto__op_desc__var__init void paddle_mobile__framework__proto__op_desc__var__init(
(PaddleMobile__Framework__Proto__OpDesc__Var *message); PaddleMobile__Framework__Proto__OpDesc__Var *message);
/* PaddleMobile__Framework__Proto__OpDesc methods */ /* PaddleMobile__Framework__Proto__OpDesc methods */
void paddle_mobile__framework__proto__op_desc__init void paddle_mobile__framework__proto__op_desc__init(
(PaddleMobile__Framework__Proto__OpDesc *message); PaddleMobile__Framework__Proto__OpDesc *message);
size_t paddle_mobile__framework__proto__op_desc__get_packed_size size_t paddle_mobile__framework__proto__op_desc__get_packed_size(
(const PaddleMobile__Framework__Proto__OpDesc *message); const PaddleMobile__Framework__Proto__OpDesc *message);
PaddleMobile__Framework__Proto__OpDesc * PaddleMobile__Framework__Proto__OpDesc *
paddle_mobile__framework__proto__op_desc__unpack paddle_mobile__framework__proto__op_desc__unpack(ProtobufCAllocator *allocator,
(ProtobufCAllocator *allocator, size_t len,
size_t len, const uint8_t *data);
const uint8_t *data); void paddle_mobile__framework__proto__op_desc__free_unpacked(
void paddle_mobile__framework__proto__op_desc__free_unpacked PaddleMobile__Framework__Proto__OpDesc *message,
(PaddleMobile__Framework__Proto__OpDesc *message, ProtobufCAllocator *allocator);
ProtobufCAllocator *allocator);
/* PaddleMobile__Framework__Proto__OpProto__Var methods */ /* PaddleMobile__Framework__Proto__OpProto__Var methods */
void paddle_mobile__framework__proto__op_proto__var__init void paddle_mobile__framework__proto__op_proto__var__init(
(PaddleMobile__Framework__Proto__OpProto__Var *message); PaddleMobile__Framework__Proto__OpProto__Var *message);
/* PaddleMobile__Framework__Proto__OpProto__Attr methods */ /* PaddleMobile__Framework__Proto__OpProto__Attr methods */
void paddle_mobile__framework__proto__op_proto__attr__init void paddle_mobile__framework__proto__op_proto__attr__init(
(PaddleMobile__Framework__Proto__OpProto__Attr *message); PaddleMobile__Framework__Proto__OpProto__Attr *message);
/* PaddleMobile__Framework__Proto__OpProto methods */ /* PaddleMobile__Framework__Proto__OpProto methods */
void paddle_mobile__framework__proto__op_proto__init void paddle_mobile__framework__proto__op_proto__init(
(PaddleMobile__Framework__Proto__OpProto *message); PaddleMobile__Framework__Proto__OpProto *message);
size_t paddle_mobile__framework__proto__op_proto__get_packed_size size_t paddle_mobile__framework__proto__op_proto__get_packed_size(
(const PaddleMobile__Framework__Proto__OpProto *message); const PaddleMobile__Framework__Proto__OpProto *message);
PaddleMobile__Framework__Proto__OpProto * PaddleMobile__Framework__Proto__OpProto *
paddle_mobile__framework__proto__op_proto__unpack paddle_mobile__framework__proto__op_proto__unpack(ProtobufCAllocator *allocator,
(ProtobufCAllocator *allocator, size_t len,
size_t len, const uint8_t *data);
const uint8_t *data); void paddle_mobile__framework__proto__op_proto__free_unpacked(
void paddle_mobile__framework__proto__op_proto__free_unpacked PaddleMobile__Framework__Proto__OpProto *message,
(PaddleMobile__Framework__Proto__OpProto *message, ProtobufCAllocator *allocator);
ProtobufCAllocator *allocator);
/* PaddleMobile__Framework__Proto__VarType__TensorDesc methods */ /* PaddleMobile__Framework__Proto__VarType__TensorDesc methods */
void paddle_mobile__framework__proto__var_type__tensor_desc__init void paddle_mobile__framework__proto__var_type__tensor_desc__init(
(PaddleMobile__Framework__Proto__VarType__TensorDesc *message); PaddleMobile__Framework__Proto__VarType__TensorDesc *message);
/* PaddleMobile__Framework__Proto__VarType__LoDTensorDesc methods */ /* PaddleMobile__Framework__Proto__VarType__LoDTensorDesc methods */
void paddle_mobile__framework__proto__var_type__lo_dtensor_desc__init void paddle_mobile__framework__proto__var_type__lo_dtensor_desc__init(
(PaddleMobile__Framework__Proto__VarType__LoDTensorDesc *message); PaddleMobile__Framework__Proto__VarType__LoDTensorDesc *message);
/* PaddleMobile__Framework__Proto__VarType__LoDTensorArrayDesc methods */ /* PaddleMobile__Framework__Proto__VarType__LoDTensorArrayDesc methods */
void paddle_mobile__framework__proto__var_type__lo_dtensor_array_desc__init void paddle_mobile__framework__proto__var_type__lo_dtensor_array_desc__init(
(PaddleMobile__Framework__Proto__VarType__LoDTensorArrayDesc *message); PaddleMobile__Framework__Proto__VarType__LoDTensorArrayDesc *message);
/* PaddleMobile__Framework__Proto__VarType__ReaderDesc methods */ /* PaddleMobile__Framework__Proto__VarType__ReaderDesc methods */
void paddle_mobile__framework__proto__var_type__reader_desc__init void paddle_mobile__framework__proto__var_type__reader_desc__init(
(PaddleMobile__Framework__Proto__VarType__ReaderDesc *message); PaddleMobile__Framework__Proto__VarType__ReaderDesc *message);
/* PaddleMobile__Framework__Proto__VarType__ChannelDesc methods */ /* PaddleMobile__Framework__Proto__VarType__ChannelDesc methods */
void paddle_mobile__framework__proto__var_type__channel_desc__init void paddle_mobile__framework__proto__var_type__channel_desc__init(
(PaddleMobile__Framework__Proto__VarType__ChannelDesc *message); PaddleMobile__Framework__Proto__VarType__ChannelDesc *message);
/* PaddleMobile__Framework__Proto__VarType__Tuple methods */ /* PaddleMobile__Framework__Proto__VarType__Tuple methods */
void paddle_mobile__framework__proto__var_type__tuple__init void paddle_mobile__framework__proto__var_type__tuple__init(
(PaddleMobile__Framework__Proto__VarType__Tuple *message); PaddleMobile__Framework__Proto__VarType__Tuple *message);
/* PaddleMobile__Framework__Proto__VarType methods */ /* PaddleMobile__Framework__Proto__VarType methods */
void paddle_mobile__framework__proto__var_type__init void paddle_mobile__framework__proto__var_type__init(
(PaddleMobile__Framework__Proto__VarType *message); PaddleMobile__Framework__Proto__VarType *message);
size_t paddle_mobile__framework__proto__var_type__get_packed_size size_t paddle_mobile__framework__proto__var_type__get_packed_size(
(const PaddleMobile__Framework__Proto__VarType *message); const PaddleMobile__Framework__Proto__VarType *message);
PaddleMobile__Framework__Proto__VarType * PaddleMobile__Framework__Proto__VarType *
paddle_mobile__framework__proto__var_type__unpack paddle_mobile__framework__proto__var_type__unpack(ProtobufCAllocator *allocator,
(ProtobufCAllocator *allocator, size_t len,
size_t len, const uint8_t *data);
const uint8_t *data); void paddle_mobile__framework__proto__var_type__free_unpacked(
void paddle_mobile__framework__proto__var_type__free_unpacked PaddleMobile__Framework__Proto__VarType *message,
(PaddleMobile__Framework__Proto__VarType *message, ProtobufCAllocator *allocator);
ProtobufCAllocator *allocator);
/* PaddleMobile__Framework__Proto__VarDesc methods */ /* PaddleMobile__Framework__Proto__VarDesc methods */
void paddle_mobile__framework__proto__var_desc__init void paddle_mobile__framework__proto__var_desc__init(
(PaddleMobile__Framework__Proto__VarDesc *message); PaddleMobile__Framework__Proto__VarDesc *message);
size_t paddle_mobile__framework__proto__var_desc__get_packed_size size_t paddle_mobile__framework__proto__var_desc__get_packed_size(
(const PaddleMobile__Framework__Proto__VarDesc *message); const PaddleMobile__Framework__Proto__VarDesc *message);
PaddleMobile__Framework__Proto__VarDesc * PaddleMobile__Framework__Proto__VarDesc *
paddle_mobile__framework__proto__var_desc__unpack paddle_mobile__framework__proto__var_desc__unpack(ProtobufCAllocator *allocator,
(ProtobufCAllocator *allocator, size_t len,
size_t len, const uint8_t *data);
const uint8_t *data); void paddle_mobile__framework__proto__var_desc__free_unpacked(
void paddle_mobile__framework__proto__var_desc__free_unpacked PaddleMobile__Framework__Proto__VarDesc *message,
(PaddleMobile__Framework__Proto__VarDesc *message, ProtobufCAllocator *allocator);
ProtobufCAllocator *allocator);
/* PaddleMobile__Framework__Proto__BlockDesc methods */ /* PaddleMobile__Framework__Proto__BlockDesc methods */
void paddle_mobile__framework__proto__block_desc__init void paddle_mobile__framework__proto__block_desc__init(
(PaddleMobile__Framework__Proto__BlockDesc *message); PaddleMobile__Framework__Proto__BlockDesc *message);
size_t paddle_mobile__framework__proto__block_desc__get_packed_size size_t paddle_mobile__framework__proto__block_desc__get_packed_size(
(const PaddleMobile__Framework__Proto__BlockDesc *message); const PaddleMobile__Framework__Proto__BlockDesc *message);
PaddleMobile__Framework__Proto__BlockDesc * PaddleMobile__Framework__Proto__BlockDesc *
paddle_mobile__framework__proto__block_desc__unpack paddle_mobile__framework__proto__block_desc__unpack(
(ProtobufCAllocator *allocator, ProtobufCAllocator *allocator, size_t len, const uint8_t *data);
size_t len, void paddle_mobile__framework__proto__block_desc__free_unpacked(
const uint8_t *data); PaddleMobile__Framework__Proto__BlockDesc *message,
void paddle_mobile__framework__proto__block_desc__free_unpacked ProtobufCAllocator *allocator);
(PaddleMobile__Framework__Proto__BlockDesc *message,
ProtobufCAllocator *allocator);
/* PaddleMobile__Framework__Proto__ProgramDesc methods */ /* PaddleMobile__Framework__Proto__ProgramDesc methods */
void paddle_mobile__framework__proto__program_desc__init void paddle_mobile__framework__proto__program_desc__init(
(PaddleMobile__Framework__Proto__ProgramDesc *message); PaddleMobile__Framework__Proto__ProgramDesc *message);
size_t paddle_mobile__framework__proto__program_desc__get_packed_size size_t paddle_mobile__framework__proto__program_desc__get_packed_size(
(const PaddleMobile__Framework__Proto__ProgramDesc *message); const PaddleMobile__Framework__Proto__ProgramDesc *message);
PaddleMobile__Framework__Proto__ProgramDesc * PaddleMobile__Framework__Proto__ProgramDesc *
paddle_mobile__framework__proto__program_desc__unpack paddle_mobile__framework__proto__program_desc__unpack(
(ProtobufCAllocator *allocator, ProtobufCAllocator *allocator, size_t len, const uint8_t *data);
size_t len, void paddle_mobile__framework__proto__program_desc__free_unpacked(
const uint8_t *data); PaddleMobile__Framework__Proto__ProgramDesc *message,
void paddle_mobile__framework__proto__program_desc__free_unpacked ProtobufCAllocator *allocator);
(PaddleMobile__Framework__Proto__ProgramDesc *message,
ProtobufCAllocator *allocator);
/* --- per-message closures --- */ /* --- per-message closures --- */
typedef void (*PaddleMobile__Framework__Proto__OpDesc__Attr_Closure) typedef void (*PaddleMobile__Framework__Proto__OpDesc__Attr_Closure)(
(const PaddleMobile__Framework__Proto__OpDesc__Attr *message, const PaddleMobile__Framework__Proto__OpDesc__Attr *message,
void *closure_data); void *closure_data);
typedef void (*PaddleMobile__Framework__Proto__OpDesc__Var_Closure) typedef void (*PaddleMobile__Framework__Proto__OpDesc__Var_Closure)(
(const PaddleMobile__Framework__Proto__OpDesc__Var *message, const PaddleMobile__Framework__Proto__OpDesc__Var *message,
void *closure_data); void *closure_data);
typedef void (*PaddleMobile__Framework__Proto__OpDesc_Closure) typedef void (*PaddleMobile__Framework__Proto__OpDesc_Closure)(
(const PaddleMobile__Framework__Proto__OpDesc *message, const PaddleMobile__Framework__Proto__OpDesc *message, void *closure_data);
void *closure_data); typedef void (*PaddleMobile__Framework__Proto__OpProto__Var_Closure)(
typedef void (*PaddleMobile__Framework__Proto__OpProto__Var_Closure) const PaddleMobile__Framework__Proto__OpProto__Var *message,
(const PaddleMobile__Framework__Proto__OpProto__Var *message, void *closure_data);
void *closure_data); typedef void (*PaddleMobile__Framework__Proto__OpProto__Attr_Closure)(
typedef void (*PaddleMobile__Framework__Proto__OpProto__Attr_Closure) const PaddleMobile__Framework__Proto__OpProto__Attr *message,
(const PaddleMobile__Framework__Proto__OpProto__Attr *message, void *closure_data);
void *closure_data); typedef void (*PaddleMobile__Framework__Proto__OpProto_Closure)(
typedef void (*PaddleMobile__Framework__Proto__OpProto_Closure) const PaddleMobile__Framework__Proto__OpProto *message, void *closure_data);
(const PaddleMobile__Framework__Proto__OpProto *message, typedef void (*PaddleMobile__Framework__Proto__VarType__TensorDesc_Closure)(
void *closure_data); const PaddleMobile__Framework__Proto__VarType__TensorDesc *message,
typedef void (*PaddleMobile__Framework__Proto__VarType__TensorDesc_Closure) void *closure_data);
(const PaddleMobile__Framework__Proto__VarType__TensorDesc *message, typedef void (*PaddleMobile__Framework__Proto__VarType__LoDTensorDesc_Closure)(
void *closure_data); const PaddleMobile__Framework__Proto__VarType__LoDTensorDesc *message,
typedef void (*PaddleMobile__Framework__Proto__VarType__LoDTensorDesc_Closure) void *closure_data);
(const PaddleMobile__Framework__Proto__VarType__LoDTensorDesc *message, typedef void (
void *closure_data); *PaddleMobile__Framework__Proto__VarType__LoDTensorArrayDesc_Closure)(
typedef void (*PaddleMobile__Framework__Proto__VarType__LoDTensorArrayDesc_Closure) const PaddleMobile__Framework__Proto__VarType__LoDTensorArrayDesc *message,
(const PaddleMobile__Framework__Proto__VarType__LoDTensorArrayDesc *message, void *closure_data);
void *closure_data); typedef void (*PaddleMobile__Framework__Proto__VarType__ReaderDesc_Closure)(
typedef void (*PaddleMobile__Framework__Proto__VarType__ReaderDesc_Closure) const PaddleMobile__Framework__Proto__VarType__ReaderDesc *message,
(const PaddleMobile__Framework__Proto__VarType__ReaderDesc *message, void *closure_data);
void *closure_data); typedef void (*PaddleMobile__Framework__Proto__VarType__ChannelDesc_Closure)(
typedef void (*PaddleMobile__Framework__Proto__VarType__ChannelDesc_Closure) const PaddleMobile__Framework__Proto__VarType__ChannelDesc *message,
(const PaddleMobile__Framework__Proto__VarType__ChannelDesc *message, void *closure_data);
void *closure_data); typedef void (*PaddleMobile__Framework__Proto__VarType__Tuple_Closure)(
typedef void (*PaddleMobile__Framework__Proto__VarType__Tuple_Closure) const PaddleMobile__Framework__Proto__VarType__Tuple *message,
(const PaddleMobile__Framework__Proto__VarType__Tuple *message, void *closure_data);
void *closure_data); typedef void (*PaddleMobile__Framework__Proto__VarType_Closure)(
typedef void (*PaddleMobile__Framework__Proto__VarType_Closure) const PaddleMobile__Framework__Proto__VarType *message, void *closure_data);
(const PaddleMobile__Framework__Proto__VarType *message, typedef void (*PaddleMobile__Framework__Proto__VarDesc_Closure)(
void *closure_data); const PaddleMobile__Framework__Proto__VarDesc *message, void *closure_data);
typedef void (*PaddleMobile__Framework__Proto__VarDesc_Closure) typedef void (*PaddleMobile__Framework__Proto__BlockDesc_Closure)(
(const PaddleMobile__Framework__Proto__VarDesc *message, const PaddleMobile__Framework__Proto__BlockDesc *message,
void *closure_data); void *closure_data);
typedef void (*PaddleMobile__Framework__Proto__BlockDesc_Closure) typedef void (*PaddleMobile__Framework__Proto__ProgramDesc_Closure)(
(const PaddleMobile__Framework__Proto__BlockDesc *message, const PaddleMobile__Framework__Proto__ProgramDesc *message,
void *closure_data); void *closure_data);
typedef void (*PaddleMobile__Framework__Proto__ProgramDesc_Closure)
(const PaddleMobile__Framework__Proto__ProgramDesc *message,
void *closure_data);
/* --- services --- */ /* --- services --- */
/* --- descriptors --- */ /* --- descriptors --- */
extern const ProtobufCEnumDescriptor paddle_mobile__framework__proto__attr_type__descriptor; extern const ProtobufCEnumDescriptor
extern const ProtobufCMessageDescriptor paddle_mobile__framework__proto__op_desc__descriptor; paddle_mobile__framework__proto__attr_type__descriptor;
extern const ProtobufCMessageDescriptor paddle_mobile__framework__proto__op_desc__attr__descriptor; extern const ProtobufCMessageDescriptor
extern const ProtobufCMessageDescriptor paddle_mobile__framework__proto__op_desc__var__descriptor; paddle_mobile__framework__proto__op_desc__descriptor;
extern const ProtobufCMessageDescriptor paddle_mobile__framework__proto__op_proto__descriptor; extern const ProtobufCMessageDescriptor
extern const ProtobufCMessageDescriptor paddle_mobile__framework__proto__op_proto__var__descriptor; paddle_mobile__framework__proto__op_desc__attr__descriptor;
extern const ProtobufCMessageDescriptor paddle_mobile__framework__proto__op_proto__attr__descriptor; extern const ProtobufCMessageDescriptor
extern const ProtobufCMessageDescriptor paddle_mobile__framework__proto__var_type__descriptor; paddle_mobile__framework__proto__op_desc__var__descriptor;
extern const ProtobufCMessageDescriptor paddle_mobile__framework__proto__var_type__tensor_desc__descriptor; extern const ProtobufCMessageDescriptor
extern const ProtobufCMessageDescriptor paddle_mobile__framework__proto__var_type__lo_dtensor_desc__descriptor; paddle_mobile__framework__proto__op_proto__descriptor;
extern const ProtobufCMessageDescriptor paddle_mobile__framework__proto__var_type__lo_dtensor_array_desc__descriptor; extern const ProtobufCMessageDescriptor
extern const ProtobufCMessageDescriptor paddle_mobile__framework__proto__var_type__reader_desc__descriptor; paddle_mobile__framework__proto__op_proto__var__descriptor;
extern const ProtobufCMessageDescriptor paddle_mobile__framework__proto__var_type__channel_desc__descriptor; extern const ProtobufCMessageDescriptor
extern const ProtobufCMessageDescriptor paddle_mobile__framework__proto__var_type__tuple__descriptor; paddle_mobile__framework__proto__op_proto__attr__descriptor;
extern const ProtobufCEnumDescriptor paddle_mobile__framework__proto__var_type__type__descriptor; extern const ProtobufCMessageDescriptor
extern const ProtobufCMessageDescriptor paddle_mobile__framework__proto__var_desc__descriptor; paddle_mobile__framework__proto__var_type__descriptor;
extern const ProtobufCMessageDescriptor paddle_mobile__framework__proto__block_desc__descriptor; extern const ProtobufCMessageDescriptor
extern const ProtobufCMessageDescriptor paddle_mobile__framework__proto__program_desc__descriptor; paddle_mobile__framework__proto__var_type__tensor_desc__descriptor;
extern const ProtobufCMessageDescriptor
paddle_mobile__framework__proto__var_type__lo_dtensor_desc__descriptor;
extern const ProtobufCMessageDescriptor
paddle_mobile__framework__proto__var_type__lo_dtensor_array_desc__descriptor;
extern const ProtobufCMessageDescriptor
paddle_mobile__framework__proto__var_type__reader_desc__descriptor;
extern const ProtobufCMessageDescriptor
paddle_mobile__framework__proto__var_type__channel_desc__descriptor;
extern const ProtobufCMessageDescriptor
paddle_mobile__framework__proto__var_type__tuple__descriptor;
extern const ProtobufCEnumDescriptor
paddle_mobile__framework__proto__var_type__type__descriptor;
extern const ProtobufCMessageDescriptor
paddle_mobile__framework__proto__var_desc__descriptor;
extern const ProtobufCMessageDescriptor
paddle_mobile__framework__proto__block_desc__descriptor;
extern const ProtobufCMessageDescriptor
paddle_mobile__framework__proto__program_desc__descriptor;
PROTOBUF_C__END_DECLS PROTOBUF_C__END_DECLS
#endif /* PROTOBUF_C_framework_2eproto__INCLUDED */
#endif /* PROTOBUF_C_framework_2eproto__INCLUDED */
...@@ -33,17 +33,18 @@ std::vector<std::shared_ptr<OpDesc>> BlockDesc::Ops() const { ...@@ -33,17 +33,18 @@ std::vector<std::shared_ptr<OpDesc>> BlockDesc::Ops() const {
return res; return res;
} }
BlockDesc::BlockDesc(PaddleMobile__Framework__Proto__BlockDesc *desc): index_(desc->idx), parent_index_(desc->idx) { BlockDesc::BlockDesc(PaddleMobile__Framework__Proto__BlockDesc *desc)
: index_(desc->idx), parent_index_(desc->idx) {
for (int i = 0; i < desc->n_vars; ++i) { for (int i = 0; i < desc->n_vars; ++i) {
PaddleMobile__Framework__Proto__VarDesc *var_desc = desc->vars[i]; PaddleMobile__Framework__Proto__VarDesc *var_desc = desc->vars[i];
vars_[std::string(var_desc->name)] = std::shared_ptr<VarDesc>(new VarDesc(var_desc)); vars_[std::string(var_desc->name)] =
std::shared_ptr<VarDesc>(new VarDesc(var_desc));
} }
for (int j = 0; j < desc->n_ops; ++j) { for (int j = 0; j < desc->n_ops; ++j) {
PaddleMobile__Framework__Proto__OpDesc *op_desc = desc->ops[j]; PaddleMobile__Framework__Proto__OpDesc *op_desc = desc->ops[j];
ops_.emplace_back(new framework::OpDesc(op_desc)); ops_.emplace_back(new framework::OpDesc(op_desc));
} }
} }
} // namespace framework } // namespace framework
......
...@@ -15,9 +15,9 @@ limitations under the License. */ ...@@ -15,9 +15,9 @@ limitations under the License. */
#pragma once #pragma once
#include "framework/framework.pb-c.h" #include "framework/framework.pb-c.h"
#include "framework/paddle_mobile_object.h"
#include "framework/program/op_desc.h" #include "framework/program/op_desc.h"
#include "framework/program/var_desc.h" #include "framework/program/var_desc.h"
#include "framework/paddle_mobile_object.h"
namespace paddle_mobile { namespace paddle_mobile {
namespace framework { namespace framework {
......
...@@ -15,8 +15,8 @@ limitations under the License. */ ...@@ -15,8 +15,8 @@ limitations under the License. */
#include <string> #include <string>
#include <vector> #include <vector>
#include "program_desc.h"
#include "framework/program/tensor_desc.h" #include "framework/program/tensor_desc.h"
#include "program_desc.h"
namespace paddle_mobile { namespace paddle_mobile {
namespace framework { namespace framework {
...@@ -70,7 +70,6 @@ void ProgramDesc::Description(std::string header) { ...@@ -70,7 +70,6 @@ void ProgramDesc::Description(std::string header) {
} }
} }
} }
} }
#endif #endif
} }
......
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
// //
// Created by liuRuiLong on 2018/5/26. // Created by liuRuiLong on 2018/5/26.
// //
......
...@@ -21,26 +21,26 @@ limitations under the License. */ ...@@ -21,26 +21,26 @@ limitations under the License. */
namespace paddle_mobile { namespace paddle_mobile {
namespace framework { namespace framework {
enum VarType_Type{ enum VarType_Type {
VARTYPE_TYPE_BOOL = 0, VARTYPE_TYPE_BOOL = 0,
VARTYPE_TYPE_INT16 = 1, VARTYPE_TYPE_INT16 = 1,
VARTYPE_TYPE_INT32 = 2, VARTYPE_TYPE_INT32 = 2,
VARTYPE_TYPE_INT64 = 3, VARTYPE_TYPE_INT64 = 3,
VARTYPE_TYPE_FP16 = 4, VARTYPE_TYPE_FP16 = 4,
VARTYPE_TYPE_FP32 = 5, VARTYPE_TYPE_FP32 = 5,
VARTYPE_TYPE_FP64 = 6, VARTYPE_TYPE_FP64 = 6,
VARTYPE_TYPE_LOD_TENSOR = 7, VARTYPE_TYPE_LOD_TENSOR = 7,
VARTYPE_TYPE_SELECTED_ROWS = 8, VARTYPE_TYPE_SELECTED_ROWS = 8,
VARTYPE_TYPE_FEED_MINIBATCH = 9, VARTYPE_TYPE_FEED_MINIBATCH = 9,
VARTYPE_TYPE_FETCH_LIST = 10, VARTYPE_TYPE_FETCH_LIST = 10,
VARTYPE_TYPE_STEP_SCOPES = 11, VARTYPE_TYPE_STEP_SCOPES = 11,
VARTYPE_TYPE_STEP_LOD_RANK_TABLE = 12, VARTYPE_TYPE_STEP_LOD_RANK_TABLE = 12,
VARTYPE_TYPE_STEP_LOD_TENSOR_ARRAY = 13, VARTYPE_TYPE_STEP_LOD_TENSOR_ARRAY = 13,
VARTYPE_TYPE_STEP_PLACE_LIST = 14, VARTYPE_TYPE_STEP_PLACE_LIST = 14,
VARTYPE_TYPE_READER = 15, VARTYPE_TYPE_READER = 15,
VARTYPE_TYPE_CHANNEL = 16, VARTYPE_TYPE_CHANNEL = 16,
VARTYPE_TYPE_RAW = 17, VARTYPE_TYPE_RAW = 17,
VARTYPE_TYPE_TUPLE = 18 VARTYPE_TYPE_TUPLE = 18
}; };
class TensorDesc { class TensorDesc {
...@@ -59,17 +59,13 @@ class TensorDesc { ...@@ -59,17 +59,13 @@ class TensorDesc {
data_type_ = (VarType_Type)desc->data_type; data_type_ = (VarType_Type)desc->data_type;
} }
std::vector<int64_t> Dims() const { std::vector<int64_t> Dims() const { return dims_; };
return dims_; VarType_Type DataType() const { return data_type_; }
};
VarType_Type DataType() const {
return data_type_;
}
private: private:
std::vector<int64_t> dims_; std::vector<int64_t> dims_;
VarType_Type data_type_; VarType_Type data_type_;
}; };
} } // namespace framework
} } // namespace paddle_mobile
...@@ -16,8 +16,5 @@ limitations under the License. */ ...@@ -16,8 +16,5 @@ limitations under the License. */
namespace paddle_mobile { namespace paddle_mobile {
namespace framework { namespace framework {} // namespace framework
} // namespace framework
} // namespace paddle_mobile } // namespace paddle_mobile
...@@ -15,8 +15,8 @@ limitations under the License. */ ...@@ -15,8 +15,8 @@ limitations under the License. */
#pragma once #pragma once
#include "framework/framework.pb-c.h" #include "framework/framework.pb-c.h"
#include "framework/program/tensor_desc.h"
#include "framework/paddle_mobile_object.h" #include "framework/paddle_mobile_object.h"
#include "framework/program/tensor_desc.h"
namespace paddle_mobile { namespace paddle_mobile {
namespace framework { namespace framework {
...@@ -48,7 +48,6 @@ PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__BOOL = 0, ...@@ -48,7 +48,6 @@ PADDLE_MOBILE__FRAMEWORK__PROTO__VAR_TYPE__TYPE__BOOL = 0,
*/ */
class VarDesc { class VarDesc {
public: public:
VarDesc(const VarDesc &var_desc) { VarDesc(const VarDesc &var_desc) {
...@@ -65,7 +64,6 @@ class VarDesc { ...@@ -65,7 +64,6 @@ class VarDesc {
VarType_Type type_; VarType_Type type_;
VarType_Type data_type_; VarType_Type data_type_;
* */ * */
} }
VarDesc(PaddleMobile__Framework__Proto__VarDesc *desc) { VarDesc(PaddleMobile__Framework__Proto__VarDesc *desc) {
type_ = (VarType_Type)desc->type->type; type_ = (VarType_Type)desc->type->type;
...@@ -94,9 +92,7 @@ class VarDesc { ...@@ -94,9 +92,7 @@ class VarDesc {
default: default:
data_type_ = tensor_desc_.DataType(); data_type_ = tensor_desc_.DataType();
break; break;
} }
} }
std::string Name() const { return name_; } std::string Name() const { return name_; }
...@@ -104,42 +100,40 @@ class VarDesc { ...@@ -104,42 +100,40 @@ class VarDesc {
bool Persistable() const { return persistable_; } bool Persistable() const { return persistable_; }
const TensorDesc &Tensor_desc() const { const TensorDesc &Tensor_desc() const { return tensor_desc_; }
return tensor_desc_;
}
// const proto::VarType::ChannelDesc &channel_desc() const { // const proto::VarType::ChannelDesc &channel_desc() const {
// switch (desc_.type().type()) { // switch (desc_.type().type()) {
// case proto::VarType::CHANNEL: // case proto::VarType::CHANNEL:
// return desc_.type().channel(); // return desc_.type().channel();
// default: // default:
// break; // break;
// } // }
// } // }
// proto::VarType::Type GetDataType() const { // proto::VarType::Type GetDataType() const {
// switch (desc_.type().type()) { // switch (desc_.type().type()) {
// case proto::VarType::CHANNEL: // case proto::VarType::CHANNEL:
// return channel_desc().data_type(); // return channel_desc().data_type();
// break; // break;
// default: // default:
// return tensor_desc().data_type(); // return tensor_desc().data_type();
// } // }
// } // }
// template <typename T> // template <typename T>
// std::vector<T> RepeatedToVector( // std::vector<T> RepeatedToVector(
// const google::protobuf::RepeatedField<T> &repeated_field) const { // const google::protobuf::RepeatedField<T> &repeated_field) const {
// std::vector<T> ret; // std::vector<T> ret;
// ret.reserve(repeated_field.size()); // ret.reserve(repeated_field.size());
// std::copy(repeated_field.begin(), repeated_field.end(), // std::copy(repeated_field.begin(), repeated_field.end(),
// std::back_inserter(ret)); // std::back_inserter(ret));
// return ret; // return ret;
// } // }
// std::vector<int64_t> GetShape() const { // std::vector<int64_t> GetShape() const {
// return this->RepeatedToVector(tensor_desc().dims()); // return this->RepeatedToVector(tensor_desc().dims());
// } // }
private: private:
std::string name_; std::string name_;
...@@ -147,7 +141,6 @@ class VarDesc { ...@@ -147,7 +141,6 @@ class VarDesc {
TensorDesc tensor_desc_; TensorDesc tensor_desc_;
VarType_Type type_; VarType_Type type_;
VarType_Type data_type_; VarType_Type data_type_;
}; };
} // namespace framework } // namespace framework
......
...@@ -16,15 +16,15 @@ limitations under the License. */ ...@@ -16,15 +16,15 @@ limitations under the License. */
#include <fstream> #include <fstream>
#include <vector> #include <vector>
#include "common/log.h"
#include "common/enforce.h" #include "common/enforce.h"
#include "framework/scope.h" #include "common/log.h"
#include "framework/tensor.h"
#include "framework/operator.h"
#include "framework/lod_tensor.h"
#include "framework/framework.pb-c.h" #include "framework/framework.pb-c.h"
#include "framework/program/var_desc.h" #include "framework/lod_tensor.h"
#include "framework/operator.h"
#include "framework/program/program_desc.h" #include "framework/program/program_desc.h"
#include "framework/program/var_desc.h"
#include "framework/scope.h"
#include "framework/tensor.h"
namespace paddle_mobile { namespace paddle_mobile {
...@@ -40,7 +40,7 @@ void ReadBinaryFile(const std::string &filename, std::string *contents) { ...@@ -40,7 +40,7 @@ void ReadBinaryFile(const std::string &filename, std::string *contents) {
fin.close(); fin.close();
} }
static size_t ReadBuffer (const char *file_name, uint8_t **out) { static size_t ReadBuffer(const char *file_name, uint8_t **out) {
printf("%s \n", file_name); printf("%s \n", file_name);
FILE *fp; FILE *fp;
fp = fopen(file_name, "rb"); fp = fopen(file_name, "rb");
...@@ -56,7 +56,7 @@ static size_t ReadBuffer (const char *file_name, uint8_t **out) { ...@@ -56,7 +56,7 @@ static size_t ReadBuffer (const char *file_name, uint8_t **out) {
size_t cur_len = 0; size_t cur_len = 0;
size_t nread; size_t nread;
while ((nread=fread(*out + cur_len, 1, size - cur_len, fp)) != 0) { while ((nread = fread(*out + cur_len, 1, size - cur_len, fp)) != 0) {
cur_len += nread; cur_len += nread;
} }
fclose(fp); fclose(fp);
...@@ -64,7 +64,8 @@ static size_t ReadBuffer (const char *file_name, uint8_t **out) { ...@@ -64,7 +64,8 @@ static size_t ReadBuffer (const char *file_name, uint8_t **out) {
} }
template <typename Dtype, Precision P> template <typename Dtype, Precision P>
void Loader<Dtype, P>::LoadVar(framework::Variable *variable, const framework::VarDesc &var_desc, void Loader<Dtype, P>::LoadVar(framework::Variable *variable,
const framework::VarDesc &var_desc,
const std::string &file_path) { const std::string &file_path) {
auto tensor = variable->GetMutable<framework::LoDTensor>(); auto tensor = variable->GetMutable<framework::LoDTensor>();
std::ifstream is(file_path); std::ifstream is(file_path);
...@@ -109,22 +110,22 @@ void Loader<Dtype, P>::LoadVar(framework::Variable *variable, const framework::V ...@@ -109,22 +110,22 @@ void Loader<Dtype, P>::LoadVar(framework::Variable *variable, const framework::V
const framework::TensorDesc &desc = var_desc.Tensor_desc(); const framework::TensorDesc &desc = var_desc.Tensor_desc();
PaddleMobile__Framework__Proto__VarType__TensorDesc *tensor_desc = NULL; PaddleMobile__Framework__Proto__VarType__TensorDesc *tensor_desc = NULL;
// void *v; // void *v;
// PaddleMobile__Framework__Proto__VarType__TensorDesc_Closure()(tensor_desc, buf.get()); // PaddleMobile__Framework__Proto__VarType__TensorDesc_Closure()(tensor_desc,
// buf.get());
// DLOG << "PaddleMobile__Framework__Proto__VarType__TensorDesc_Closure- " << tensor_desc;
// DLOG << "PaddleMobile__Framework__Proto__VarType__TensorDesc_Closure- " <<
// tensor_desc;
// framework::TensorDesc &tensor_desc = variable-> // framework::TensorDesc &tensor_desc = variable->
// PaddleMobile__Framework__Proto__ProgramDesc *c_program; // PaddleMobile__Framework__Proto__ProgramDesc *c_program;
// uint8_t *proto_buf = NULL; // uint8_t *proto_buf = NULL;
// size_t read_size = ReadBuffer(file_path.c_str(), &proto_buf); // size_t read_size = ReadBuffer(file_path.c_str(), &proto_buf);
// c_program = paddle_mobile__framework__proto__program_desc__unpack(NULL, read_size, buf); // c_program = paddle_mobile__framework__proto__program_desc__unpack(NULL,
// read_size, buf);
// paddle_mobile__framework__proto__var_type__tensor_desc__init()
// paddle_mobile__framework__proto__var_type__tensor_desc__init()
int memory_size = 1; int memory_size = 1;
for (auto l : desc.Dims()) { for (auto l : desc.Dims()) {
...@@ -173,7 +174,8 @@ const framework::Program<Dtype, P> Loader<Dtype, P>::Load( ...@@ -173,7 +174,8 @@ const framework::Program<Dtype, P> Loader<Dtype, P>::Load(
PADDLE_MOBILE_ENFORCE(buf != NULL, "read from __model__ is null"); PADDLE_MOBILE_ENFORCE(buf != NULL, "read from __model__ is null");
c_program = paddle_mobile__framework__proto__program_desc__unpack(NULL, read_size, buf); c_program = paddle_mobile__framework__proto__program_desc__unpack(
NULL, read_size, buf);
PADDLE_MOBILE_ENFORCE(c_program != NULL, "program is null"); PADDLE_MOBILE_ENFORCE(c_program != NULL, "program is null");
...@@ -194,14 +196,14 @@ const framework::Program<Dtype, P> Loader<Dtype, P>::Load( ...@@ -194,14 +196,14 @@ const framework::Program<Dtype, P> Loader<Dtype, P>::Load(
for (const auto &block : originProgramDesc->Blocks()) { for (const auto &block : originProgramDesc->Blocks()) {
for (int i = 0; i < block->Vars().size(); ++i) { for (int i = 0; i < block->Vars().size(); ++i) {
std::shared_ptr<framework::VarDesc> var_desc = block->Vars()[i]; std::shared_ptr<framework::VarDesc> var_desc = block->Vars()[i];
// DLOG << "var name-- " << var_desc->Name(); // DLOG << "var name-- " << var_desc->Name();
auto var = scope->Var(var_desc->Name()); auto var = scope->Var(var_desc->Name());
if (var_desc->Type() == framework::VARTYPE_TYPE_LOD_TENSOR) { if (var_desc->Type() == framework::VARTYPE_TYPE_LOD_TENSOR) {
if (var_desc->Persistable() && if (var_desc->Persistable() &&
var_desc->Type() != framework::VARTYPE_TYPE_FEED_MINIBATCH && var_desc->Type() != framework::VARTYPE_TYPE_FEED_MINIBATCH &&
var_desc->Type() != framework::VARTYPE_TYPE_FETCH_LIST) { var_desc->Type() != framework::VARTYPE_TYPE_FETCH_LIST) {
// DLOG << "to load var "; // DLOG << "to load var ";
LoadVar(var, *var_desc, dirname + "/" + var_desc->Name()); LoadVar(var, *var_desc, dirname + "/" + var_desc->Name());
} }
...@@ -247,7 +249,8 @@ Executor<Dtype, P>::Executor(const framework::Program<Dtype> p) : program_(p) { ...@@ -247,7 +249,8 @@ Executor<Dtype, P>::Executor(const framework::Program<Dtype> p) : program_(p) {
} }
template <typename Dtype, Precision P> template <typename Dtype, Precision P>
void Executor<Dtype, P>::LoadMemory(const framework::VarDesc var_desc, framework::LoDTensor *tensor, void Executor<Dtype, P>::LoadMemory(const framework::VarDesc var_desc,
framework::LoDTensor *tensor,
const std::string &file_path) { const std::string &file_path) {
std::ifstream is(file_path); std::ifstream is(file_path);
PADDLE_MOBILE_ENFORCE(is.is_open(), "open file: %s failed", PADDLE_MOBILE_ENFORCE(is.is_open(), "open file: %s failed",
...@@ -290,7 +293,6 @@ void Executor<Dtype, P>::LoadMemory(const framework::VarDesc var_desc, framework ...@@ -290,7 +293,6 @@ void Executor<Dtype, P>::LoadMemory(const framework::VarDesc var_desc, framework
const framework::TensorDesc &desc = var_desc.Tensor_desc(); const framework::TensorDesc &desc = var_desc.Tensor_desc();
int memory_size = 1; int memory_size = 1;
for (auto l : desc.Dims()) { for (auto l : desc.Dims()) {
memory_size *= l; memory_size *= l;
...@@ -335,7 +337,8 @@ void Executor<Dtype, P>::InitMemory() { ...@@ -335,7 +337,8 @@ void Executor<Dtype, P>::InitMemory() {
auto var = program_.scope->Var(var_desc->Name()); auto var = program_.scope->Var(var_desc->Name());
if (var_desc->Persistable()) { if (var_desc->Persistable()) {
auto tensor = var->template GetMutable<framework::LoDTensor>(); auto tensor = var->template GetMutable<framework::LoDTensor>();
LoadMemory(*var_desc, tensor, program_.model_path + "/" + var_desc->Name()); LoadMemory(*var_desc, tensor,
program_.model_path + "/" + var_desc->Name());
} else { } else {
if (var_desc->Type() == framework::VARTYPE_TYPE_LOD_TENSOR) { if (var_desc->Type() == framework::VARTYPE_TYPE_LOD_TENSOR) {
auto tensor = var->template GetMutable<framework::Tensor>(); auto tensor = var->template GetMutable<framework::Tensor>();
......
...@@ -33,7 +33,9 @@ class Loader : PaddleMobileObject { ...@@ -33,7 +33,9 @@ class Loader : PaddleMobileObject {
const framework::Program<Dtype, P> Load(const std::string &dirname); const framework::Program<Dtype, P> Load(const std::string &dirname);
private: private:
void LoadVar(framework::Variable *variable, const framework::VarDesc &var_desc, const std::string &file_path); void LoadVar(framework::Variable *variable,
const framework::VarDesc &var_desc,
const std::string &file_path);
}; };
template <typename Dtype, Precision P = Precision::FP32> template <typename Dtype, Precision P = Precision::FP32>
...@@ -52,7 +54,8 @@ class Executor { ...@@ -52,7 +54,8 @@ class Executor {
protected: protected:
void InitMemory(); void InitMemory();
void LoadMemory(const framework::VarDesc var_desc, framework::LoDTensor *tensor, const std::string &file_path); void LoadMemory(const framework::VarDesc var_desc,
framework::LoDTensor *tensor, const std::string &file_path);
framework::Program<Dtype> program_; framework::Program<Dtype> program_;
std::shared_ptr<framework::ProgramDesc> to_predict_program_; std::shared_ptr<framework::ProgramDesc> to_predict_program_;
void predict(const framework::Tensor &t, int block_id); void predict(const framework::Tensor &t, int block_id);
......
...@@ -116,8 +116,7 @@ inline std::string DataTypeToString(const VarType_Type type) { ...@@ -116,8 +116,7 @@ inline std::string DataTypeToString(const VarType_Type type) {
} }
} }
inline std::ostream &operator<<(std::ostream &out, inline std::ostream &operator<<(std::ostream &out, const VarType_Type &type) {
const VarType_Type &type) {
out << DataTypeToString(type); out << DataTypeToString(type);
return out; return out;
} }
......
...@@ -58,7 +58,6 @@ class Executor4Test : public Executor<DeviceType> { ...@@ -58,7 +58,6 @@ class Executor4Test : public Executor<DeviceType> {
for (std::shared_ptr<BlockDesc> block_desc : blocks) { for (std::shared_ptr<BlockDesc> block_desc : blocks) {
std::vector<std::shared_ptr<OpDesc>> ops = block_desc->Ops(); std::vector<std::shared_ptr<OpDesc>> ops = block_desc->Ops();
for (std::shared_ptr<OpDesc> op : ops) { for (std::shared_ptr<OpDesc> op : ops) {
if (op->Type() == op_type) { if (op->Type() == op_type) {
/// test first meeting op in program /// test first meeting op in program
std::shared_ptr<paddle_mobile::framework::OperatorBase<DeviceType>> std::shared_ptr<paddle_mobile::framework::OperatorBase<DeviceType>>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册