diff options
author | Joshua Haberman <joshua@reverberate.org> | 2011-05-19 10:56:34 -0700 |
---|---|---|
committer | Joshua Haberman <joshua@reverberate.org> | 2011-05-19 10:56:34 -0700 |
commit | d619852e06983dc30d2070f6c4af32d563b101f2 (patch) | |
tree | aad6f6c1e2221ec2f0703fab2a842022156fa520 /src/upb_msg.h | |
parent | a5506318aa6f815f8c9439de99247463ad8883e0 (diff) |
Change dispatcher error handling model.
Now the dispatcher will call error handlers
instaed of returning statuses that the caller
has to constantly check.
Diffstat (limited to 'src/upb_msg.h')
-rw-r--r-- | src/upb_msg.h | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/src/upb_msg.h b/src/upb_msg.h index 33f5d1c..a0b2ad2 100644 --- a/src/upb_msg.h +++ b/src/upb_msg.h @@ -169,7 +169,6 @@ INLINE void upb_array_unref(upb_array *a, upb_fielddef *f) { } void upb_array_recycle(upb_array **arr); - INLINE uint32_t upb_array_len(upb_array *a) { return a->len; } @@ -279,8 +278,40 @@ INLINE void upb_msg_clear(upb_msg *msg, upb_msgdef *md) { // The upb_msg itself must be passed as the param to the src. upb_mhandlers *upb_msg_reghandlers(upb_handlers *h, upb_msgdef *md); -void upb_msg_runhandlers(upb_msg *msg, upb_msgdef *md, upb_handlers *h, - void *closure, upb_status *status); + +/* upb_msgvisitor *************************************************************/ + +// Calls a set of upb_handlers with the contents of a upb_msg. +typedef struct { + upb_fhandlers *fh; + upb_fielddef *f; + uint16_t msgindex; // Only when upb_issubmsg(f). +} upb_msgvisitor_field; + +typedef struct { + upb_msgvisitor_field *fields; + int fields_len; +} upb_msgvisitor_msg; + +typedef struct { + uint16_t msgindex; + uint16_t fieldindex; + uint32_t arrayindex; // UINT32_MAX if not an array frame. +} upb_msgvisitor_frame; + +typedef struct { + upb_msgvisitor_msg *messages; + int messages_len; + upb_dispatcher dispatcher; +} upb_msgvisitor; + +// Initializes a msgvisitor that will push data from messages of the given +// msgdef to the given set of handlers. +void upb_msgvisitor_init(upb_msgvisitor *v, upb_msgdef *md, upb_handlers *h); +void upb_msgvisitor_uninit(upb_msgvisitor *v); + +void upb_msgvisitor_reset(upb_msgvisitor *v, upb_msg *m); +void upb_msgvisitor_visit(upb_msgvisitor *v, upb_status *status); #ifdef __cplusplus } /* extern "C" */ |