From fd184f0df2e5e428873eadfaf1ae829d2e4d8e51 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 22 Feb 2011 01:54:31 -0800 Subject: 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. --- src/upb_def.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/upb_def.h') diff --git a/src/upb_def.h b/src/upb_def.h index 121d5bc..3f79895 100644 --- a/src/upb_def.h +++ b/src/upb_def.h @@ -81,6 +81,9 @@ INLINE void upb_def_unref(upb_def *def) { if(def && upb_atomic_unref(&def->refcount)) _upb_def_reftozero(def); } +#define UPB_UPCAST(ptr) (&(ptr)->base) + + /* upb_fielddef ***************************************************************/ // A upb_fielddef describes a single field in a message. It isn't a full def @@ -158,6 +161,10 @@ typedef struct _upb_msgdef { // Tables for looking up fields by number and name. upb_inttable itof; // int to field upb_strtable ntof; // name to field + + // Immutable msg instance that has all default values set. + // TODO: need a way of making this immutable! + struct _upb_msg *default_message; } upb_msgdef; // Hash table entries for looking up fields by name or number. @@ -172,6 +179,13 @@ typedef struct { upb_fielddef *f; } upb_ntof_ent; +INLINE void upb_msgdef_unref(upb_msgdef *md) { + upb_def_unref(UPB_UPCAST(md)); +} +INLINE void upb_msgdef_ref(upb_msgdef *md) { + upb_def_ref(UPB_UPCAST(md)); +} + // Looks up a field by name or number. While these are written to be as fast // as possible, it will still be faster to cache the results of this lookup if // possible. These return NULL if no such field is found. @@ -361,8 +375,6 @@ UPB_DOWNCAST_DEF(extdef, EXT); UPB_DOWNCAST_DEF(unresolveddef, UNRESOLVED); #undef UPB_DOWNCAST_DEF -#define UPB_UPCAST(ptr) (&(ptr)->base) - #ifdef __cplusplus } /* extern "C" */ #endif -- cgit v1.2.3