From c7ed5279116db060f7c466604f98e700dba21c0a Mon Sep 17 00:00:00 2001 From: Cloud Wu Date: Wed, 8 Apr 2015 11:42:06 +0800 Subject: [PATCH] add const to sproto C api --- lualib-src/sproto/sproto.c | 16 ++++++++-------- lualib-src/sproto/sproto.h | 12 ++++++------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lualib-src/sproto/sproto.c b/lualib-src/sproto/sproto.c index ac64bcff..c37fdc1b 100644 --- a/lualib-src/sproto/sproto.c +++ b/lualib-src/sproto/sproto.c @@ -510,7 +510,7 @@ sproto_dump(struct sproto *s) { // query int -sproto_prototag(struct sproto *sp, const char * name) { +sproto_prototag(const struct sproto *sp, const char * name) { int i; for (i=0;iprotocol_n;i++) { if (strcmp(name, sp->proto[i].name) == 0) { @@ -521,7 +521,7 @@ sproto_prototag(struct sproto *sp, const char * name) { } static struct protocol * -query_proto(struct sproto *sp, int tag) { +query_proto(const struct sproto *sp, int tag) { int begin = 0, end = sp->protocol_n; while(begin1) { return NULL; @@ -552,7 +552,7 @@ sproto_protoquery(struct sproto *sp, int proto, int what) { } const char * -sproto_protoname(struct sproto *sp, int proto) { +sproto_protoname(const struct sproto *sp, int proto) { struct protocol * p = query_proto(sp, proto); if (p) { return p->name; @@ -561,7 +561,7 @@ sproto_protoname(struct sproto *sp, int proto) { } struct sproto_type * -sproto_type(struct sproto *sp, const char * type_name) { +sproto_type(const struct sproto *sp, const char * type_name) { int i; for (i=0;itype_n;i++) { if (strcmp(type_name, sp->type[i].name) == 0) { @@ -577,7 +577,7 @@ sproto_name(struct sproto_type * st) { } static struct field * -findtag(struct sproto_type *st, int tag) { +findtag(const struct sproto_type *st, int tag) { int begin, end; if (st->base >=0 ) { tag -= st->base; @@ -839,7 +839,7 @@ encode_array(sproto_callback cb, struct sproto_arg *args, uint8_t *data, int siz } int -sproto_encode(struct sproto_type *st, void * buffer, int size, sproto_callback cb, void *ud) { +sproto_encode(const struct sproto_type *st, void * buffer, int size, sproto_callback cb, void *ud) { struct sproto_arg args; uint8_t * header = buffer; uint8_t * data; @@ -1035,7 +1035,7 @@ decode_array(sproto_callback cb, struct sproto_arg *args, uint8_t * stream) { } int -sproto_decode(struct sproto_type *st, const void * data, int size, sproto_callback cb, void *ud) { +sproto_decode(const struct sproto_type *st, const void * data, int size, sproto_callback cb, void *ud) { struct sproto_arg args; int total = size; uint8_t * stream; diff --git a/lualib-src/sproto/sproto.h b/lualib-src/sproto/sproto.h index 934e18f8..0a419c86 100644 --- a/lualib-src/sproto/sproto.h +++ b/lualib-src/sproto/sproto.h @@ -17,12 +17,12 @@ struct sproto_type; struct sproto * sproto_create(const void * proto, size_t sz); void sproto_release(struct sproto *); -int sproto_prototag(struct sproto *, const char * name); -const char * sproto_protoname(struct sproto *, int proto); +int sproto_prototag(const struct sproto *, const char * name); +const char * sproto_protoname(const struct sproto *, int proto); // SPROTO_REQUEST(0) : request, SPROTO_RESPONSE(1): response -struct sproto_type * sproto_protoquery(struct sproto *, int proto, int what); +struct sproto_type * sproto_protoquery(const struct sproto *, int proto, int what); -struct sproto_type * sproto_type(struct sproto *, const char * type_name); +struct sproto_type * sproto_type(const struct sproto *, const char * type_name); int sproto_pack(const void * src, int srcsz, void * buffer, int bufsz); int sproto_unpack(const void * src, int srcsz, void * buffer, int bufsz); @@ -41,8 +41,8 @@ struct sproto_arg { typedef int (*sproto_callback)(const struct sproto_arg *args); -int sproto_decode(struct sproto_type *, const void * data, int size, sproto_callback cb, void *ud); -int sproto_encode(struct sproto_type *, void * buffer, int size, sproto_callback cb, void *ud); +int sproto_decode(const struct sproto_type *, const void * data, int size, sproto_callback cb, void *ud); +int sproto_encode(const struct sproto_type *, void * buffer, int size, sproto_callback cb, void *ud); // for debug use void sproto_dump(struct sproto *);