diff --git a/binding/lua53/protobuf.lua b/binding/lua53/protobuf.lua index 40ca42b..293df3e 100644 --- a/binding/lua53/protobuf.lua +++ b/binding/lua53/protobuf.lua @@ -215,7 +215,9 @@ local function encode_message(CObj, message_type, t) local type = encode_type_cache[message_type] for k,v in pairs(t) do local func = type[k] - func(CObj, k , v) + if func then + func(CObj, k , v) + end end end @@ -305,8 +307,11 @@ local _encode_type_meta = {} function _encode_type_meta:__index(key) local t, msg = c._env_type(P, self._CType, key) - local func = assert(_writer[t],key)(msg) - self[key] = func + local func = _writer[t] + if func then + func = func(msg) + self[key] = func + end return func end diff --git a/pbc.h b/pbc.h index 26312af..2f36c35 100644 --- a/pbc.h +++ b/pbc.h @@ -71,7 +71,7 @@ const char * pbc_rmessage_string(struct pbc_rmessage * , const char *key , int i struct pbc_rmessage * pbc_rmessage_message(struct pbc_rmessage *, const char *key, int index); int pbc_rmessage_size(struct pbc_rmessage *, const char *key); int pbc_rmessage_next(struct pbc_rmessage *, const char **key); - +// 新建pbc_wmessage struct pbc_wmessage * pbc_wmessage_new(struct pbc_env * env, const char *type_name); void pbc_wmessage_delete(struct pbc_wmessage *); diff --git a/src/alloc.c b/src/alloc.c index 96590ed..8b5448d 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -2,7 +2,7 @@ #include static int _g = 0; - +// 分配内存,并记录到_g void * _pbcM_malloc(size_t sz) { ++ _g; return malloc(sz); @@ -60,11 +60,11 @@ _pbcH_delete(struct heap *h) { } _pbcM_free(h); } - +// 创建一个堆;h:全局堆, size:堆大小 void* _pbcH_alloc(struct heap *h, int size) { size = (size + 3) & ~3; - if (h->size - h->used < size) { + if (h->size - h->used < size) { // 内存不够 struct heap_page * p; if (size < h->size) { p = (struct heap_page *)_pbcM_malloc(sizeof(struct heap_page) + h->size); diff --git a/src/wmessage.c b/src/wmessage.c index 8c10165..ca1d758 100644 --- a/src/wmessage.c +++ b/src/wmessage.c @@ -14,15 +14,15 @@ #endif #define WMESSAGE_SIZE 64 - +// pbc编码结构体 struct pbc_wmessage { - struct _message *type; - uint8_t * buffer; - uint8_t * ptr; - uint8_t * endptr; - pbc_array sub; - struct map_sp *packed; - struct heap * heap; + struct _message *type; // + uint8_t * buffer; // + uint8_t * ptr; // + uint8_t * endptr; // + pbc_array sub; // + struct map_sp *packed; // + struct heap * heap; // }; struct _packed { @@ -30,7 +30,7 @@ struct _packed { int ptype; pbc_array data; }; - +// 新建pbc_wmessage static struct pbc_wmessage * _wmessage_new(struct heap *h, struct _message *msg) { struct pbc_wmessage * m = (struct pbc_wmessage *)_pbcH_alloc(h, sizeof(*m));