summaryrefslogtreecommitdiff
path: root/src/hub
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2017-05-10 21:59:18 +0200
committerChristian Pointner <equinox@spreadspace.org>2017-05-10 21:59:18 +0200
commit7dcd996b38aa1c4fe247315d72add074c0fdf2f3 (patch)
treea2289caa3a840e22fb93dabcf2110c271ce9354d /src/hub
parentmajor variable name refactoring (diff)
some more variable renaming
Diffstat (limited to 'src/hub')
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5cvt.go58
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5cvt_test.go54
2 files changed, 56 insertions, 56 deletions
diff --git a/src/hub/src/spreadspace.org/sfive/s5cvt.go b/src/hub/src/spreadspace.org/sfive/s5cvt.go
index 8d84fbc..2741a5a 100644
--- a/src/hub/src/spreadspace.org/sfive/s5cvt.go
+++ b/src/hub/src/spreadspace.org/sfive/s5cvt.go
@@ -64,12 +64,12 @@ func (sd *StatelessDecoder) Slug() string {
return ""
}
-func (sd *StatelessDecoder) Decode() (res UpdateFull, err error) {
- if err = sd.dec.Decode(&res); err != nil {
+func (sd *StatelessDecoder) Decode() (uf UpdateFull, err error) {
+ if err = sd.dec.Decode(&uf); err != nil {
return
}
- if res.Version != ProtocolVersion {
- err = fmt.Errorf("unsupported version: %d, expected: %d", res.Version, ProtocolVersion)
+ if uf.Version != ProtocolVersion {
+ err = fmt.Errorf("unsupported version: %d, expected: %d", uf.Version, ProtocolVersion)
}
return
}
@@ -82,15 +82,15 @@ type StatefulDecoder struct {
}
func NewStatefulDecoder(r io.Reader) (Decoder, error) {
- res := &StatefulDecoder{}
- res.dec = json.NewDecoder(r)
- if err := res.dec.Decode(&res); err != nil {
+ dec := &StatefulDecoder{}
+ dec.dec = json.NewDecoder(r)
+ if err := dec.dec.Decode(&dec); err != nil {
return nil, err
}
- if res.Version != ProtocolVersion {
- return nil, fmt.Errorf("unsupported version: %d, expected: %d", res.Version, ProtocolVersion)
+ if dec.Version != ProtocolVersion {
+ return nil, fmt.Errorf("unsupported version: %d, expected: %d", dec.Version, ProtocolVersion)
}
- return res, nil
+ return dec, nil
}
func (sd *StatefulDecoder) Slug() string {
@@ -98,14 +98,14 @@ func (sd *StatefulDecoder) Slug() string {
return fmt.Sprintf("%s/%s/%s/%s", s.Hostname, s.Stream.ContentId, s.Stream.Format, s.Stream.Quality)
}
-func (sd *StatefulDecoder) Decode() (res UpdateFull, err error) {
- res.Version = sd.Version
- res.CopyFromSource(&sd.Source)
- if err = sd.dec.Decode(&res); err != nil {
+func (sd *StatefulDecoder) Decode() (uf UpdateFull, err error) {
+ uf.Version = sd.Version
+ uf.CopyFromSource(&sd.Source)
+ if err = sd.dec.Decode(&uf); err != nil {
return
}
- if res.Version != sd.Version {
- err = fmt.Errorf("unsupported version: %d, expected: %d", res.Version, sd.Version)
+ if uf.Version != sd.Version {
+ err = fmt.Errorf("unsupported version: %d, expected: %d", uf.Version, sd.Version)
}
return
}
@@ -115,7 +115,7 @@ func (sd *StatefulDecoder) Decode() (res UpdateFull, err error) {
//
type Encoder interface {
- Encode(data UpdateFull) error
+ Encode(UpdateFull) error
Slug() string
}
@@ -132,10 +132,10 @@ func (se *StatelessEncoder) Slug() string {
return ""
}
-func (se *StatelessEncoder) Encode(data UpdateFull) error {
- data.Version = ProtocolVersion
- data.StartTime = data.StartTime.UTC()
- return se.enc.Encode(data)
+func (se *StatelessEncoder) Encode(uf UpdateFull) error {
+ uf.Version = ProtocolVersion
+ uf.StartTime = uf.StartTime.UTC()
+ return se.enc.Encode(uf)
}
// stateful protocol interfaces
@@ -145,18 +145,18 @@ type StatefulEncoder struct {
}
func NewStatefulEncoder(w io.Writer) (Encoder, error) {
- res := &StatefulEncoder{}
- res.Version = ProtocolVersion
- res.enc = json.NewEncoder(w)
- return res, res.enc.Encode(&res)
+ enc := &StatefulEncoder{}
+ enc.Version = ProtocolVersion
+ enc.enc = json.NewEncoder(w)
+ return enc, enc.enc.Encode(&enc)
}
func (se *StatefulEncoder) Slug() string {
return ""
}
-func (se *StatefulEncoder) Encode(data UpdateFull) error {
- data.Version = 0 // the init message took care of that
- data.StartTime = data.StartTime.UTC()
- return se.enc.Encode(data)
+func (se *StatefulEncoder) Encode(uf UpdateFull) error {
+ uf.Version = 0 // the init message took care of that
+ uf.StartTime = uf.StartTime.UTC()
+ return se.enc.Encode(uf)
}
diff --git a/src/hub/src/spreadspace.org/sfive/s5cvt_test.go b/src/hub/src/spreadspace.org/sfive/s5cvt_test.go
index 722d675..46b5705 100644
--- a/src/hub/src/spreadspace.org/sfive/s5cvt_test.go
+++ b/src/hub/src/spreadspace.org/sfive/s5cvt_test.go
@@ -42,16 +42,16 @@ import (
)
var (
- initDataEncoded = `"hostname": "localhost", "streamer-id": {"quality": "low", "content-id": "av", "format": "webm"}, "tags": ["elevate", "2014"]`
- initDataStruct = Source{Hostname: "localhost", Stream: Stream{Quality: "low", ContentId: "av", Format: "webm"}, Tags: []string{"elevate", "2014"}}
- updateDataEncoded = `"data": {"bytes-sent": 1, "client-count": 3, "bytes-received": 1}, "start-time": "2014-08-24T14:35:33.847282Z", "duration-ms": 5000`
- updateDataStruct = Update{Data: UpdateData{BytesSent: 1, ClientCount: 3, BytesReceived: 1}, StartTime: time.Date(2014, time.August, 24, 14, 35, 33, 847282000, time.UTC), Duration: 5000}
+ initEncoded = `"hostname": "localhost", "streamer-id": {"quality": "low", "content-id": "av", "format": "webm"}, "tags": ["elevate", "2014"]`
+ initStruct = Source{Hostname: "localhost", Stream: Stream{Quality: "low", ContentId: "av", Format: "webm"}, Tags: []string{"elevate", "2014"}}
+ updateEncoded = `"data": {"bytes-sent": 1, "client-count": 3, "bytes-received": 1}, "start-time": "2014-08-24T14:35:33.847282Z", "duration-ms": 5000`
+ updateStruct = Update{Data: UpdateData{BytesSent: 1, ClientCount: 3, BytesReceived: 1}, StartTime: time.Date(2014, time.August, 24, 14, 35, 33, 847282000, time.UTC), Duration: 5000}
)
func GetExpected() (expected UpdateFull) {
expected.Version = ProtocolVersion
- expected.CopyFromSource(&initDataStruct)
- expected.CopyFromUpdate(&updateDataStruct)
+ expected.CopyFromSource(&initStruct)
+ expected.CopyFromUpdate(&updateStruct)
return
}
@@ -68,13 +68,13 @@ func TestDecodeStateless(t *testing.T) {
}
// wrong protocol version
- dec = NewStatelessDecoder(strings.NewReader(fmt.Sprintf(`{ "version": %d, %s, %s }`, ProtocolVersion+1, initDataEncoded, updateDataEncoded)))
+ dec = NewStatelessDecoder(strings.NewReader(fmt.Sprintf(`{ "version": %d, %s, %s }`, ProtocolVersion+1, initEncoded, updateEncoded)))
if _, err := dec.Decode(); err == nil {
t.Fatalf("decoding message with wrong protocol version should throw an error")
}
// valid message
- dec = NewStatelessDecoder(strings.NewReader(fmt.Sprintf(`{ "version": %d, %s, %s }`, ProtocolVersion, initDataEncoded, updateDataEncoded)))
+ dec = NewStatelessDecoder(strings.NewReader(fmt.Sprintf(`{ "version": %d, %s, %s }`, ProtocolVersion, initEncoded, updateEncoded)))
decoded, err := dec.Decode()
if err != nil {
t.Fatalf("decoding message failed: %v", err)
@@ -94,19 +94,19 @@ func TestDecodeStateful(t *testing.T) {
}
// wrong protocol version
- wrongProtoVerMsg := fmt.Sprintf(`{ "version": %d, %s }`, ProtocolVersion+1, initDataEncoded)
+ wrongProtoVerMsg := fmt.Sprintf(`{ "version": %d, %s }`, ProtocolVersion+1, initEncoded)
if _, err := NewStatefulDecoder(strings.NewReader(wrongProtoVerMsg)); err == nil {
t.Fatalf("creating decoder with wrong protocol version should throw an error")
}
// valid init message
- statefulInitMsg := fmt.Sprintf(`{ "version": %d, %s }`, ProtocolVersion, initDataEncoded)
+ statefulInitMsg := fmt.Sprintf(`{ "version": %d, %s }`, ProtocolVersion, initEncoded)
if _, err := NewStatefulDecoder(strings.NewReader(statefulInitMsg)); err != nil {
t.Fatalf("creating decoder failed: %v", err)
}
// invalid data-update message
- data := fmt.Sprintf(`{ "version": %d, %s }`, ProtocolVersion, initDataEncoded)
+ data := fmt.Sprintf(`{ "version": %d, %s }`, ProtocolVersion, initEncoded)
data = data + "\nthis isn't valid json either"
dec, err := NewStatefulDecoder(strings.NewReader(data))
if err != nil {
@@ -117,8 +117,8 @@ func TestDecodeStateful(t *testing.T) {
}
// wrong protocol version
- data = fmt.Sprintf(`{ "version": %d, %s }`, ProtocolVersion, initDataEncoded)
- data = data + fmt.Sprintf(`{ "version": %d, %s }`, ProtocolVersion+1, updateDataEncoded)
+ data = fmt.Sprintf(`{ "version": %d, %s }`, ProtocolVersion, initEncoded)
+ data = data + fmt.Sprintf(`{ "version": %d, %s }`, ProtocolVersion+1, updateEncoded)
dec, err = NewStatefulDecoder(strings.NewReader(data))
if err != nil {
t.Fatalf("unexpected error: %v", err)
@@ -128,8 +128,8 @@ func TestDecodeStateful(t *testing.T) {
}
// valid data-update message
- data = fmt.Sprintf(`{ "version": %d, %s }`, ProtocolVersion, initDataEncoded)
- data = data + fmt.Sprintf(`{ "version": %d, %s }`, ProtocolVersion, updateDataEncoded)
+ data = fmt.Sprintf(`{ "version": %d, %s }`, ProtocolVersion, initEncoded)
+ data = data + fmt.Sprintf(`{ "version": %d, %s }`, ProtocolVersion, updateEncoded)
dec, err = NewStatefulDecoder(strings.NewReader(data))
if err != nil {
t.Fatalf("unexpected error: %v", err)
@@ -146,8 +146,8 @@ func TestDecodeStateful(t *testing.T) {
}
slug := dec.Slug()
- expectedSlug := strings.Join([]string{initDataStruct.Hostname, initDataStruct.Stream.ContentId,
- initDataStruct.Stream.Format, initDataStruct.Stream.Quality}, "/")
+ expectedSlug := strings.Join([]string{initStruct.Hostname, initStruct.Stream.ContentId,
+ initStruct.Stream.Format, initStruct.Stream.Quality}, "/")
if slug != expectedSlug {
t.Fatalf("slug failed:\n actual: %v\n expected: %v\n", slug, expectedSlug)
}
@@ -155,13 +155,13 @@ func TestDecodeStateful(t *testing.T) {
}
func TestEncodeStateless(t *testing.T) {
- var td UpdateFull
- td.CopyFromSource(&initDataStruct)
- td.CopyFromUpdate(&updateDataStruct)
+ var uf UpdateFull
+ uf.CopyFromSource(&initStruct)
+ uf.CopyFromUpdate(&updateStruct)
encoded := &bytes.Buffer{}
enc := NewStatelessEncoder(encoded)
- if err := enc.Encode(td); err != nil {
+ if err := enc.Encode(uf); err != nil {
t.Fatalf("encoding message failed: %v", err)
}
@@ -176,7 +176,7 @@ func TestEncodeStateless(t *testing.T) {
t.Fatalf("decoding message failed: %v", err)
}
- expected := td
+ expected := uf
expected.Version = ProtocolVersion
if !reflect.DeepEqual(decoded, expected) {
t.Fatalf("encoding failed:\n actual: %v\n expected: %v\n", decoded, expected)
@@ -184,16 +184,16 @@ func TestEncodeStateless(t *testing.T) {
}
func TestEncodeStateful(t *testing.T) {
- var td UpdateFull
- td.CopyFromSource(&initDataStruct)
- td.CopyFromUpdate(&updateDataStruct)
+ var uf UpdateFull
+ uf.CopyFromSource(&initStruct)
+ uf.CopyFromUpdate(&updateStruct)
encoded := &bytes.Buffer{}
enc, err := NewStatefulEncoder(encoded)
if err != nil {
t.Fatalf("encoding init message failed: %v", err)
}
- if err := enc.Encode(td); err != nil {
+ if err := enc.Encode(uf); err != nil {
t.Fatalf("encoding data message failed: %v", err)
}
@@ -212,7 +212,7 @@ func TestEncodeStateful(t *testing.T) {
t.Fatalf("decoding data message failed: %v", err)
}
- expected := td
+ expected := uf
expected.Version = ProtocolVersion
if !reflect.DeepEqual(decoded, expected) {
t.Fatalf("encoding failed:\n actual: %v\n expected: %v\n", decoded, expected)