Skip to content

Commit

Permalink
Add encode and decode to BatchSnapshot type
Browse files Browse the repository at this point in the history
  • Loading branch information
gdiazlo committed Nov 20, 2018
1 parent fd96b9e commit a25e7c6
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions protocol/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@
package protocol

import (
"bytes"

"github.com/bbva/qed/balloon"
"github.com/bbva/qed/balloon/history"
"github.com/bbva/qed/balloon/hyper"
"github.com/bbva/qed/balloon/visitor"
"github.com/bbva/qed/hashing"
"github.com/bbva/qed/log"
"github.com/bbva/qed/util"
"github.com/hashicorp/go-msgpack/codec"
)

// Event is the public struct that Add handler function uses to
Expand Down Expand Up @@ -56,6 +60,26 @@ type BatchSnapshots struct {
TTL int
}

func (b *BatchSnapshots) Encode() ([]byte, error) {
var buf bytes.Buffer
encoder := codec.NewEncoder(&buf, &codec.MsgpackHandle{})
if err := encoder.Encode(b); err != nil {
log.Errorf("Failed to encode message: %v", err)
return nil, err
}
return buf.Bytes(), nil
}

func (b *BatchSnapshots) Decode(msg []byte) error {
reader := bytes.NewReader(msg)
decoder := codec.NewDecoder(reader, &codec.MsgpackHandle{})
if err := decoder.Decode(b); err != nil {
log.Errorf("Failed to decode snapshots batch: %v", err)
return err
}
return nil
}

type MembershipResult struct {
Exists bool
Hyper visitor.AuditPath
Expand Down

0 comments on commit a25e7c6

Please sign in to comment.