예제 #1
0
파일: msg.c 프로젝트: alepharchives/upb
bool upb_stdmsg_has(const void *_m, upb_value fval) {
  assert(_m != NULL);
  const char *m = _m;
  const upb_fielddef *f = upb_value_getfielddef(fval);
  return f->hasbit < 0 ||
      (m[(uint32_t)f->hasbit / 8] & (1 << ((uint32_t)f->hasbit % 8)));
}
예제 #2
0
파일: msg.c 프로젝트: alepharchives/upb
void upb_stdmsg_sethas(void *_m, upb_value fval) {
  assert(_m != NULL);
  char *m = _m;
  const upb_fielddef *f = upb_value_getfielddef(fval);
  if (f->hasbit >= 0)
    m[(uint32_t)f->hasbit / 8] |= (1 << ((uint32_t)f->hasbit % 8));
}
예제 #3
0
파일: msg.c 프로젝트: alepharchives/upb
upb_sflow_t upb_stdmsg_startsubmsg_r(void *a, upb_value fval) {
  assert(a != NULL);
  const upb_fielddef *f = upb_value_getfielddef(fval);
  void **subm = upb_stdarray_append((upb_stdarray*)a, sizeof(void*));
  upb_stdmsg_recycle(subm, upb_downcast_msgdef(f->def));
  return UPB_CONTINUE_WITH(*subm);
}
예제 #4
0
파일: msg.c 프로젝트: alepharchives/upb
upb_flow_t upb_stdmsg_setstr(void *_m, upb_value fval, upb_value val) {
  assert(_m != NULL);
  char *m = _m;
  const upb_fielddef *f = upb_value_getfielddef(fval);
  // Hasbit automatically set by the handlers.
  _upb_stdmsg_setstr(&m[f->offset], val);
  return UPB_CONTINUE;
}
예제 #5
0
static upb_sflow_t upb_textprinter_startsubmsg(void *_p, upb_value fval) {
  upb_textprinter *p = _p;
  upb_fielddef *f = upb_value_getfielddef(fval);
  upb_textprinter_indent(p);
  CHECK(upb_bytesink_printf(p->bytesink, &p->status, UPB_STRFMT " {", UPB_STRARG(f->name)));
  if(!p->single_line) upb_bytesink_putstr(p->bytesink, UPB_STRLIT("\n"), &p->status);
  p->indent_depth++;
  return UPB_CONTINUE_WITH(_p);
err:
  return UPB_S_BREAK;
}
예제 #6
0
파일: msg.c 프로젝트: alepharchives/upb
upb_sflow_t upb_stdmsg_startsubmsg(void *_m, upb_value fval) {
  assert(_m != NULL);
  char *m = _m;
  const upb_fielddef *f = upb_value_getfielddef(fval);
  void **subm = (void*)&m[f->offset];
  if (!upb_stdmsg_has(m, fval)) {
    upb_stdmsg_recycle(subm, upb_downcast_msgdef(f->def));
    upb_stdmsg_sethas(m, fval);
  }
  return UPB_CONTINUE_WITH(*subm);
}
예제 #7
0
static upb_flow_t upb_textprinter_value(void *_p, upb_value fval,
                                        upb_value val) {
  upb_textprinter *p = _p;
  upb_fielddef *f = upb_value_getfielddef(fval);
  upb_textprinter_indent(p);
  CHECK(upb_bytesink_printf(p->bytesink, &p->status, UPB_STRFMT ": ", UPB_STRARG(f->name)));
#define CASE(fmtstr, member) \
    CHECK(upb_bytesink_printf(p->bytesink, &p->status, fmtstr, upb_value_get ## member(val))); break;
  switch(f->type) {
    case UPB_TYPE(DOUBLE):
      CASE("%0.f", double);
    case UPB_TYPE(FLOAT):
      CASE("%0.f", float)
    case UPB_TYPE(INT64):
    case UPB_TYPE(SFIXED64):
    case UPB_TYPE(SINT64):
      CASE("%" PRId64, int64)
    case UPB_TYPE(UINT64):
    case UPB_TYPE(FIXED64):
      CASE("%" PRIu64, uint64)
    case UPB_TYPE(UINT32):
    case UPB_TYPE(FIXED32):
      CASE("%" PRIu32, uint32);
    case UPB_TYPE(ENUM): {
      upb_enumdef *enum_def = upb_downcast_enumdef(f->def);
      upb_string *enum_label =
          upb_enumdef_iton(enum_def, upb_value_getint32(val));
      if (enum_label) {
        // We found a corresponding string for this enum.  Otherwise we fall
        // through to the int32 code path.
        CHECK(upb_bytesink_putstr(p->bytesink, enum_label, &p->status));
        break;
      }
    }
    case UPB_TYPE(INT32):
    case UPB_TYPE(SFIXED32):
    case UPB_TYPE(SINT32):
      CASE("%" PRId32, int32)
    case UPB_TYPE(BOOL):
      CASE("%hhu", bool);
    case UPB_TYPE(STRING):
    case UPB_TYPE(BYTES):
      CHECK(upb_bytesink_putstr(p->bytesink, UPB_STRLIT("\""), &p->status));
      CHECK(upb_textprinter_putescaped(p, upb_value_getstr(val),
                                       f->type == UPB_TYPE(STRING)));
      CHECK(upb_bytesink_putstr(p->bytesink, UPB_STRLIT("\""), &p->status));
      break;
  }
  upb_textprinter_endfield(p);
  return UPB_CONTINUE;
err:
  return UPB_BREAK;
}
예제 #8
0
파일: msg.c 프로젝트: alepharchives/upb
upb_sflow_t upb_stdmsg_startseq(void *_m, upb_value fval) {
  char *m = _m;
  const upb_fielddef *f = upb_value_getfielddef(fval);
  upb_stdarray **arr = (void*)&m[f->offset];
  if (!upb_stdmsg_has(_m, fval)) {
    if (!*arr) {
      *arr = malloc(sizeof(**arr));
      (*arr)->size = 0;
      (*arr)->ptr = NULL;
    }
    (*arr)->len = 0;
    upb_stdmsg_sethas(m, fval);
  }
  return UPB_CONTINUE_WITH(*arr);
}