mirror of https://bitbucket.org/ausocean/av.git
psi: modified error messages for updateTime and updateLocation to make clearer
This commit is contained in:
parent
31683b4194
commit
8cf2181958
|
@ -33,12 +33,6 @@ import (
|
||||||
"errors"
|
"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 -
|
// TimeBytes takes a timestamp as an uint64 and converts to an 8 byte slice -
|
||||||
// allows for updating of timestamp in pmt time descriptor.
|
// allows for updating of timestamp in pmt time descriptor.
|
||||||
func TimeBytes(t uint64) []byte {
|
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
|
// given time if the time descriptor exists, otherwise an error is returned
|
||||||
func UpdateTime(dst []byte, t uint64) error {
|
func UpdateTime(dst []byte, t uint64) error {
|
||||||
if !HasTime(dst) {
|
if !HasTime(dst) {
|
||||||
return ErrNoTime
|
return errors.New("pmt does not have time descriptor, cannot update")
|
||||||
}
|
}
|
||||||
ts := TimeBytes(uint64(t))
|
ts := TimeBytes(uint64(t))
|
||||||
for i := range dst[timeDataIndx : timeDataIndx+timeDataSize] {
|
for i := range dst[timeDataIndx : timeDataIndx+timeDataSize] {
|
||||||
|
@ -85,7 +79,7 @@ func UpdateTime(dst []byte, t uint64) error {
|
||||||
// if it does not exist
|
// if it does not exist
|
||||||
func TimeFrom(p []byte) (t uint64, err error) {
|
func TimeFrom(p []byte) (t uint64, err error) {
|
||||||
if !HasTime(p) {
|
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])
|
t = binary.BigEndian.Uint64(p[timeDataIndx : timeDataIndx+timeDataSize])
|
||||||
return t, nil
|
return t, nil
|
||||||
|
@ -96,7 +90,7 @@ func TimeFrom(p []byte) (t uint64, err error) {
|
||||||
// if it does not exist
|
// if it does not exist
|
||||||
func LocationFrom(p []byte) (g string, err error) {
|
func LocationFrom(p []byte) (g string, err error) {
|
||||||
if !HasLocation(p) {
|
if !HasLocation(p) {
|
||||||
return "", ErrNoLocation
|
return "", errors.New("pmt does not have location descriptor")
|
||||||
}
|
}
|
||||||
gBytes := p[locationDataIndx : locationDataIndx+locationDataSize]
|
gBytes := p[locationDataIndx : locationDataIndx+locationDataSize]
|
||||||
gBytes = bytes.Trim(gBytes, "\x00")
|
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.
|
// If the psi does not contain a location descriptor, and error is returned.
|
||||||
func UpdateLocation(d []byte, s string) error {
|
func UpdateLocation(d []byte, s string) error {
|
||||||
if !HasLocation(d) {
|
if !HasLocation(d) {
|
||||||
return ErrNoLocation
|
return errors.New("pmt does not location descriptor, cannot update")
|
||||||
}
|
}
|
||||||
gb := LocationStrBytes(s)
|
gb := LocationStrBytes(s)
|
||||||
for i := range d[locationDataIndx : locationDataIndx+locationDataSize] {
|
for i := range d[locationDataIndx : locationDataIndx+locationDataSize] {
|
||||||
|
|
Loading…
Reference in New Issue