Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix protobuf string bugs

  • Loading branch information...
commit d5e02433b4ebd7e9d0209f57a0a7b624b99886b6 1 parent 265f817
@fantasyni fantasyni authored
View
4 include/pomelo-protobuf/pb-util.h
@@ -8,12 +8,12 @@
/* Wire types. Library user needs these only in encoder callbacks. */
typedef enum {
- PB_string = 0,
PB_uInt32 = 1,
PB_int32 = 2,
PB_sInt32 = 3,
PB_float = 4,
- PB_double = 5
+ PB_double = 5,
+ PB_string = 6
} pb_wire_type_t;
/*Helper Function*/
View
2  src/pb-decode.c
@@ -296,7 +296,7 @@ static int checkreturn pb_decode_array(pb_istream_t *stream, const json_t *gprot
need_decref = 1;
}
- if (pb__get_type(type_text)) {
+ if (pb__get_type(type_text) && pb__get_type(type_text) != PB_string) {
if (!pb_decode_varint32(stream, &size)) {
if (need_decref)
json_decref(array);
View
2  src/pb-encode.c
@@ -138,7 +138,7 @@ static int checkreturn pb_encode_array(pb_ostream_t *stream, const json_t *gprot
size_t len = json_array_size(array);
size_t i;
// simple msg
- if (pb__get_type(type_text)) {
+ if (pb__get_type(type_text) && pb__get_type(type_text) != PB_string) {
if (!pb_encode_tag_for_field(stream, proto)) {
return 0;
}
View
4 src/pb-util.c
@@ -4,8 +4,6 @@
#include "pomelo-protobuf/pb-util.h"
int pb__get_type(const char *type) {
- if (strcmp(type, "string") == 0)
- return 0;
if (strcmp(type, "uInt32") == 0)
return 1;
if (strcmp(type, "int32") == 0)
@@ -16,6 +14,8 @@ int pb__get_type(const char *type) {
return 4;
if (strcmp(type, "double") == 0)
return 5;
+ if (strcmp(type, "string") == 0)
+ return 6;
// if (strcmp(type, "uInt64") == 0)
// return 5;
// if (strcmp(type, "sInt64") == 0)
Please sign in to comment.
Something went wrong with that request. Please try again.