summaryrefslogtreecommitdiff
path: root/core/upb_stream.c
blob: bda11dec94fd3c0f43cbdf20c600d8aa2cd1a356 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
 * upb - a minimalist implementation of protocol buffers.
 *
 * Copyright (c) 2010 Joshua Haberman.  See LICENSE for details.
 */

#include "upb_stream.h"

#include "upb_def.h"

#define CHECKSRC(x) if(!x) goto src_err
#define CHECKSINK(x) if(!x) goto sink_err

void upb_streamdata(upb_src *src, upb_sink *sink, upb_status *status) {
  upb_fielddef *f;
  upb_string *str = NULL;
  while((f = upb_src_getdef(src)) != NULL) {
    CHECKSINK(upb_sink_putdef(sink, f));
    if(upb_issubmsg(f)) {
      // We always recurse into submessages, but the putdef above already told
      // the sink that.
    } else if(upb_isstring(f)) {
      str = upb_string_tryrecycle(str);
      CHECKSRC(upb_src_getstr(src, str));
      CHECKSINK(upb_sink_putstr(sink, str));
    } else {
      // 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));
  return;

src_err:
  upb_copyerr(status, upb_src_status(src));
  return;

sink_err:
  upb_copyerr(status, upb_sink_status(sink));
  return;
}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback