From 15c388b819ebfebb83851950893413041288970f Mon Sep 17 00:00:00 2001 From: Josh Haberman Date: Mon, 12 Dec 2016 18:47:55 +0000 Subject: Basic serialization for upb_msg and Lua. Doesn't yet include strings, submessages, maps, or repeated fields. --- upb/sink.h | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) (limited to 'upb/sink.h') 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, \ -- cgit v1.2.3 From ce1f63fde226f367c1ce2172a416d9b9f57c297e Mon Sep 17 00:00:00 2001 From: Josh Haberman Date: Mon, 12 Dec 2016 18:57:13 +0000 Subject: A few C++ fixes for BufferSink. --- upb/sink.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'upb/sink.h') diff --git a/upb/sink.h b/upb/sink.h index d44cb60..a50bafb 100644 --- a/upb/sink.h +++ b/upb/sink.h @@ -22,6 +22,7 @@ #ifdef __cplusplus namespace upb { +class BufferSink; class BufferSource; class BytesSink; class Sink; @@ -213,6 +214,8 @@ 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); -- cgit v1.2.3