summaryrefslogtreecommitdiff
path: root/upb/def.c
diff options
context:
space:
mode:
authorChris Fallin <cfallin@google.com>2014-12-09 12:27:22 -0800
committerChris Fallin <cfallin@google.com>2014-12-09 13:23:58 -0800
commit8f8113b4fff748b57b0ff2f1a301e86b4703be84 (patch)
treece16586d7f0a8e5c87252727b4b3745d1a48a4eb /upb/def.c
parente257bd978d5e6278e7b188d543858852c0c4d856 (diff)
JSON test, symbolic enum names in JSON, and a few improvements.
- Added a JSON test that round-trips (parses then re-serializes) several test messages, ensuring that the re-serialized form matches the original exactly. - Added support for printing and parsing symbolic enum names (rather than integer values) in JSON. - Updated JSON printer to properly handle string fields that come in multiple pieces. ('bytes' fields still do not support this, and this work is more challenging because it requires making the base64 encoder resumable. Base64 encoding is not separable at an input-byte granularity, unlike string escaping.) - Fixed a < vs. <= bug in UTF-8 encoding generation (oops).
Diffstat (limited to 'upb/def.c')
-rw-r--r--upb/def.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/upb/def.c b/upb/def.c
index fde2ee8..aa05618 100644
--- a/upb/def.c
+++ b/upb/def.c
@@ -457,7 +457,7 @@ bool upb_enumdef_addval(upb_enumdef *e, const char *name, int32_t num,
if (!upb_isident(name, strlen(name), false, status)) {
return false;
}
- if (upb_enumdef_ntoi(e, name, NULL)) {
+ if (upb_enumdef_ntoiz(e, name, NULL)) {
upb_status_seterrf(status, "name '%s' is already defined", name);
return false;
}
@@ -505,9 +505,10 @@ void upb_enum_begin(upb_enum_iter *i, const upb_enumdef *e) {
void upb_enum_next(upb_enum_iter *iter) { upb_strtable_next(iter); }
bool upb_enum_done(upb_enum_iter *iter) { return upb_strtable_done(iter); }
-bool upb_enumdef_ntoi(const upb_enumdef *def, const char *name, int32_t *num) {
+bool upb_enumdef_ntoi(const upb_enumdef *def, const char *name,
+ size_t len, int32_t *num) {
upb_value v;
- if (!upb_strtable_lookup(&def->ntoi, name, &v)) {
+ if (!upb_strtable_lookup2(&def->ntoi, name, len, &v)) {
return false;
}
if (num) *num = upb_value_getint32(v);
@@ -595,7 +596,7 @@ static bool enumdefaultint32(const upb_fielddef *f, int32_t *val) {
if (f->defaultval.bytes) {
// Default was explicitly set as a str; try to lookup corresponding int.
str_t *s = f->defaultval.bytes;
- if (upb_enumdef_ntoi(e, s->str, val)) {
+ if (upb_enumdef_ntoiz(e, s->str, val)) {
return true;
}
} else {
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback