summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Haberman <joshua@reverberate.org>2009-07-06 14:31:22 -0700
committerJoshua Haberman <joshua@reverberate.org>2009-07-06 14:31:22 -0700
commitec2da8e59df66569f010dbdbddb207372460f860 (patch)
treed6e17aba60ac3c86fbf192330ff715e755f7df7a
parent5bfef1bc8e8514640ae40e66bc4dc391e9dd6b8f (diff)
More documentation and fixed check_wire_type.
-rw-r--r--upb_parse.h23
1 files changed, 20 insertions, 3 deletions
diff --git a/upb_parse.h b/upb_parse.h
index c5640f1..466c383 100644
--- a/upb_parse.h
+++ b/upb_parse.h
@@ -1,8 +1,10 @@
/*
* upb - a minimalist implementation of protocol buffers.
*
- * This file contains parsing routines; both stream-oriented and tree-oriented
- * models are supported.
+ * upb_parse implements a high performance, callback-based, stream-oriented
+ * parser (comparable to the SAX model in XML parsers). For parsing protobufs
+ * into in-memory messages (a more DOM-like model), see the routines in
+ * upb_msg.h, which are layered on top of this parser.
*
* Copyright (c) 2009 Joshua Haberman. See LICENSE for details.
*/
@@ -47,6 +49,15 @@ struct upb_tag {
/* High-level parsing interface. **********************************************/
+/* The general scheme is that the client registers callbacks that will be
+ * called at the appropriate times. These callbacks provide the client with
+ * data and let the client make decisions (like whether to parse or to skip
+ * a value).
+ *
+ * After initializing the parse state, the client can repeatedly call upb_parse
+ * as data becomes available. The parser is fully streaming-capable, so the
+ * data need not all be available at the same time. */
+
struct upb_parse_state;
/* Initialize and free (respectively) the given parse state, which must have
@@ -116,7 +127,13 @@ upb_status_t upb_parse(struct upb_parse_state *s, void *buf, size_t len,
extern upb_wire_type_t upb_expected_wire_types[];
/* Returns true if wt is the correct on-the-wire type for ft. */
INLINE bool upb_check_type(upb_wire_type_t wt, upb_field_type_t ft) {
- return upb_type_info[ft].expected_wire_type == wt;
+ if(ft == 10) { // GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_GROUP)
+ return wt == UPB_WIRE_TYPE_START_GROUP;
+ } else {
+ /* With packed arrays, anything can be delimited. */
+ return wt == UPB_WIRE_TYPE_DELIMITED ||
+ upb_type_info[ft].expected_wire_type == wt;
+ }
}
/* Data-consuming functions (to be called from value cb). *********************/
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback