psi: modified error messages for updateTime and updateLocation to make clearer

This commit is contained in:
saxon 2019-01-07 13:56:25 +10:30
parent 31683b4194
commit 8cf2181958
1 changed files with 4 additions and 10 deletions
stream/mts/psi

View File

@ -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] {