summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorJoshua Haberman <joshua@reverberate.org>2011-01-29 12:07:09 -0800
committerJoshua Haberman <joshua@reverberate.org>2011-01-29 12:07:09 -0800
commitd98db7cb567f17a3bb56e2af8499d2e3aef03b3b (patch)
tree77efc5010829b4a8e718e6d56689c2c14f18bcbd /core
parentfbb9fd35e05b88908beeca2c2b88b15aec1fca01 (diff)
Textprinter is compiling again.
Diffstat (limited to 'core')
-rw-r--r--core/upb_stream.h22
-rw-r--r--core/upb_stream_vtbl.h21
2 files changed, 32 insertions, 11 deletions
diff --git a/core/upb_stream.h b/core/upb_stream.h
index 09e4025..aa23549 100644
--- a/core/upb_stream.h
+++ b/core/upb_stream.h
@@ -245,16 +245,26 @@ INLINE bool upb_value_getfullstr(upb_value val, upb_string *str,
struct _upb_bytesink;
typedef struct _upb_bytesink upb_bytesink;
-INLINE bool upb_bytesink_printf(upb_bytesink *sink, const char *fmt, ...);
+// TODO: Figure out how buffering should be handled. Should the caller buffer
+// data and only call these functions when a buffer is full? Seems most
+// efficient, but then buffering has to be configured in the caller, which
+// could be anything, which makes it hard to have a standard interface for
+// controlling buffering.
+//
+// The downside of having the bytesink buffer is efficiency: the caller is
+// making more (virtual) function calls, and the caller can't arrange to have
+// a big contiguous buffer. The bytesink can do this, but will have to copy
+// to make the data contiguous.
+
+// Returns the number of bytes written.
+INLINE upb_strlen_t upb_bytesink_printf(upb_bytesink *sink, upb_status *status,
+ const char *fmt, ...);
// Puts the given string, returning true if the operation was successful, otherwise
// check "status" for details. Ownership of the string is *not* passed; if
// the callee wants a reference he must call upb_string_getref() on it.
-INLINE bool upb_bytesink_putstr(upb_bytesink *sink, upb_string *str,
- upb_status *status);
-
-// Returns the current error status for the stream.
-INLINE upb_status *upb_bytesink_status(upb_bytesink *sink);
+INLINE upb_strlen_t upb_bytesink_putstr(upb_bytesink *sink, upb_string *str,
+ upb_status *status);
#include "upb_stream_vtbl.h"
diff --git a/core/upb_stream_vtbl.h b/core/upb_stream_vtbl.h
index ef655fd..8e8971f 100644
--- a/core/upb_stream_vtbl.h
+++ b/core/upb_stream_vtbl.h
@@ -34,8 +34,10 @@ typedef bool (*upb_bytesrc_getstr_fptr)(
// upb_bytesink.
typedef upb_strlen_t (*upb_bytesink_write_fptr)(
upb_bytesink *bytesink, void *buf, upb_strlen_t count);
-typedef upb_strlen_t (*upb_bytesink_putstr_fptr)(
- upb_bytesink *bytesink, upb_string *str);
+typedef bool (*upb_bytesink_putstr_fptr)(
+ upb_bytesink *bytesink, upb_string *str, upb_status *status);
+typedef upb_strlen_t (*upb_bytesink_vprintf_fptr)(
+ upb_status *status, const char *fmt, va_list args);
// Vtables for the above interfaces.
typedef struct {
@@ -44,8 +46,9 @@ typedef struct {
} upb_bytesrc_vtbl;
typedef struct {
- upb_bytesink_write_fptr write;
- upb_bytesink_putstr_fptr putstr;
+ upb_bytesink_write_fptr write;
+ upb_bytesink_putstr_fptr putstr;
+ upb_bytesink_vprintf_fptr vprintf;
} upb_bytesink_vtbl;
typedef struct {
@@ -140,13 +143,21 @@ INLINE upb_strlen_t upb_bytesink_write(upb_bytesink *sink, void *buf,
}
INLINE upb_strlen_t upb_bytesink_putstr(upb_bytesink *sink, upb_string *str, upb_status *status) {
- return sink->vtbl->putstr(sink, str);
+ return sink->vtbl->putstr(sink, str, status);
}
INLINE upb_status *upb_bytesink_status(upb_bytesink *sink) {
return &sink->status;
}
+INLINE upb_strlen_t upb_bytesink_printf(upb_bytesink *sink, upb_status *status, const char *fmt, ...) {
+ va_list args;
+ va_start(args, fmt);
+ upb_strlen_t ret = sink->vtbl->vprintf(status, fmt, args);
+ va_end(args);
+ return ret;
+}
+
// upb_handlers
struct _upb_handlers {
upb_handlerset *set;
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback