summaryrefslogtreecommitdiff
path: root/upb/sink.h
diff options
context:
space:
mode:
authorJosh Haberman <jhaberman@gmail.com>2016-12-12 18:47:55 +0000
committerJosh Haberman <jhaberman@gmail.com>2016-12-12 18:52:20 +0000
commit15c388b819ebfebb83851950893413041288970f (patch)
tree2c266da71bda82fdcc641f4af9bf0e406396f49f /upb/sink.h
parent076a82ee7edf35fb5f2a3430535e21a6dbd4cd6d (diff)
Basic serialization for upb_msg and Lua.
Doesn't yet include strings, submessages, maps, or repeated fields.
Diffstat (limited to 'upb/sink.h')
-rw-r--r--upb/sink.h26
1 files changed, 8 insertions, 18 deletions
diff --git a/upb/sink.h b/upb/sink.h
index 765916e..d44cb60 100644
--- a/upb/sink.h
+++ b/upb/sink.h
@@ -28,6 +28,7 @@ class Sink;
}
#endif
+UPB_DECLARE_TYPE(upb::BufferSink, upb_bufsink)
UPB_DECLARE_TYPE(upb::BufferSource, upb_bufsrc)
UPB_DECLARE_TYPE(upb::BytesSink, upb_bytessink)
UPB_DECLARE_TYPE(upb::Sink, upb_sink)
@@ -212,7 +213,12 @@ struct upb_bufsrc {
#endif
};
-UPB_BEGIN_EXTERN_C
+/* A class for accumulating output string data in a flat buffer. */
+
+upb_bufsink *upb_bufsink_new(upb_env *env);
+void upb_bufsink_free(upb_bufsink *sink);
+upb_bytessink *upb_bufsink_sink(upb_bufsink *sink);
+const char *upb_bufsink_getdata(const upb_bufsink *sink, size_t *len);
/* Inline definitions. */
@@ -263,23 +269,7 @@ UPB_INLINE bool upb_bytessink_end(upb_bytessink *s) {
&s->handler->table[UPB_ENDSTR_SELECTOR].attr));
}
-UPB_INLINE bool upb_bufsrc_putbuf(const char *buf, size_t len,
- upb_bytessink *sink) {
- void *subc;
- bool ret;
- upb_bufhandle handle;
- upb_bufhandle_init(&handle);
- upb_bufhandle_setbuf(&handle, buf, 0);
- ret = upb_bytessink_start(sink, len, &subc);
- if (ret && len != 0) {
- ret = (upb_bytessink_putbuf(sink, subc, buf, len, &handle) >= len);
- }
- if (ret) {
- ret = upb_bytessink_end(sink);
- }
- upb_bufhandle_uninit(&handle);
- return ret;
-}
+bool upb_bufsrc_putbuf(const char *buf, size_t len, upb_bytessink *sink);
#define PUTVAL(type, ctype) \
UPB_INLINE bool upb_sink_put##type(upb_sink *s, upb_selector_t sel, \
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback