summaryrefslogtreecommitdiff
path: root/upb/def.h
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.h
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.h')
-rw-r--r--upb/def.h14
1 files changed, 12 insertions, 2 deletions
diff --git a/upb/def.h b/upb/def.h
index 2699fbf..cfa140a 100644
--- a/upb/def.h
+++ b/upb/def.h
@@ -943,7 +943,17 @@ bool upb_enumdef_setdefault(upb_enumdef *e, int32_t val, upb_status *s);
int upb_enumdef_numvals(const upb_enumdef *e);
bool upb_enumdef_addval(upb_enumdef *e, const char *name, int32_t num,
upb_status *status);
-bool upb_enumdef_ntoi(const upb_enumdef *e, const char *name, int32_t *num);
+
+// Enum lookups:
+// - ntoi: look up a name with specified length.
+// - ntoiz: look up a name provided as a null-terminated string.
+// - iton: look up an integer, returning the name as a null-terminated string.
+bool upb_enumdef_ntoi(const upb_enumdef *e, const char *name, size_t len,
+ int32_t *num);
+UPB_INLINE bool upb_enumdef_ntoiz(const upb_enumdef *e,
+ const char *name, int32_t *num) {
+ return upb_enumdef_ntoi(e, name, strlen(name), num);
+}
const char *upb_enumdef_iton(const upb_enumdef *e, int32_t num);
// upb_enum_iter i;
@@ -1352,7 +1362,7 @@ inline bool EnumDef::AddValue(const std::string& name, int32_t num,
return upb_enumdef_addval(this, upb_safecstr(name), num, status);
}
inline bool EnumDef::FindValueByName(const char* name, int32_t *num) const {
- return upb_enumdef_ntoi(this, name, num);
+ return upb_enumdef_ntoiz(this, name, num);
}
inline const char* EnumDef::FindValueByNumber(int32_t num) const {
return upb_enumdef_iton(this, num);
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback