From 8cf2181958367f3154f8b30ad25d18eb7f243481 Mon Sep 17 00:00:00 2001 From: saxon Date: Mon, 7 Jan 2019 13:56:25 +1030 Subject: [PATCH] psi: modified error messages for updateTime and updateLocation to make clearer --- stream/mts/psi/helpers.go | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/stream/mts/psi/helpers.go b/stream/mts/psi/helpers.go index be8a9541..a3275fc3 100644 --- a/stream/mts/psi/helpers.go +++ b/stream/mts/psi/helpers.go @@ -33,12 +33,6 @@ import ( "errors" ) -// error message -var ( - ErrNoLocation = errors.New("psi does not have location descriptor") - ErrNoTime = errors.New("psi does not have time descriptor") -) - // TimeBytes takes a timestamp as an uint64 and converts to an 8 byte slice - // allows for updating of timestamp in pmt time descriptor. func TimeBytes(t uint64) []byte { @@ -70,7 +64,7 @@ func HasLocation(p []byte) bool { // given time if the time descriptor exists, otherwise an error is returned func UpdateTime(dst []byte, t uint64) error { if !HasTime(dst) { - return ErrNoTime + return errors.New("pmt does not have time descriptor, cannot update") } ts := TimeBytes(uint64(t)) for i := range dst[timeDataIndx : timeDataIndx+timeDataSize] { @@ -85,7 +79,7 @@ func UpdateTime(dst []byte, t uint64) error { // if it does not exist func TimeFrom(p []byte) (t uint64, err error) { if !HasTime(p) { - return 0, ErrNoTime + return 0, errors.New("pmt does not have a time descriptor") } t = binary.BigEndian.Uint64(p[timeDataIndx : timeDataIndx+timeDataSize]) return t, nil @@ -96,7 +90,7 @@ func TimeFrom(p []byte) (t uint64, err error) { // if it does not exist func LocationFrom(p []byte) (g string, err error) { if !HasLocation(p) { - return "", ErrNoLocation + return "", errors.New("pmt does not have location descriptor") } gBytes := p[locationDataIndx : locationDataIndx+locationDataSize] gBytes = bytes.Trim(gBytes, "\x00") @@ -117,7 +111,7 @@ func LocationStrBytes(s string) []byte { // If the psi does not contain a location descriptor, and error is returned. func UpdateLocation(d []byte, s string) error { if !HasLocation(d) { - return ErrNoLocation + return errors.New("pmt does not location descriptor, cannot update") } gb := LocationStrBytes(s) for i := range d[locationDataIndx : locationDataIndx+locationDataSize] {