Skip to content

Commit 1b6bbb7

Browse files
committed
Allow int values for double/float fields (fixes #4)
1 parent 404c827 commit 1b6bbb7

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

json2pb.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ static void _json2field(Message &msg, const FieldDescriptor *field, json_t *jf)
164164
break; \
165165
}
166166

167-
_CONVERT(CPPTYPE_DOUBLE, double, "f", SetDouble, AddDouble);
168-
_CONVERT(CPPTYPE_FLOAT, double, "f", SetFloat, AddFloat);
167+
_CONVERT(CPPTYPE_DOUBLE, double, "F", SetDouble, AddDouble);
168+
_CONVERT(CPPTYPE_FLOAT, double, "F", SetFloat, AddFloat);
169169
_CONVERT(CPPTYPE_INT64, json_int_t, "I", SetInt64, AddInt64);
170170
_CONVERT(CPPTYPE_UINT64, json_int_t, "I", SetUInt64, AddUInt64);
171171
_CONVERT(CPPTYPE_INT32, json_int_t, "I", SetInt32, AddInt32);

test.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"_str": "b",
33
"_bin": "0a0a0a0a",
44
"_bool": true,
5+
"_float": 1,
56
"sub": {
67
"field": "subfield",
78
"echo": [

0 commit comments

Comments
 (0)