summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarkus Grüneis <gimpf@gimpf.org>2014-10-16 20:14:06 +0200
committerMarkus Grüneis <gimpf@gimpf.org>2014-10-16 20:14:06 +0200
commit4a7c1eb8d700fec117b016d49ceffd76a48bdebf (patch)
tree746cbd2cc3b667b7bd2875a9fcf0ee3ae7ea90d2 /src
parentfix, refactor s5store (diff)
fix json conversion interface
- return partial data on conversion error in StatefulDecoder, to be in line with PlainDecoder and golang convention - add err as return value for NewStatefulDecoder
Diffstat (limited to 'src')
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5cvt.go14
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5cvt_test.go6
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)