Skip to content

Commit

Permalink
fix protobuf string bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
fantasyni committed Nov 28, 2013
1 parent 265f817 commit d5e0243
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions include/pomelo-protobuf/pb-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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*/
Expand Down
2 changes: 1 addition & 1 deletion src/pb-decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/pb-encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/pb-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit d5e0243

Please sign in to comment.