Fixed broken submsg support in upb_streamdata.

pull/13171/head
Joshua Haberman 15 years ago
parent af9d691a34
commit b77db14646
  1. 38
      core/upb_stream.c
  2. 2
      stream/upb_textprinter.c

@ -14,24 +14,30 @@
void upb_streamdata(upb_src *src, upb_sink *sink, upb_status *status) { void upb_streamdata(upb_src *src, upb_sink *sink, upb_status *status) {
upb_fielddef *f; upb_fielddef *f;
upb_string *str = NULL; upb_string *str = NULL;
while((f = upb_src_getdef(src)) != NULL) { int depth = 0;
CHECKSINK(upb_sink_putdef(sink, f)); while(1) {
if(upb_issubmsg(f)) { while((f = upb_src_getdef(src)) != NULL) {
// We always recurse into submessages, but the putdef above already told CHECKSINK(upb_sink_putdef(sink, f));
// the sink that. if(upb_issubmsg(f)) {
} else if(upb_isstring(f)) { upb_src_startmsg(src);
str = upb_string_tryrecycle(str); upb_sink_startmsg(sink);
CHECKSRC(upb_src_getstr(src, str)); ++depth;
CHECKSINK(upb_sink_putstr(sink, str)); } else if(upb_isstring(f)) {
} else { str = upb_string_tryrecycle(str);
// Primitive type. CHECKSRC(upb_src_getstr(src, str));
upb_value val; CHECKSINK(upb_sink_putstr(sink, str));
CHECKSRC(upb_src_getval(src, upb_value_addrof(&val))); } else {
CHECKSINK(upb_sink_putval(sink, val)); // Primitive type.
upb_value val;
CHECKSRC(upb_src_getval(src, upb_value_addrof(&val)));
CHECKSINK(upb_sink_putval(sink, val));
}
} }
// If we're not EOF now, the loop terminated due to an error.
CHECKSRC(upb_src_eof(src));
if (depth == 0) break;
--depth;
} }
// If we're not EOF now, the loop terminated due to an error.
CHECKSRC(upb_src_eof(src));
return; return;
src_err: src_err:

@ -79,7 +79,7 @@ static bool upb_textprinter_putdef(upb_textprinter *p, upb_fielddef *f)
{ {
upb_textprinter_indent(p); upb_textprinter_indent(p);
upb_bytesink_put(p->bytesink, f->name); upb_bytesink_put(p->bytesink, f->name);
upb_bytesink_put(p->bytesink, UPB_STRLIT(":")); upb_bytesink_put(p->bytesink, UPB_STRLIT(": "));
p->f = f; p->f = f;
return upb_ok(upb_bytesink_status(p->bytesink)); return upb_ok(upb_bytesink_status(p->bytesink));
} }

Loading…
Cancel
Save