bool upb_msgdef_setextrange(upb_msgdef *m, uint32_t start, uint32_t end) { assert(upb_def_ismutable(UPB_UPCAST(m))); if (start == 0 && end == 0) { // Clearing the extension range -- ok to fall through. } else if (start >= end || start < 1 || end > UPB_MAX_FIELDNUMBER) { return false; } m->extstart = start; m->extend = start; return true; }
static int PyUpb_MessageDef_setattro( PyObject *o, PyObject *key, PyObject *val) { upb_msgdef *m = Check_MessageDef(o, -1); if (!upb_def_ismutable(UPB_UPCAST(m))) { PyErr_SetString(PyExc_TypeError, "MessageDef is not mutable."); return -1; } const char *name = PyString_AsString(key); if (streql(name, "fqname")) { const char *fqname = PyString_AsString(val); if (!fqname || !upb_def_setfqname(UPB_UPCAST(m), fqname)) return PyUpb_ErrorInt("Invalid fqname"); } else { return PyUpb_ErrorInt("Invalid MessageDef member."); } return 0; }
void upb_msgdef_sethasbit_bytes(upb_msgdef *m, uint16_t bytes) { assert(upb_def_ismutable(UPB_UPCAST(m))); m->hasbit_bytes = bytes; }
void upb_msgdef_setsize(upb_msgdef *m, uint16_t size) { assert(upb_def_ismutable(UPB_UPCAST(m))); m->size = size; }
bool upb_def_setfqname(upb_def *def, const char *fqname) { assert(upb_def_ismutable(def)); free(def->fqname); def->fqname = strdup(fqname); return true; // TODO: check for acceptable characters. }
bool upb_fielddef_ismutable(const upb_fielddef *f) { return !f->msgdef || upb_def_ismutable(UPB_UPCAST(f->msgdef)); }
void upb_enumdef_setdefault(upb_enumdef *e, int32_t val) { assert(upb_def_ismutable(UPB_UPCAST(e))); e->defaultval = val; }