summaryrefslogtreecommitdiff
path: root/src/hub/src/spreadspace.org/sfive/s5cvt.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/hub/src/spreadspace.org/sfive/s5cvt.go')
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5cvt.go15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/hub/src/spreadspace.org/sfive/s5cvt.go b/src/hub/src/spreadspace.org/sfive/s5cvt.go
index 28162ba..48eac4b 100644
--- a/src/hub/src/spreadspace.org/sfive/s5cvt.go
+++ b/src/hub/src/spreadspace.org/sfive/s5cvt.go
@@ -37,6 +37,10 @@ import (
"fmt"
)
+const (
+ ProtocolVersion = 1
+)
+
type FullDecoder interface {
Decode(jsonString []byte) (DataUpdateFull, error)
}
@@ -46,7 +50,8 @@ type FullEncoder interface {
}
type StatefulDecoder struct {
- sourceId SourceId
+ Version uint
+ SourceId
}
type PlainDecoder struct{}
@@ -55,12 +60,12 @@ type PlainEncoder struct{}
func NewStatefulDecoder(jsonString []byte) (decoder FullDecoder, err error) {
res := new(StatefulDecoder)
- err = json.Unmarshal(jsonString, &res.sourceId)
+ err = json.Unmarshal(jsonString, &res)
if err != nil {
return
}
- if res.sourceId.Version != 1 {
- err = fmt.Errorf("unsupported version, expected 1, actual %v", res.sourceId.Version)
+ if res.Version != ProtocolVersion {
+ err = fmt.Errorf("unsupported version, expected %d, actual %v", ProtocolVersion, res.Version)
}
decoder = res
return
@@ -71,7 +76,7 @@ func NewPlainDecoder() FullDecoder {
}
func (sd *StatefulDecoder) Decode(jsonString []byte) (dat DataUpdateFull, err error) {
- dat.CopyFromSourceId(&sd.sourceId)
+ dat.CopyFromSourceId(&sd.SourceId)
err = json.Unmarshal(jsonString, &dat)
// like in PlainDecoder, let the client decide how to use partial results
// (Unmarshal returns partial results in case of errors)