Skip to content

Commit

Permalink
add const to api
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwu committed Apr 8, 2015
1 parent 4aceeb2 commit f21257f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
16 changes: 8 additions & 8 deletions sproto.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;i<sp->protocol_n;i++) {
if (strcmp(name, sp->proto[i].name) == 0) {
Expand All @@ -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(begin<end) {
int mid = (begin+end)/2;
Expand All @@ -539,7 +539,7 @@ query_proto(struct sproto *sp, int tag) {
}

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;
if (what <0 || what >1) {
return NULL;
Expand All @@ -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;
Expand All @@ -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;i<sp->type_n;i++) {
if (strcmp(type_name, sp->type[i].name) == 0) {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions sproto.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 *);
Expand Down

0 comments on commit f21257f

Please sign in to comment.