upb_strstream compiles again.

That covers all source files except upb_msg!
pull/13171/head
Joshua Haberman 14 years ago
parent 8536bbc5f8
commit 93099cccd1
  1. 4
      Makefile
  2. 50
      stream/upb_strstream.c

@ -64,9 +64,9 @@ SRC=core/upb.c \
core/upb_def.c \
stream/upb_decoder.c \
stream/upb_stdio.c \
stream/upb_textprinter.c
stream/upb_textprinter.c \
stream/upb_strstream.c \
# core/upb_msg.c \
# stream/upb_strstream.c \
$(SRC): perf-cppflags
# Parts of core that are yet to be converted.

@ -12,6 +12,7 @@
struct upb_stringsrc {
upb_bytesrc bytesrc;
upb_string *str;
upb_strlen_t offset;
};
void upb_stringsrc_reset(upb_stringsrc *s, upb_string *str) {
@ -27,34 +28,41 @@ void upb_stringsrc_free(upb_stringsrc *s) {
free(s);
}
static bool upb_stringsrc_get(upb_stringsrc *src, upb_string *str,
upb_strlen_t minlen) {
// We ignore "minlen" since we always return the entire string.
(void)minlen;
upb_string_substr(str, src->str, 0, upb_string_len(src->str));
src->bytesrc.eof = true;
return true;
static upb_strlen_t upb_stringsrc_read(upb_bytesrc *_src, void *buf,
upb_strlen_t count, upb_status *status) {
upb_stringsrc *src = (upb_stringsrc*)_src;
if (src->offset == upb_string_len(src->str)) {
upb_seterr(status, UPB_EOF, "");
return -1;
} else {
upb_strlen_t to_read = UPB_MIN(count, upb_string_len(src->str) - src->offset);
memcpy(buf, upb_string_getrobuf(src->str) + src->offset, to_read);
src->offset += to_read;
return to_read;
}
}
static bool upb_stringsrc_append(upb_stringsrc *src, upb_string *str,
upb_strlen_t len) {
// Unimplemented; since we return the string via "get" all in one go,
// this method probably isn't very useful.
(void)src;
(void)str;
(void)len;
return false;
static bool upb_stringsrc_getstr(upb_bytesrc *_src, upb_string *str,
upb_status *status) {
upb_stringsrc *src = (upb_stringsrc*)_src;
if (src->offset == upb_string_len(str)) {
upb_seterr(status, UPB_EOF, "");
return false;
} else {
upb_string_substr(str, src->str, 0, upb_string_len(src->str));
return true;
}
}
static upb_bytesrc_vtable upb_stringsrc_vtbl = {
(upb_bytesrc_get_fptr)upb_stringsrc_get,
(upb_bytesrc_append_fptr)upb_stringsrc_append,
};
upb_stringsrc *upb_stringsrc_new() {
static upb_bytesrc_vtbl bytesrc_vtbl = {
upb_stringsrc_read,
upb_stringsrc_getstr,
};
upb_stringsrc *s = malloc(sizeof(*s));
s->str = NULL;
upb_bytesrc_init(&s->bytesrc, &upb_stringsrc_vtbl);
upb_bytesrc_init(&s->bytesrc, &bytesrc_vtbl);
return s;
}

Loading…
Cancel
Save