Implemented the _init_parser() function.

pull/13171/head
Joshua Haberman 16 years ago
parent afe132eb10
commit 1aa1627fc1
  1. 15
      pbstream.c
  2. 2
      pbstream.h

@ -301,3 +301,18 @@ unknown_value:
s->offset += (b-buf); s->offset += (b-buf);
return unknown_value_status; return unknown_value_status;
} }
void pbstream_init_parser(
struct pbstream_parse_state *state,
struct pbstream_message_descriptor *message_descriptor,
void *user_data)
{
state->offset = 0;
state->user_data = user_data;
/* Initial stack of <300b most protobufs are unlikely to nest >20 deep. */
const int initial_stack = 20;
state->top = state->base = malloc(sizeof(*state->base) * initial_stack);
state->limit = state->base + initial_stack;
state->top->message_descriptor = message_descriptor;
state->top->end_offset = SIZE_MAX;
}

@ -127,7 +127,7 @@ struct pbstream_parse_state;
struct pbstream_parse_stack_frame { struct pbstream_parse_stack_frame {
struct pbstream_message_descriptor *message_descriptor; struct pbstream_message_descriptor *message_descriptor;
int end_offset; /* unknown for the top frame, so we set to INT_MAX */ size_t end_offset; /* unknown for the top frame, so we set to SIZE_MAX */
}; };
/* The stream parser's state. */ /* The stream parser's state. */

Loading…
Cancel
Save