Esempio n. 1
0
File: proto.c Progetto: justnull/pbc
struct pbc_env * 
pbc_new(void) {
	struct pbc_env * p = malloc(sizeof(*p));
	p->files = _pbcM_sp_new();
	p->enums = _pbcM_sp_new();
	p->msgs = _pbcM_sp_new();

	_pbcB_init(p);

	return p;
}
Esempio n. 2
0
struct pbc_env * 
pbc_new(void) {
	struct pbc_env * p = (struct pbc_env *)malloc(sizeof(*p));
	p->files = _pbcM_sp_new(0 , NULL);
	p->enums = _pbcM_sp_new(0 , NULL);
	p->msgs = _pbcM_sp_new(0 , NULL);
	p->lasterror = "";

	_pbcB_init(p);

	return p;
}
Esempio n. 3
0
struct _message * 
_pbcP_init_message(struct pbc_env * p, const char *name) {
	struct _message * m = _pbcM_sp_query(p->msgs, name);
	if (m == NULL) {
		m = malloc(sizeof(*m));
		m->def = NULL;
		m->key = name;
		m->id = NULL;
		m->name = _pbcM_sp_new();
		m->env = p;
		_pbcM_sp_insert(p->msgs, name, m);

		return m;
	}
	if (m->id) {
		// extend message, delete old id map.
		_pbcM_ip_delete(m->id);
	}
	struct _iter iter = { 0, NULL };
	_pbcM_sp_foreach_ud(m->name, _count, &iter);
	iter.table = malloc(iter.count * sizeof(struct map_kv));
	iter.count = 0;
	_pbcM_sp_foreach_ud(m->name, _set_table, &iter);

	m->id = _pbcM_ip_new(iter.table , iter.count);

	free(iter.table);

	return m;
}
Esempio n. 4
0
static void
_pbc_rmessage_new(struct pbc_rmessage * ret , struct _message * type , void *buffer, int size) {
	pbc_ctx _ctx;
	if (_pbcC_open(_ctx,buffer,size) <=0) {
		memset(ret , 0, sizeof(*ret));
		return;
	}
	struct context * ctx = (struct context *)_ctx;

	ret->msg = type;
	ret->index = _pbcM_sp_new();

	int i;

	for (i=0;i<ctx->number;i++) {
		int id = ctx->a[i].id;
		struct _field * f = _pbcM_ip_query(type->id , id);
		if (f) {
			if (f->label == LABEL_REPEATED || f->label == LABEL_PACKED) {
				struct value * v;
				void ** vv = _pbcM_sp_query_insert(ret->index, f->name);
				if (*vv == NULL) {
					v = malloc(SIZE_ARRAY);
					v->type = f;
					_pbcA_open(v->v.array);
					*vv = v;
				} else {
					v= *vv;
				}
				if (f->label == LABEL_PACKED) {
					push_value_packed(v->v.array , f , &(ctx->a[i]), buffer);
				} else {
					push_value_array(v->v.array , f, &(ctx->a[i]), buffer);
				}
			} else {
				struct value * v = read_value(f, &(ctx->a[i]), buffer);
				if (v) {
					_pbcM_sp_insert(ret->index, f->name, v);
				}
			}
		}
	}

	_pbcC_close(_ctx);
}
Esempio n. 5
0
File: proto.c Progetto: justnull/pbc
void 
_pbcP_push_message(struct pbc_env * p, const char *name, struct _field *f , pbc_array queue) {
	struct _message * m = _pbcM_sp_query(p->msgs, name);
	if (m==NULL) {
		m = malloc(sizeof(*m));
		m->def = NULL;
		m->key = name;
		m->id = NULL;
		m->name = _pbcM_sp_new();
		_pbcM_sp_insert(p->msgs, name, m);
	}
	struct _field * field = malloc(sizeof(*field));
	memcpy(field,f,sizeof(*f));
	_pbcM_sp_insert(m->name, field->name, field); 
	pbc_var atom;
	atom->m.buffer = field;
	if (f->type == PTYPE_MESSAGE || f->type == PTYPE_ENUM) {
		_pbcA_push(queue, atom);
	}
}
Esempio n. 6
0
static void
_pbc_rmessage_new(struct pbc_rmessage * ret , struct _message * type , void *buffer, int size , struct heap *h) {
	if (size == 0) {
		ret->msg = type;
		ret->index = _pbcM_sp_new(0 , h);
		ret->heap = h;
		return;
	}
	pbc_ctx _ctx;
	int count = _pbcC_open(_ctx,buffer,size);
	if (count <= 0) {
		type->env->lasterror = "rmessage decode context error";
		memset(ret , 0, sizeof(*ret));
		return;
	}
	struct context * ctx = (struct context *)_ctx;

	ret->msg = type;
	ret->index = _pbcM_sp_new(count, h);
	ret->heap = h;

	int i;

	for (i=0;i<ctx->number;i++) {
		int id = ctx->a[i].wire_id >> 3;
		struct _field * f = _pbcM_ip_query(type->id , id);
		if (f) {
			if (f->label == LABEL_REPEATED || f->label == LABEL_PACKED) {
				struct value * v;
				void ** vv = _pbcM_sp_query_insert(ret->index, f->name);
				if (*vv == NULL) {
					v = _pbcH_alloc(h, SIZE_ARRAY);
					v->type = f;
					_pbcA_open_heap(v->v.array,ret->heap);
					*vv = v;
				} else {
					v= *vv;
				}
				if (f->label == LABEL_PACKED) {
					push_value_packed(type, v->v.array , f , &(ctx->a[i]), buffer);
					if (pbc_array_size(v->v.array) == 0) {
						type->env->lasterror = "rmessage decode packed data error";
						*vv = NULL;
					}
				} else {
					push_value_array(h,v->v.array , f, &(ctx->a[i]), buffer);
					if (pbc_array_size(v->v.array) == 0) {
						type->env->lasterror = "rmessage decode repeated data error";
						*vv = NULL;
					}
				}
			} else {
				struct value * v = read_value(h, f, &(ctx->a[i]), buffer);
				if (v) {
					_pbcM_sp_insert(ret->index, f->name, v);
				} else {
					type->env->lasterror = "rmessage decode data error";
				}
			}
		}
	}

	_pbcC_close(_ctx);
}