diff options
Diffstat (limited to 'src/hub')
-rw-r--r-- | src/hub/src/spreadspace.org/sfive/s5cvt.go | 14 | ||||
-rw-r--r-- | src/hub/src/spreadspace.org/sfive/s5cvt_test.go | 6 |
2 files changed, 12 insertions, 8 deletions
diff --git a/src/hub/src/spreadspace.org/sfive/s5cvt.go b/src/hub/src/spreadspace.org/sfive/s5cvt.go index 5a2ef70..d828af7 100644 --- a/src/hub/src/spreadspace.org/sfive/s5cvt.go +++ b/src/hub/src/spreadspace.org/sfive/s5cvt.go @@ -20,13 +20,14 @@ type PlainDecoder struct{} type PlainEncoder struct{} -func NewStatefulDecoder(jsonString []byte) (decoder StatsDecoder) { +func NewStatefulDecoder(jsonString []byte) (decoder StatsDecoder, err error) { res := new(StatefulDecoder) - err := json.Unmarshal(jsonString, &res.sourceId) + err = json.Unmarshal(jsonString, &res.sourceId) if err != nil { - return nil + return } - return res + decoder = res + return } func NewPlainDecoder() (decoder StatsDecoder) { @@ -35,10 +36,9 @@ func NewPlainDecoder() (decoder StatsDecoder) { func (self *StatefulDecoder) Decode(jsonString []byte) (dat StatisticsData, err error) { err = json.Unmarshal(jsonString, &dat) - if err != nil { - return - } dat.CopyFrom(&self.sourceId) + // like in PlainDecoder, let the client decide how to use partial results + // (Unmarshal returns partial results in case of errors) return } diff --git a/src/hub/src/spreadspace.org/sfive/s5cvt_test.go b/src/hub/src/spreadspace.org/sfive/s5cvt_test.go index 5b53160..418d154 100644 --- a/src/hub/src/spreadspace.org/sfive/s5cvt_test.go +++ b/src/hub/src/spreadspace.org/sfive/s5cvt_test.go @@ -24,7 +24,11 @@ func GetExpected() *StatisticsData { } func TestDecodeStateful(t *testing.T) { - dc := NewStatefulDecoder([]byte(sourceIdData)) + dc, err := NewStatefulDecoder([]byte(sourceIdData)) + if err != nil { + t.Errorf("Creating decoder failed with %v", err) + return + } dat, err := dc.Decode([]byte(testData)) if err != nil { t.Errorf("Decode failed with %v", err) |