From 1aa1627fc1ccf0e22d87d2b71ad356a1150190f2 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Wed, 25 Feb 2009 15:49:57 -0800 Subject: Implemented the _init_parser() function. --- pbstream.c | 15 +++++++++++++++ pbstream.h | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pbstream.c b/pbstream.c index ae61df8..441b216 100644 --- a/pbstream.c +++ b/pbstream.c @@ -301,3 +301,18 @@ unknown_value: s->offset += (b-buf); 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; +} diff --git a/pbstream.h b/pbstream.h index 9cc9578..9277843 100644 --- a/pbstream.h +++ b/pbstream.h @@ -127,7 +127,7 @@ struct pbstream_parse_state; struct pbstream_parse_stack_frame { 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. */ -- cgit v1.2.3