summaryrefslogtreecommitdiff
path: root/bindings/cpp/upb/handlers.cc
diff options
context:
space:
mode:
Diffstat (limited to 'bindings/cpp/upb/handlers.cc')
-rw-r--r--bindings/cpp/upb/handlers.cc39
1 files changed, 39 insertions, 0 deletions
diff --git a/bindings/cpp/upb/handlers.cc b/bindings/cpp/upb/handlers.cc
new file mode 100644
index 0000000..c96a74e
--- /dev/null
+++ b/bindings/cpp/upb/handlers.cc
@@ -0,0 +1,39 @@
+//
+// upb - a minimalist implementation of protocol buffers.
+//
+// Copyright (c) 2011 Google Inc. See LICENSE for details.
+// Author: Josh Haberman <jhaberman@gmail.com>
+
+#include "handlers.hpp"
+
+#include "def.hpp"
+
+namespace upb {
+
+namespace {
+
+void MessageCallbackWrapper(
+ void* closure, upb_mhandlers* mh, const upb_msgdef* m) {
+ Handlers::MessageRegistrationVisitor* visitor =
+ static_cast<Handlers::MessageRegistrationVisitor*>(closure);
+ visitor->OnMessage(static_cast<MessageHandlers*>(mh),
+ static_cast<const MessageDef*>(m));
+}
+
+void FieldCallbackWrapper(
+ void* closure, upb_fhandlers* fh, const upb_fielddef* f) {
+ Handlers::MessageRegistrationVisitor* visitor =
+ static_cast<Handlers::MessageRegistrationVisitor*>(closure);
+ visitor->OnField(static_cast<FieldHandlers*>(fh),
+ static_cast<const FieldDef*>(f));
+}
+} // namepace
+
+MessageHandlers* Handlers::RegisterMessageDef(
+ const MessageDef& m, Handlers::MessageRegistrationVisitor* visitor) {
+ upb_mhandlers* mh = upb_handlers_regmsgdef(
+ this, &m, &MessageCallbackWrapper, &FieldCallbackWrapper, &visitor);
+ return static_cast<MessageHandlers*>(mh);
+}
+
+} // namespace upb
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback