static inline int pb_decode_tag(pb_field_t *f) { if (pb_decode_varint(f)) { if(f->left == 0) f->eom = 1; // signal end-of-message return -1; } if (f->val.i64 == 0) { f->eom = 1; // Allow 0-terminated messages. PB_RETURN_ERROR(f, -2, "0-terminated msg"); } f->tag = f->val.i64 >> 3; f->type = (pb_wire_type_t)(f->val.i32 & 7); DBGOUT("tag %u, type %u\n", f->tag, f->type); switch (f->type) { case PB_WT_VARINT: return pb_decode_varint(f); case PB_WT_FIXED64: return pb_decode_fixed64(f); case PB_WT_STRING: return pb_decode_string(f); case PB_WT_FIXED32: return pb_decode_fixed32(f); default: PB_RETURN_ERROR(f, -3, "invalid wire_type"); } return 0; }
static bool read_fixed64(pb_istream_t *stream, const pb_field_t *field, void **arg) { uint64_t value; if (!pb_decode_fixed64(stream, &value)) return false; TEST(value == *(uint64_t*)*arg); return true; }
static bool read_repeated_fixed64(pb_istream_t *stream, const pb_field_t *field, void **arg) { uint64_t** expected = (uint64_t**)arg; uint64_t value; if (!pb_decode_fixed64(stream, &value)) return false; TEST(*(*expected)++ == value); return true; }