示例#1
0
文件: reader.c 项目: YauzZ/upb
static bool file_endmsg(void *closure, const void *hd, upb_status *status) {
  UPB_UNUSED(hd);
  UPB_UNUSED(status);
  upb_descreader *r = closure;
  upb_descreader_endcontainer(r);
  return true;
}
示例#2
0
文件: reader.c 项目: YauzZ/upb
static size_t file_onpackage(void *closure, const void *hd, const char *buf,
                             size_t n, const upb_bufhandle *handle) {
  UPB_UNUSED(hd);
  UPB_UNUSED(handle);
  upb_descreader *r = closure;
  // XXX: see comment at the top of the file.
  upb_descreader_setscopename(r, upb_strndup(buf, n));
  return n;
}
示例#3
0
文件: encoder.c 项目: gityf/upb
static bool endmsg(void *c, const void *hd, upb_status *status) {
  upb_pb_encoder *e = c;
  UPB_UNUSED(hd);
  UPB_UNUSED(status);
  if (--e->depth == 0) {
    upb_bytessink_end(e->output_);
  }
  return true;
}
示例#4
0
文件: textprinter.c 项目: atdt/upb
static bool textprinter_endmsg(void *c, const void *hd, upb_status *s) {
  upb_textprinter *p = c;
  UPB_UNUSED(hd);
  UPB_UNUSED(s);
  if (p->indent_depth_ == 0) {
    upb_bytessink_end(p->output_);
  }
  return true;
}
示例#5
0
int run_tests(int argc, char *argv[]) {
    UPB_UNUSED(argc);
    UPB_UNUSED(argv);
    test_check2_branch32();
    test_check2_branch64();
    test_check2_wright();
    test_check2_massimino();
    return 0;
}
示例#6
0
文件: reader.c 项目: YauzZ/upb
static size_t enumval_onname(void *closure, const void *hd, const char *buf,
                             size_t n, const upb_bufhandle *handle) {
  UPB_UNUSED(hd);
  UPB_UNUSED(handle);
  upb_descreader *r = closure;
  // XXX: see comment at the top of the file.
  free(r->name);
  r->name = upb_strndup(buf, n);
  r->saw_name = true;
  return n;
}
示例#7
0
文件: reader.c 项目: YauzZ/upb
static size_t field_onextendee(void *closure, const void *hd, const char *buf,
                               size_t n, const upb_bufhandle *handle) {
  UPB_UNUSED(hd);
  UPB_UNUSED(handle);
  upb_descreader *r = closure;
  // XXX: see comment at the top of the file.
  char *name = upb_strndup(buf, n);
  upb_fielddef_setcontainingtypename(r->f, name, NULL);
  free(name);
  return n;
}
示例#8
0
文件: reader.c 项目: YauzZ/upb
static size_t enum_onname(void *closure, const void *hd, const char *buf,
                          size_t n, const upb_bufhandle *handle) {
  UPB_UNUSED(hd);
  UPB_UNUSED(handle);
  upb_descreader *r = closure;
  // XXX: see comment at the top of the file.
  char *fullname = upb_strndup(buf, n);
  upb_def_setfullname(upb_descreader_last(r), fullname, NULL);
  free(fullname);
  return n;
}
示例#9
0
文件: reader.c 项目: YauzZ/upb
static size_t field_ondefaultval(void *closure, const void *hd, const char *buf,
                                 size_t n, const upb_bufhandle *handle) {
  UPB_UNUSED(hd);
  UPB_UNUSED(handle);
  upb_descreader *r = closure;
  // Have to convert from string to the correct type, but we might not know the
  // type yet, so we save it as a string until the end of the field.
  // XXX: see comment at the top of the file.
  free(r->default_string);
  r->default_string = upb_strndup(buf, n);
  return n;
}
示例#10
0
文件: reader.c 项目: YauzZ/upb
static size_t msg_onname(void *closure, const void *hd, const char *buf,
                         size_t n, const upb_bufhandle *handle) {
  UPB_UNUSED(hd);
  UPB_UNUSED(handle);
  upb_descreader *r = closure;
  upb_msgdef *m = upb_descreader_top(r);
  // XXX: see comment at the top of the file.
  char *name = upb_strndup(buf, n);
  upb_def_setfullname(UPB_UPCAST(m), name, NULL);
  upb_descreader_setscopename(r, name);  // Passes ownership of name.
  return n;
}
示例#11
0
文件: reader.c 项目: YauzZ/upb
static bool enumval_onnumber(void *closure, const void *hd, int32_t val) {
  UPB_UNUSED(hd);
  upb_descreader *r = closure;
  r->number = val;
  r->saw_number = true;
  return true;
}
示例#12
0
文件: reader.c 项目: YauzZ/upb
// Handlers for google.protobuf.EnumValueDescriptorProto.
static bool enumval_startmsg(void *closure, const void *hd) {
  UPB_UNUSED(hd);
  upb_descreader *r = closure;
  r->saw_number = false;
  r->saw_name = false;
  return true;
}
示例#13
0
static bool enumval_onnumber(void *_r, void *fval, int32_t val) {
  UPB_UNUSED(fval);
  upb_descreader *r = _r;
  r->number = val;
  r->saw_number = true;
  return true;
}
示例#14
0
文件: reader.c 项目: YauzZ/upb
static bool field_endmsg(void *closure, const void *hd, upb_status *status) {
  UPB_UNUSED(hd);
  upb_descreader *r = closure;
  upb_fielddef *f = r->f;
  // TODO: verify that all required fields were present.
  assert(upb_fielddef_number(f) != 0);
  assert(upb_fielddef_name(f) != NULL);
  assert((upb_fielddef_subdefname(f) != NULL) == upb_fielddef_hassubdef(f));

  if (r->default_string) {
    if (upb_fielddef_issubmsg(f)) {
      upb_status_seterrmsg(status, "Submessages cannot have defaults.");
      return false;
    }
    if (upb_fielddef_isstring(f) || upb_fielddef_type(f) == UPB_TYPE_ENUM) {
      upb_fielddef_setdefaultcstr(f, r->default_string, NULL);
    } else {
      if (r->default_string && !parse_default(r->default_string, f)) {
        // We don't worry too much about giving a great error message since the
        // compiler should have ensured this was correct.
        upb_status_seterrmsg(status, "Error converting default value.");
        return false;
      }
    }
  }
  return true;
}
示例#15
0
文件: reader.c 项目: YauzZ/upb
// Handlers for google.protobuf.DescriptorProto (representing a message).
static bool msg_startmsg(void *closure, const void *hd) {
  UPB_UNUSED(hd);
  upb_descreader *r = closure;
  upb_deflist_push(&r->defs, UPB_UPCAST(upb_msgdef_new(&r->defs)));
  upb_descreader_startcontainer(r);
  return true;
}
示例#16
0
文件: textprinter.c 项目: atdt/upb
static bool textprinter_endstr(void *closure, const void *handler_data) {
  upb_textprinter *p = closure;
  UPB_UNUSED(handler_data);
  putf(p, "\"");
  endfield(p);
  return true;
}
示例#17
0
文件: reader.c 项目: YauzZ/upb
static bool field_onnumber(void *closure, const void *hd, int32_t val) {
  UPB_UNUSED(hd);
  upb_descreader *r = closure;
  bool ok = upb_fielddef_setnumber(r->f, val, NULL);
  UPB_ASSERT_VAR(ok, ok);
  return true;
}
示例#18
0
static size_t file_onpackage(void *_r, void *fval, const char *buf, size_t n) {
  UPB_UNUSED(fval);
  upb_descreader *r = _r;
  // XXX: see comment at the top of the file.
  upb_descreader_setscopename(r, upb_strndup(buf, n));
  return n;
}
示例#19
0
文件: textprinter.c 项目: atdt/upb
static bool textprinter_startmsg(void *c, const void *hd) {
  upb_textprinter *p = c;
  UPB_UNUSED(hd);
  if (p->indent_depth_ == 0) {
    upb_bytessink_start(p->output_, 0, &p->subc);
  }
  return true;
}
示例#20
0
文件: encoder.c 项目: gityf/upb
static bool startmsg(void *c, const void *hd) {
  upb_pb_encoder *e = c;
  UPB_UNUSED(hd);
  if (e->depth++ == 0) {
    upb_bytessink_start(e->output_, 0, &e->subc);
  }
  return true;
}
示例#21
0
文件: reader.c 项目: YauzZ/upb
static bool msg_onendfield(void *closure, const void *hd) {
  UPB_UNUSED(hd);
  upb_descreader *r = closure;
  upb_msgdef *m = upb_descreader_top(r);
  upb_msgdef_addfield(m, r->f, &r->defs, NULL);
  r->f = NULL;
  return true;
}
示例#22
0
static bool msg_onendfield(void *_r, void *fval) {
  UPB_UNUSED(fval);
  upb_descreader *r = _r;
  upb_msgdef *m = upb_descreader_top(r);
  upb_msgdef_addfield(m, r->f, &r->defs);
  r->f = NULL;
  return true;
}
示例#23
0
static bool discardfield(void *_r, void *fval) {
  UPB_UNUSED(fval);
  upb_descreader *r = _r;
  // Discard extension field so we don't leak it.
  upb_fielddef_unref(r->f, &r->defs);
  r->f = NULL;
  return true;
}
示例#24
0
文件: reader.c 项目: YauzZ/upb
// Handlers for google.protobuf.FieldDescriptorProto
static bool field_startmsg(void *closure, const void *hd) {
  UPB_UNUSED(hd);
  upb_descreader *r = closure;
  r->f = upb_fielddef_new(&r->defs);
  free(r->default_string);
  r->default_string = NULL;
  return true;
}
示例#25
0
文件: textprinter.c 项目: atdt/upb
static void onmreg(const void *c, upb_handlers *h) {
  const upb_msgdef *m = upb_handlers_msgdef(h);
  upb_msg_field_iter i;
  UPB_UNUSED(c);

  upb_handlers_setstartmsg(h, textprinter_startmsg, NULL);
  upb_handlers_setendmsg(h, textprinter_endmsg, NULL);

  for(upb_msg_field_begin(&i, m);
      !upb_msg_field_done(&i);
      upb_msg_field_next(&i)) {
    upb_fielddef *f = upb_msg_iter_field(&i);
    upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER;
    upb_handlerattr_sethandlerdata(&attr, f);
    switch (upb_fielddef_type(f)) {
      case UPB_TYPE_INT32:
        upb_handlers_setint32(h, f, textprinter_putint32, &attr);
        break;
      case UPB_TYPE_INT64:
        upb_handlers_setint64(h, f, textprinter_putint64, &attr);
        break;
      case UPB_TYPE_UINT32:
        upb_handlers_setuint32(h, f, textprinter_putuint32, &attr);
        break;
      case UPB_TYPE_UINT64:
        upb_handlers_setuint64(h, f, textprinter_putuint64, &attr);
        break;
      case UPB_TYPE_FLOAT:
        upb_handlers_setfloat(h, f, textprinter_putfloat, &attr);
        break;
      case UPB_TYPE_DOUBLE:
        upb_handlers_setdouble(h, f, textprinter_putdouble, &attr);
        break;
      case UPB_TYPE_BOOL:
        upb_handlers_setbool(h, f, textprinter_putbool, &attr);
        break;
      case UPB_TYPE_STRING:
      case UPB_TYPE_BYTES:
        upb_handlers_setstartstr(h, f, textprinter_startstr, &attr);
        upb_handlers_setstring(h, f, textprinter_putstr, &attr);
        upb_handlers_setendstr(h, f, textprinter_endstr, &attr);
        break;
      case UPB_TYPE_MESSAGE: {
        const char *name =
            upb_fielddef_istagdelim(f)
                ? shortname(upb_msgdef_fullname(upb_fielddef_msgsubdef(f)))
                : upb_fielddef_name(f);
        upb_handlerattr_sethandlerdata(&attr, name);
        upb_handlers_setstartsubmsg(h, f, textprinter_startsubmsg, &attr);
        upb_handlers_setendsubmsg(h, f, textprinter_endsubmsg, &attr);
        break;
      }
      case UPB_TYPE_ENUM:
        upb_handlers_setint32(h, f, textprinter_putenum, &attr);
        break;
    }
  }
}
示例#26
0
文件: textprinter.c 项目: atdt/upb
static void *textprinter_startstr(void *closure, const void *handler_data,
                      size_t size_hint) {
  upb_textprinter *p = closure;
  const upb_fielddef *f = handler_data;
  UPB_UNUSED(size_hint);
  indent(p);
  putf(p, "%s: \"", upb_fielddef_name(f));
  return p;
}
示例#27
0
static size_t enum_onname(void *_r, void *fval, const char *buf, size_t n) {
  UPB_UNUSED(fval);
  upb_descreader *r = _r;
  // XXX: see comment at the top of the file.
  char *fullname = upb_strndup(buf, n);
  upb_def_setfullname(upb_descreader_last(r), fullname);
  free(fullname);
  return n;
}
示例#28
0
static size_t field_onname(void *_r, void *fval, const char *buf, size_t n) {
  UPB_UNUSED(fval);
  upb_descreader *r = _r;
  // XXX: see comment at the top of the file.
  char *name = upb_strndup(buf, n);
  upb_fielddef_setname(r->f, name);
  free(name);
  return n;
}
示例#29
0
文件: reader.c 项目: YauzZ/upb
static bool pushextension(void *closure, const void *hd) {
  UPB_UNUSED(hd);
  upb_descreader *r = closure;
  assert(upb_fielddef_containingtypename(r->f));
  upb_fielddef_setisextension(r->f, true);
  upb_deflist_push(&r->defs, UPB_UPCAST(r->f));
  r->f = NULL;
  return true;
}
示例#30
0
文件: reader.c 项目: YauzZ/upb
void upb_descreader_init(upb_descreader *r, const upb_handlers *handlers,
                         upb_status *status) {
  UPB_UNUSED(status);
  upb_deflist_init(&r->defs);
  upb_sink_reset(upb_descreader_input(r), handlers, r);
  r->stack_len = 0;
  r->name = NULL;
  r->default_string = NULL;
}