Modify proto

This commit is contained in:
Steve Dee 2014-02-24 10:16:42 -08:00
parent 575f28cef0
commit ef3c34c803
3 changed files with 73 additions and 103 deletions

View File

@ -15,22 +15,19 @@ extern "C" {
struct Raft;
struct Raft_Comd;
struct Raft_Rent;
struct Raft_Apen;
struct Raft_Revo;
struct Raft_Rest;
struct Raft_Rasp;
typedef struct {capn_ptr p;} Raft_ptr;
typedef struct {capn_ptr p;} Raft_Comd_ptr;
typedef struct {capn_ptr p;} Raft_Rent_ptr;
typedef struct {capn_ptr p;} Raft_Apen_ptr;
typedef struct {capn_ptr p;} Raft_Revo_ptr;
typedef struct {capn_ptr p;} Raft_Rest_ptr;
typedef struct {capn_ptr p;} Raft_Rasp_ptr;
typedef struct {capn_ptr p;} Raft_list;
typedef struct {capn_ptr p;} Raft_Comd_list;
typedef struct {capn_ptr p;} Raft_Rent_list;
typedef struct {capn_ptr p;} Raft_Apen_list;
typedef struct {capn_ptr p;} Raft_Revo_list;
typedef struct {capn_ptr p;} Raft_Rest_list;
typedef struct {capn_ptr p;} Raft_Rasp_list;
enum Raft_Comd_Type {
@ -47,24 +44,26 @@ struct Raft_Comd {
};
struct Raft_Rent {
uint64_t tem;
uint32_t tem;
Raft_Comd_ptr cmd;
};
struct Raft_Apen {
uint64_t tem;
capn_text cid;
uint64_t lai;
uint64_t lat;
Raft_Rent_list ent;
uint64_t cit;
enum Raft_Rest_which {
Raft_Rest_revo = 0,
Raft_Rest_apen = 1
};
struct Raft_Revo {
uint64_t tem;
struct Raft_Rest {
uint32_t tem;
capn_text cid;
uint64_t lai;
uint64_t lat;
uint32_t lat;
enum Raft_Rest_which which;
union {
struct {
Raft_Rent_list ent;
uint64_t cit;
} apen;
};
};
struct Raft_Rasp {
@ -75,43 +74,37 @@ struct Raft_Rasp {
Raft_ptr new_Raft(struct capn_segment*);
Raft_Comd_ptr new_Raft_Comd(struct capn_segment*);
Raft_Rent_ptr new_Raft_Rent(struct capn_segment*);
Raft_Apen_ptr new_Raft_Apen(struct capn_segment*);
Raft_Revo_ptr new_Raft_Revo(struct capn_segment*);
Raft_Rest_ptr new_Raft_Rest(struct capn_segment*);
Raft_Rasp_ptr new_Raft_Rasp(struct capn_segment*);
Raft_list new_Raft_list(struct capn_segment*, int len);
Raft_Comd_list new_Raft_Comd_list(struct capn_segment*, int len);
Raft_Rent_list new_Raft_Rent_list(struct capn_segment*, int len);
Raft_Apen_list new_Raft_Apen_list(struct capn_segment*, int len);
Raft_Revo_list new_Raft_Revo_list(struct capn_segment*, int len);
Raft_Rest_list new_Raft_Rest_list(struct capn_segment*, int len);
Raft_Rasp_list new_Raft_Rasp_list(struct capn_segment*, int len);
void read_Raft(struct Raft*, Raft_ptr);
void read_Raft_Comd(struct Raft_Comd*, Raft_Comd_ptr);
void read_Raft_Rent(struct Raft_Rent*, Raft_Rent_ptr);
void read_Raft_Apen(struct Raft_Apen*, Raft_Apen_ptr);
void read_Raft_Revo(struct Raft_Revo*, Raft_Revo_ptr);
void read_Raft_Rest(struct Raft_Rest*, Raft_Rest_ptr);
void read_Raft_Rasp(struct Raft_Rasp*, Raft_Rasp_ptr);
void write_Raft(const struct Raft*, Raft_ptr);
void write_Raft_Comd(const struct Raft_Comd*, Raft_Comd_ptr);
void write_Raft_Rent(const struct Raft_Rent*, Raft_Rent_ptr);
void write_Raft_Apen(const struct Raft_Apen*, Raft_Apen_ptr);
void write_Raft_Revo(const struct Raft_Revo*, Raft_Revo_ptr);
void write_Raft_Rest(const struct Raft_Rest*, Raft_Rest_ptr);
void write_Raft_Rasp(const struct Raft_Rasp*, Raft_Rasp_ptr);
void get_Raft(struct Raft*, Raft_list, int i);
void get_Raft_Comd(struct Raft_Comd*, Raft_Comd_list, int i);
void get_Raft_Rent(struct Raft_Rent*, Raft_Rent_list, int i);
void get_Raft_Apen(struct Raft_Apen*, Raft_Apen_list, int i);
void get_Raft_Revo(struct Raft_Revo*, Raft_Revo_list, int i);
void get_Raft_Rest(struct Raft_Rest*, Raft_Rest_list, int i);
void get_Raft_Rasp(struct Raft_Rasp*, Raft_Rasp_list, int i);
void set_Raft(const struct Raft*, Raft_list, int i);
void set_Raft_Comd(const struct Raft_Comd*, Raft_Comd_list, int i);
void set_Raft_Rent(const struct Raft_Rent*, Raft_Rent_list, int i);
void set_Raft_Apen(const struct Raft_Apen*, Raft_Apen_list, int i);
void set_Raft_Revo(const struct Raft_Revo*, Raft_Revo_list, int i);
void set_Raft_Rest(const struct Raft_Rest*, Raft_Rest_list, int i);
void set_Raft_Rasp(const struct Raft_Rasp*, Raft_Rasp_list, int i);
#ifdef __cplusplus

View File

@ -7,33 +7,31 @@ struct Raft {
enum Type {
nop @0; # no-op
ova @1; # arvo events
ova @1; # arvo event
#xek @2; # checkpoint
}
}
struct Rent { # log entry
tem @0 :UInt64; # term
tem @0 :UInt32; # term
cmd @1 :Comd; # command
}
struct Apen { # AppendEntries
tem @0 :UInt64; # term
cid @1 :Text; # leader ID
lai @2 :UInt64; # previous log index
lat @3 :UInt64; # previous log term
ent @4 :List(Rent); # entries
cit @5 :UInt64; # leader commitIndex
}
struct Revo { # RequestVote
tem @0 :UInt64; # term
cid @1 :Text; # candidate ID
struct Rest { # Raft RPC request
tem @0 :UInt32; # sender term
cid @1 :Text; # sender name
lai @2 :UInt64; # last log index
lat @3 :UInt64; # last log term
lat @3 :UInt32; # last log term
union {
revo @4 :Void; # RequestVote
apen :group { # AppendEntries
ent @5 :List(Rent); # log entries
cit @6 :UInt64; # leader commitIndex
}
}
}
struct Rasp { # Raft response
struct Rasp { # Raft RPC response
tem @0 :UInt64; # leader's term
suc @1 :Bool; # success
}

View File

@ -72,12 +72,12 @@ Raft_Rent_list new_Raft_Rent_list(struct capn_segment *s, int len) {
}
void read_Raft_Rent(struct Raft_Rent *s, Raft_Rent_ptr p) {
capn_resolve(&p.p);
s->tem = capn_read64(p.p, 0);
s->tem = capn_read32(p.p, 0);
s->cmd.p = capn_getp(p.p, 0, 0);
}
void write_Raft_Rent(const struct Raft_Rent *s, Raft_Rent_ptr p) {
capn_resolve(&p.p);
capn_write64(p.p, 0, s->tem);
capn_write32(p.p, 0, s->tem);
capn_setp(p.p, 0, s->cmd.p);
}
void get_Raft_Rent(struct Raft_Rent *s, Raft_Rent_list l, int i) {
@ -91,78 +91,57 @@ void set_Raft_Rent(const struct Raft_Rent *s, Raft_Rent_list l, int i) {
write_Raft_Rent(s, p);
}
Raft_Apen_ptr new_Raft_Apen(struct capn_segment *s) {
Raft_Apen_ptr p;
Raft_Rest_ptr new_Raft_Rest(struct capn_segment *s) {
Raft_Rest_ptr p;
p.p = capn_new_struct(s, 32, 2);
return p;
}
Raft_Apen_list new_Raft_Apen_list(struct capn_segment *s, int len) {
Raft_Apen_list p;
Raft_Rest_list new_Raft_Rest_list(struct capn_segment *s, int len) {
Raft_Rest_list p;
p.p = capn_new_list(s, len, 32, 2);
return p;
}
void read_Raft_Apen(struct Raft_Apen *s, Raft_Apen_ptr p) {
void read_Raft_Rest(struct Raft_Rest *s, Raft_Rest_ptr p) {
capn_resolve(&p.p);
s->tem = capn_read64(p.p, 0);
s->tem = capn_read32(p.p, 0);
s->cid = capn_get_text(p.p, 0, capn_val0);
s->lai = capn_read64(p.p, 8);
s->lat = capn_read64(p.p, 16);
s->ent.p = capn_getp(p.p, 1, 0);
s->cit = capn_read64(p.p, 24);
s->lat = capn_read32(p.p, 4);
s->which = (enum Raft_Rest_which) capn_read16(p.p, 16);
switch (s->which) {
case Raft_Rest_apen:
s->apen.ent.p = capn_getp(p.p, 1, 0);
s->apen.cit = capn_read64(p.p, 24);
break;
default:
break;
}
}
void write_Raft_Apen(const struct Raft_Apen *s, Raft_Apen_ptr p) {
void write_Raft_Rest(const struct Raft_Rest *s, Raft_Rest_ptr p) {
capn_resolve(&p.p);
capn_write64(p.p, 0, s->tem);
capn_write32(p.p, 0, s->tem);
capn_set_text(p.p, 0, s->cid);
capn_write64(p.p, 8, s->lai);
capn_write64(p.p, 16, s->lat);
capn_setp(p.p, 1, s->ent.p);
capn_write64(p.p, 24, s->cit);
capn_write32(p.p, 4, s->lat);
capn_write16(p.p, 16, s->which);
switch (s->which) {
case Raft_Rest_apen:
capn_setp(p.p, 1, s->apen.ent.p);
capn_write64(p.p, 24, s->apen.cit);
break;
default:
break;
}
}
void get_Raft_Apen(struct Raft_Apen *s, Raft_Apen_list l, int i) {
Raft_Apen_ptr p;
void get_Raft_Rest(struct Raft_Rest *s, Raft_Rest_list l, int i) {
Raft_Rest_ptr p;
p.p = capn_getp(l.p, i, 0);
read_Raft_Apen(s, p);
read_Raft_Rest(s, p);
}
void set_Raft_Apen(const struct Raft_Apen *s, Raft_Apen_list l, int i) {
Raft_Apen_ptr p;
void set_Raft_Rest(const struct Raft_Rest *s, Raft_Rest_list l, int i) {
Raft_Rest_ptr p;
p.p = capn_getp(l.p, i, 0);
write_Raft_Apen(s, p);
}
Raft_Revo_ptr new_Raft_Revo(struct capn_segment *s) {
Raft_Revo_ptr p;
p.p = capn_new_struct(s, 24, 1);
return p;
}
Raft_Revo_list new_Raft_Revo_list(struct capn_segment *s, int len) {
Raft_Revo_list p;
p.p = capn_new_list(s, len, 24, 1);
return p;
}
void read_Raft_Revo(struct Raft_Revo *s, Raft_Revo_ptr p) {
capn_resolve(&p.p);
s->tem = capn_read64(p.p, 0);
s->cid = capn_get_text(p.p, 0, capn_val0);
s->lai = capn_read64(p.p, 8);
s->lat = capn_read64(p.p, 16);
}
void write_Raft_Revo(const struct Raft_Revo *s, Raft_Revo_ptr p) {
capn_resolve(&p.p);
capn_write64(p.p, 0, s->tem);
capn_set_text(p.p, 0, s->cid);
capn_write64(p.p, 8, s->lai);
capn_write64(p.p, 16, s->lat);
}
void get_Raft_Revo(struct Raft_Revo *s, Raft_Revo_list l, int i) {
Raft_Revo_ptr p;
p.p = capn_getp(l.p, i, 0);
read_Raft_Revo(s, p);
}
void set_Raft_Revo(const struct Raft_Revo *s, Raft_Revo_list l, int i) {
Raft_Revo_ptr p;
p.p = capn_getp(l.p, i, 0);
write_Raft_Revo(s, p);
write_Raft_Rest(s, p);
}
Raft_Rasp_ptr new_Raft_Rasp(struct capn_segment *s) {