Skip to content

Commit

Permalink
binary Uvarint
Browse files Browse the repository at this point in the history
  • Loading branch information
ailidani committed Apr 21, 2018
1 parent b669ad3 commit c060fcf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ func (d *db) Read(k int) (int, error) {
if len(v) == 0 {
return 0, nil
}
return int(binary.LittleEndian.Uint64(v)), err
x, _ := binary.Uvarint(v)
return int(x), err
}

func (d *db) Write(k, v int) error {
key := paxi.Key(k)
value := make([]byte, 8)
binary.LittleEndian.PutUint64(value, uint64(v))
value := make([]byte, binary.MaxVarintLen64)
binary.PutUvarint(value, uint64(v))
var err error
switch *api {
case "rest":
Expand Down
4 changes: 2 additions & 2 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func run(cmd string, args []string) {
}
k, _ := strconv.Atoi(args[0])
v, _ := client.Get(paxi.Key(k))
fmt.Printf("%x", v)
fmt.Println(string(v))

case "put":
if len(args) < 2 {
Expand All @@ -45,7 +45,7 @@ func run(cmd string, args []string) {
}
k, _ := strconv.Atoi(args[0])
v, _ := client.Put(paxi.Key(k), []byte(args[1]))
fmt.Printf("%x", v)
fmt.Println(string(v))

case "consensus":
if len(args) < 1 {
Expand Down

0 comments on commit c060fcf

Please sign in to comment.