diff options
author | Joshua Haberman <joshua@reverberate.org> | 2011-02-22 01:54:31 -0800 |
---|---|---|
committer | Joshua Haberman <joshua@reverberate.org> | 2011-02-22 01:54:31 -0800 |
commit | fd184f0df2e5e428873eadfaf1ae829d2e4d8e51 (patch) | |
tree | 19c4a1d9099f04c74de60eb4d8149ea1b5d930a0 /src/upb_msg.c | |
parent | 0c6786c6fad563f181e66c90df2a74597ce6d18b (diff) |
Major work on Lua extension and default values.
Default values are now supported, and the Lua extension
can now create and modify individual protobuf objects.
Diffstat (limited to 'src/upb_msg.c')
-rw-r--r-- | src/upb_msg.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/upb_msg.c b/src/upb_msg.c index 9dfbea4..211004c 100644 --- a/src/upb_msg.c +++ b/src/upb_msg.c @@ -145,6 +145,22 @@ INLINE void upb_msg_sethas(upb_msg *msg, upb_fielddef *f) { msg->data[f->set_bit_offset] |= f->set_bit_mask; } +void upb_msg_set(upb_msg *msg, upb_fielddef *f, upb_value val) { + assert(val.type == upb_field_valuetype(f)); + upb_valueptr ptr = _upb_msg_getptr(msg, f); + if (upb_field_ismm(f)) { + // Unref any previous value we may have had there. + upb_value oldval = upb_value_read(ptr, upb_field_valuetype(f)); + upb_field_unref(oldval, f); + + // Ref the new value. + upb_atomic_refcount_t *refcount = upb_value_getrefcount(val); + if (refcount) upb_atomic_ref(refcount); + } + upb_msg_sethas(msg, f); + return upb_value_write(ptr, val, upb_field_valuetype(f)); +} + static upb_valueptr upb_msg_getappendptr(upb_msg *msg, upb_fielddef *f) { upb_valueptr p = _upb_msg_getptr(msg, f); if (upb_isarray(f)) { |