Exemplo n.º 1
0
bool upb_fielddef_resolvedefault(upb_fielddef *f) {
  if (!upb_fielddef_default_is_symbolic(f)) return true;

  upb_byteregion *bytes = upb_value_getbyteregion(f->defaultval);
  const upb_enumdef *e = upb_downcast_enumdef(upb_fielddef_subdef(f));
  assert(bytes);  // Points to either a real default or the empty string.
  assert(e);
  if (upb_byteregion_len(bytes) == 0) {
    // The "default default" for an enum is the first defined value.
    upb_value_setint32(&f->defaultval, e->defaultval);
  } else {
    size_t len;
    int32_t val = 0;
    // ptr is guaranteed to be NULL-terminated because the byteregion was
    // created with upb_byteregion_newl().
    const char *ptr = upb_byteregion_getptr(
        bytes, upb_byteregion_startofs(bytes), &len);
    assert(len == upb_byteregion_len(bytes));  // Should all be in one chunk
    if (!upb_enumdef_ntoi(e, ptr, &val)) {
      return false;
    }
    upb_value_setint32(&f->defaultval, val);
  }
  f->default_is_string = false;
  upb_byteregion_free(bytes);
  return true;
}
Exemplo n.º 2
0
void upb_decoder_resetinput(upb_decoder *d, upb_byteregion *input,
                            void *closure) {
  assert(d->plan);
  assert(upb_byteregion_discardofs(input) == upb_byteregion_startofs(input));
  upb_dispatcher_frame *f =
      upb_dispatcher_reset(&d->dispatcher, closure, d->plan->handlers->msgs[0]);
  upb_status_clear(&d->status);
  f->end_ofs = UPB_NONDELIMITED;
  d->input = input;
  d->str_byteregion.bytesrc = input->bytesrc;

  // Protect against assert in skiptonewbuf().
  d->bufstart_ofs = 0;
  d->ptr = NULL;
  d->buf = NULL;
  upb_decoder_skiptonewbuf(d, upb_byteregion_startofs(input));
}