Skip to content
This repository was archived by the owner on Nov 28, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions binding/lua53/protobuf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion pbc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);

Expand Down
6 changes: 3 additions & 3 deletions src/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <stdio.h>

static int _g = 0;

// 分配内存,并记录到_g
void * _pbcM_malloc(size_t sz) {
++ _g;
return malloc(sz);
Expand Down Expand Up @@ -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);
Expand Down
18 changes: 9 additions & 9 deletions src/wmessage.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@
#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 {
int id;
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));
Expand Down