bool upb_def_setfullname(upb_def *def, const char *fullname, upb_status *s) { assert(!upb_def_isfrozen(def)); if (!upb_isident(fullname, strlen(fullname), true, s)) return false; free((void*)def->fullname); def->fullname = upb_strdup(fullname); return true; }
bool upb_fielddef_setdefaultstr(upb_fielddef *f, const void *str, size_t len, upb_status *s) { assert(upb_fielddef_isstring(f) || f->type_ == UPB_TYPE_ENUM); if (f->type_ == UPB_TYPE_ENUM && !upb_isident(str, len, false, s)) return false; if (f->default_is_string) { str_t *s = upb_value_getptr(f->defaultval); assert(s); freestr(s); } else { assert(f->type_ == UPB_TYPE_ENUM); } str_t *str2 = newstr(str, len); upb_value_setptr(&f->defaultval, str2); f->default_is_string = true; return true; }
bool upb_fielddef_setdefaultstr(upb_fielddef *f, const void *str, size_t len) { assert(upb_fielddef_isstring(f) || f->type_ == UPB_TYPE(ENUM)); if (f->type_ == UPB_TYPE(ENUM) && !upb_isident(str, len, false)) return false; if (f->default_is_string) { upb_byteregion *bytes = upb_value_getbyteregion(f->defaultval); assert(bytes); upb_byteregion_free(bytes); } else { assert(f->type_ == UPB_TYPE(ENUM)); } upb_byteregion *r = upb_byteregion_newl(str, len); upb_value_setbyteregion(&f->defaultval, r); upb_bytesuccess_t ret = upb_byteregion_fetch(r); UPB_ASSERT_VAR(ret, ret == (len == 0 ? UPB_BYTE_EOF : UPB_BYTE_OK)); assert(upb_byteregion_available(r, 0) == upb_byteregion_len(r)); f->default_is_string = true; return true; }
bool upb_enumdef_addval(upb_enumdef *e, const char *name, int32_t num, upb_status *status) { if (!upb_isident(name, strlen(name), false, status)) { return false; } if (upb_enumdef_ntoi(e, name, NULL)) { upb_status_seterrf(status, "name '%s' is already defined", name); return false; } if (!upb_strtable_insert(&e->ntoi, name, upb_value_int32(num))) { upb_status_seterrliteral(status, "out of memory"); return false; } if (!upb_inttable_lookup(&e->iton, num, NULL) && !upb_inttable_insert(&e->iton, num, upb_value_cstr(upb_strdup(name)))) { upb_status_seterrliteral(status, "out of memory"); upb_strtable_remove(&e->ntoi, name, NULL); return false; } return true; }