add const to sproto C api

This commit is contained in:
Cloud Wu
2015-04-08 11:42:06 +08:00
parent 5a1132101b
commit c7ed527911
2 changed files with 14 additions and 14 deletions

View File

@@ -510,7 +510,7 @@ sproto_dump(struct sproto *s) {
// query // query
int int
sproto_prototag(struct sproto *sp, const char * name) { sproto_prototag(const struct sproto *sp, const char * name) {
int i; int i;
for (i=0;i<sp->protocol_n;i++) { for (i=0;i<sp->protocol_n;i++) {
if (strcmp(name, sp->proto[i].name) == 0) { if (strcmp(name, sp->proto[i].name) == 0) {
@@ -521,7 +521,7 @@ sproto_prototag(struct sproto *sp, const char * name) {
} }
static struct protocol * 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; int begin = 0, end = sp->protocol_n;
while(begin<end) { while(begin<end) {
int mid = (begin+end)/2; int mid = (begin+end)/2;
@@ -539,7 +539,7 @@ query_proto(struct sproto *sp, int tag) {
} }
struct sproto_type * struct sproto_type *
sproto_protoquery(struct sproto *sp, int proto, int what) { sproto_protoquery(const struct sproto *sp, int proto, int what) {
struct protocol * p; struct protocol * p;
if (what <0 || what >1) { if (what <0 || what >1) {
return NULL; return NULL;
@@ -552,7 +552,7 @@ sproto_protoquery(struct sproto *sp, int proto, int what) {
} }
const char * const char *
sproto_protoname(struct sproto *sp, int proto) { sproto_protoname(const struct sproto *sp, int proto) {
struct protocol * p = query_proto(sp, proto); struct protocol * p = query_proto(sp, proto);
if (p) { if (p) {
return p->name; return p->name;
@@ -561,7 +561,7 @@ sproto_protoname(struct sproto *sp, int proto) {
} }
struct sproto_type * struct sproto_type *
sproto_type(struct sproto *sp, const char * type_name) { sproto_type(const struct sproto *sp, const char * type_name) {
int i; int i;
for (i=0;i<sp->type_n;i++) { for (i=0;i<sp->type_n;i++) {
if (strcmp(type_name, sp->type[i].name) == 0) { if (strcmp(type_name, sp->type[i].name) == 0) {
@@ -577,7 +577,7 @@ sproto_name(struct sproto_type * st) {
} }
static struct field * static struct field *
findtag(struct sproto_type *st, int tag) { findtag(const struct sproto_type *st, int tag) {
int begin, end; int begin, end;
if (st->base >=0 ) { if (st->base >=0 ) {
tag -= st->base; tag -= st->base;
@@ -839,7 +839,7 @@ encode_array(sproto_callback cb, struct sproto_arg *args, uint8_t *data, int siz
} }
int 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; struct sproto_arg args;
uint8_t * header = buffer; uint8_t * header = buffer;
uint8_t * data; uint8_t * data;
@@ -1035,7 +1035,7 @@ decode_array(sproto_callback cb, struct sproto_arg *args, uint8_t * stream) {
} }
int 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; struct sproto_arg args;
int total = size; int total = size;
uint8_t * stream; uint8_t * stream;

View File

@@ -17,12 +17,12 @@ struct sproto_type;
struct sproto * sproto_create(const void * proto, size_t sz); struct sproto * sproto_create(const void * proto, size_t sz);
void sproto_release(struct sproto *); void sproto_release(struct sproto *);
int sproto_prototag(struct sproto *, const char * name); int sproto_prototag(const struct sproto *, const char * name);
const char * sproto_protoname(struct sproto *, int proto); const char * sproto_protoname(const struct sproto *, int proto);
// SPROTO_REQUEST(0) : request, SPROTO_RESPONSE(1): response // 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_pack(const void * src, int srcsz, void * buffer, int bufsz);
int sproto_unpack(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); 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_decode(const 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_encode(const struct sproto_type *, void * buffer, int size, sproto_callback cb, void *ud);
// for debug use // for debug use
void sproto_dump(struct sproto *); void sproto_dump(struct sproto *);