5#define _ISOC99_SOURCE 1
20 size_t len =
fread(buf, 1, count, file);
40 stream->bytes_left = 0;
52 printf(
"LATEST BYTES READ (%d to %d): ", position,
g_position);
64 const char *wiretypes[8] = {
"VARINT",
"64BIT",
"STRING",
"SGRP",
"EGRP",
"32BIT",
"????",
"????"};
66 while (stream->bytes_left)
81 printf(
"ERROR: Failed to parse tag: %s\n",
PB_GET_ERROR(stream));
89 printf(
"%sterminating on zero tag\n", indent);
93 printf(
"%sAt %d: field tag %d, wire type %d (%s)",
94 indent, position, (
int)tag, wire_type, wiretypes[wire_type]);
102 printf(
"\n%sERROR: Failed to parse varint: %s\n", indent,
PB_GET_ERROR(stream));
107 printf(
", varint value (%d bytes): %llu\n",
108 g_position - position, (
unsigned long long)value);
116 printf(
"\n%sERROR: Failed to parse fixed64: %s\n", indent,
PB_GET_ERROR(stream));
121 printf(
", fixed64 value (%d bytes): 0x%016llx\n",
122 g_position - position, (
unsigned long long)value);
130 printf(
"\n%sERROR: Failed to parse fixed32: %s\n", indent,
PB_GET_ERROR(stream));
135 printf(
", fixed32 value (%d bytes): 0x%08lx\n",
140 pb_istream_t substream;
144 printf(
"ERROR: Failed to parse string length: %s\n",
PB_GET_ERROR(stream));
151 if (substream.bytes_left == 0)
153 printf(
", empty string\n");
158 snprintf(prefix,
sizeof(prefix),
"f%d> ", (
int)tag);
160 printf(
", string len %d bytes, attempting recursive decode\n",
161 (
int)substream.bytes_left);
165 printf(
"%sfield %d: recursive decode failed, continuing with upper level\n\n",
185 stream.state =
stdin;
MOSAPI void * memmove(void *dest, const void *src, size_t n)
size_t fread(void *__restrict ptr, size_t size, size_t nmemb, FILE *__restrict stream)
int snprintf(char *__restrict str, size_t size, const char *__restrict format,...)
#define PB_GET_ERROR(stream)
bool pb_decode_varint(pb_istream_t *stream, uint64_t *dest)
bool pb_decode_fixed32(pb_istream_t *stream, void *dest)
bool pb_make_string_substream(pb_istream_t *stream, pb_istream_t *substream)
bool pb_close_string_substream(pb_istream_t *stream, pb_istream_t *substream)
bool pb_decode_fixed64(pb_istream_t *stream, void *dest)
bool pb_decode_tag(pb_istream_t *stream, pb_wire_type_t *wire_type, uint32_t *tag, bool *eof)
static void * memcpy(void *s1, const void *s2, size_t n)
unsigned long long uint64_t
void print_history(int position)
static pb_byte_t g_history[32]
bool callback(pb_istream_t *stream, uint8_t *buf, size_t count)
bool raw_decode(pb_istream_t *stream, const char *indent)
#define SET_BINARY_MODE(file)