watchtower/wtdb: add encode/decode to session info + updates

This commit is contained in:
Conner Fromknecht committed 2019-04-26 17:20:52 -07:00
1 parent dccef4c8bf
commit 7ba197c6a7
2 files changed
+47

No files matched your search

+24
View File
@@ -1,5 +1,7 @@
package wtdb
import "io"
// SessionStateUpdate holds a state update sent by a client along with its
// SessionID.
type SessionStateUpdate struct {
@@ -21,3 +23,25 @@ type SessionStateUpdate struct {
// hint is braodcast.
EncryptedBlob []byte
}
// Encode serializes the state update into the provided io.Writer.
func (u *SessionStateUpdate) Encode(w io.Writer) error {
return WriteElements(w,
u.ID,
u.SeqNum,
u.LastApplied,
u.Hint,
u.EncryptedBlob,
)
}
// Decode deserializes the target state update from the provided io.Reader.
func (u *SessionStateUpdate) Decode(r io.Reader) error {
return ReadElements(r,
&u.ID,
&u.SeqNum,
&u.LastApplied,
&u.Hint,
&u.EncryptedBlob,
)
}