From 7fefc5c8756fc7568371cffe66cbc0136c6eb31b Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 24 Feb 2009 10:29:29 -0800 Subject: [PATCH] Removed DECODE macro (wasn't buying much). Also decided that groups aren't a TODO -- I don't plan to ever support them (unless there is a real need). --- pbstream.c | 18 ++++++------------ pbstream.h | 7 +++++-- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/pbstream.c b/pbstream.c index 17ad8db0d9..2046ec7624 100644 --- a/pbstream.c +++ b/pbstream.c @@ -225,28 +225,22 @@ static pbstream_status_t parse_tag(char **buf, struct pbstream_tag *tag) static pbstream_status_t parse_unknown_value( char **buf, int buf_offset, struct pbstream_wire_value *wv) { -#define DECODE(dest, func) CHECK(func(buf, &dest)) switch(wv->type) { case PBSTREAM_WIRE_TYPE_VARINT: - DECODE(wv->v.varint, get_v_uint64_t); break; + CHECK(get_v_uint64_t(buf, &wv->v.varint)); break; case PBSTREAM_WIRE_TYPE_64BIT: - DECODE(wv->v._64bit, get_f_uint64_t); break; + CHECK(get_f_uint64_t(buf, &wv->v._64bit)); break; case PBSTREAM_WIRE_TYPE_32BIT: - DECODE(wv->v._32bit, get_f_uint32_t); break; - case PBSTREAM_WIRE_TYPE_DELIMITED: { - uint32_t len; + CHECK(get_f_uint32_t(buf, &wv->v._32bit)); break; + case PBSTREAM_WIRE_TYPE_DELIMITED: wv->v.delimited.offset = buf_offset; - DECODE(len, get_v_uint32_t); - wv->v.delimited.len = (size_t)len; + CHECK(get_v_uint32_t(buf, &wv->v.delimited.len)); break; - } case PBSTREAM_WIRE_TYPE_START_GROUP: case PBSTREAM_WIRE_TYPE_END_GROUP: - /* TODO (though these are deprecated, so not high priority). */ - break; + return PBSTREAM_ERROR_GROUP; /* deprecated, no plans to support. */ } return PBSTREAM_STATUS_OK; -#undef DECODE } #define CALLBACK(s, func, ...) do { \ diff --git a/pbstream.h b/pbstream.h index 3c551d2a5a..a8e623a2a9 100644 --- a/pbstream.h +++ b/pbstream.h @@ -63,7 +63,7 @@ struct pbstream_value { bool _bool; struct pbstream_delimited { size_t offset; /* relative to the beginning of the stream. */ - int len; + uint32_t len; } delimited; int32_t _enum; } v; @@ -82,7 +82,7 @@ struct pbstream_wire_value { uint64_t _64bit; struct { size_t offset; /* relative to the beginning of the stream. */ - int len; + uint32_t len; } delimited; uint32_t _32bit; } v; @@ -154,6 +154,9 @@ typedef enum pbstream_status { // A submessage ended in the middle of data. PBSTREAM_ERROR_BAD_SUBMESSAGE_END, + // Encountered a "group" on the wire (deprecated and unsupported). + PBSTREAM_ERROR_GROUP, + /** NONFATAL ERRORS: the input was invalid, but we can continue if desired. */ // A field marked "required" was not present. */