From 98d89a4e4e8eb316edbb694bfa699763562562fd Mon Sep 17 00:00:00 2001 From: saxon Date: Fri, 18 Jan 2019 13:21:35 +1030 Subject: [PATCH 01/10] mts: got rid of LocationStrBytes func --- stream/mts/psi/helpers.go | 19 +++++++++---------- stream/mts/psi/psi_test.go | 35 +++++++++++++++++++++++------------ 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/stream/mts/psi/helpers.go b/stream/mts/psi/helpers.go index 1ad8364a..86e6cc72 100644 --- a/stream/mts/psi/helpers.go +++ b/stream/mts/psi/helpers.go @@ -99,14 +99,6 @@ func LocationFrom(p []byte) (g string, err error) { return g, nil } -// LocationStrBytes take a string of location data and converts to a 32 byte slice - -// easy update of slice representation of a pmt with location descriptor -func LocationStrBytes(s string) []byte { - var b [LocationDataSize]byte - copy(b[:], s) - return b[:] -} - // UpdateLocation takes a byte slice representation of a psi-pmt containing a location // descriptor and attempts to update the location data value with the passed string. // If the psi does not contain a location descriptor, and error is returned. @@ -114,8 +106,15 @@ func UpdateLocation(d []byte, s string) error { if !HasLocation(d) { return errors.New("pmt does not location descriptor, cannot update") } - gb := LocationStrBytes(s) - copy(d[LocationDataIndx:LocationDataIndx+LocationDataSize], gb) + sb := []byte(s) + locBytes := d[LocationDataIndx : LocationDataIndx+LocationDataSize] + for i, _ := range locBytes { + if i < len(sb) { + locBytes[i] = sb[i] + } else { + locBytes[i] = 0x00 + } + } updateCrc(d) return nil } diff --git a/stream/mts/psi/psi_test.go b/stream/mts/psi/psi_test.go index 4999ee2e..98f759f3 100644 --- a/stream/mts/psi/psi_test.go +++ b/stream/mts/psi/psi_test.go @@ -123,9 +123,20 @@ const ( // GPS string for testing // TODO: make these realistic -const ( - locationTstStr1 = "$GPGGA,123519,4807.038,N,01131.0" - locationTstStr2 = "$GPGGA,183710,4902.048,N,02171.0" +var ( + locationTstStr1 = [LocationDataSize]byte{ + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + } + + locationTstStr2 = [LocationDataSize]byte{ + 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, + 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, + 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, + 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, + } ) // err message @@ -175,10 +186,10 @@ var ( } // Bytes representing pmt with time1 and location1 - pmtTimeLocationBytes1 = buildPmtTimeLocationBytes(locationTstStr1) + pmtTimeLocationBytes1 = buildPmtTimeLocationBytes(locationTstStr1[:]) // bytes representing pmt with with time1 and location 2 - pmtTimeLocationBytes2 = buildPmtTimeLocationBytes(locationTstStr2) + pmtTimeLocationBytes2 = buildPmtTimeLocationBytes(locationTstStr2[:]) ) // bytesTests contains data for testing the Bytes() funcs for the PSI data struct @@ -262,7 +273,7 @@ var bytesTests = []struct { { Dt: LocationDescTag, Dl: LocationDataSize, - Dd: LocationStrBytes(locationTstStr1), + Dd: locationTstStr1[:], }, }, Essd: &ESSD{ @@ -273,7 +284,7 @@ var bytesTests = []struct { }, }, }, - want: buildPmtTimeLocationBytes(locationTstStr1), + want: buildPmtTimeLocationBytes(locationTstStr1[:]), }, } @@ -326,7 +337,7 @@ func TestTimeGet(t *testing.T) { // TestLocationGet checks that we can correctly get location data from a pmt table func TestLocationGet(t *testing.T) { pb := standardPmtTimeLocation.Bytes() - err := UpdateLocation(pb, locationTstStr1) + err := UpdateLocation(pb, string(locationTstStr1[:])) if err != nil { t.Errorf("Error for TestLocationGet UpdateLocation(pb, locationTstStr1): %v", err) } @@ -334,7 +345,7 @@ func TestLocationGet(t *testing.T) { if err != nil { t.Errorf("Error for TestLocationGet LocationOf(pb): %v", err) } - if g != locationTstStr1 { + if g != string(locationTstStr1[:]) { t.Errorf(errCmp, "TestLocationGet", locationTstStr1, g) } } @@ -344,7 +355,7 @@ func TestLocationUpdate(t *testing.T) { cpy := make([]byte, len(pmtTimeLocationBytes1)) copy(cpy, pmtTimeLocationBytes1) cpy = addCrc(cpy) - err := UpdateLocation(cpy, locationTstStr2) + err := UpdateLocation(cpy, string(locationTstStr2[:])) cpy = cpy[:len(cpy)-4] if err != nil { t.Errorf("Update time returned err: %v", err) @@ -366,7 +377,7 @@ func TestTrim(t *testing.T) { // buildPmtTimeLocationBytes is a helper function to help construct the byte slices // for pmts with time and location, as the location data field is 32 bytes, i.e. quite large // to type out -func buildPmtTimeLocationBytes(tstStr string) []byte { +func buildPmtTimeLocationBytes(tstStr []byte) []byte { return append(append(append(make([]byte, 0), pmtTimeLocationBytesPart1...), - LocationStrBytes(tstStr)...), pmtTimeLocationBytesPart2...) + tstStr...), pmtTimeLocationBytesPart2...) } From 5c4795786e3a4ff0192d4ddebd2dda6f3c0c74cd Mon Sep 17 00:00:00 2001 From: saxon Date: Sun, 20 Jan 2019 20:14:27 +1030 Subject: [PATCH 02/10] psi/helpers.go: modified UpdateLocation() to make updating of location in pmt cleaner, and also removed redundant conversion of string to byte slice --- stream/mts/psi/helpers.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/stream/mts/psi/helpers.go b/stream/mts/psi/helpers.go index 86e6cc72..82d7ce72 100644 --- a/stream/mts/psi/helpers.go +++ b/stream/mts/psi/helpers.go @@ -106,14 +106,11 @@ func UpdateLocation(d []byte, s string) error { if !HasLocation(d) { return errors.New("pmt does not location descriptor, cannot update") } - sb := []byte(s) - locBytes := d[LocationDataIndx : LocationDataIndx+LocationDataSize] - for i, _ := range locBytes { - if i < len(sb) { - locBytes[i] = sb[i] - } else { - locBytes[i] = 0x00 - } + loc := d[LocationDataIndx : LocationDataIndx+LocationDataSize] + n := copy(loc, s) + loc = loc[n:] + for i := range loc { + loc[i] = 0 } updateCrc(d) return nil From 1a966e8f9b4dafedfe71a86e85dd97dce096bf06 Mon Sep 17 00:00:00 2001 From: saxon Date: Sun, 20 Jan 2019 20:43:00 +1030 Subject: [PATCH 03/10] psi/psi_test.go: improved some naming --- stream/mts/psi/psi_test.go | 47 ++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/stream/mts/psi/psi_test.go b/stream/mts/psi/psi_test.go index 98f759f3..7078e340 100644 --- a/stream/mts/psi/psi_test.go +++ b/stream/mts/psi/psi_test.go @@ -79,7 +79,7 @@ var ( // standardPmtTimeLocation is a standard PMT with time and location // descriptors, but time and location fields zeroed out. - standardPmtTimeLocation = PSI{ + standardPmtWithMeta = PSI{ Pf: 0x00, Tid: 0x02, Ssi: true, @@ -124,14 +124,14 @@ const ( // GPS string for testing // TODO: make these realistic var ( - locationTstStr1 = [LocationDataSize]byte{ + locationBytes1 = [LocationDataSize]byte{ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, } - locationTstStr2 = [LocationDataSize]byte{ + locationBytes2 = [LocationDataSize]byte{ 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, @@ -153,7 +153,7 @@ var ( // Parts to construct bytes of pmt with time and bytes var ( - pmtTimeLocationBytesPart1 = []byte{ + pmtWithMetaHead = []byte{ 0x00, 0x02, 0xb0, 0x12, 0x00, 0x01, 0xc1, 0x00, 0x00, 0xe1, 0x00, 0xf0, 0x0a, TimeDescTag, // Descriptor tag for timestamp TimeDataSize, // Length of bytes to follow @@ -161,7 +161,7 @@ var ( LocationDescTag, // Descriptor tag for location LocationDataSize, // Length of bytes to follow } - pmtTimeLocationBytesPart2 = []byte{ + pmtWithMetaTail = []byte{ 0x1b, 0xe1, 0x00, 0xf0, 0x00, } ) @@ -186,10 +186,10 @@ var ( } // Bytes representing pmt with time1 and location1 - pmtTimeLocationBytes1 = buildPmtTimeLocationBytes(locationTstStr1[:]) + pmtWithMetaTst1 = buildPmtWithMeta(locationBytes1[:]) // bytes representing pmt with with time1 and location 2 - pmtTimeLocationBytes2 = buildPmtTimeLocationBytes(locationTstStr2[:]) + pmtWithMetaTst2 = buildPmtWithMeta(locationBytes2[:]) ) // bytesTests contains data for testing the Bytes() funcs for the PSI data struct @@ -273,7 +273,7 @@ var bytesTests = []struct { { Dt: LocationDescTag, Dl: LocationDataSize, - Dd: locationTstStr1[:], + Dd: locationBytes1[:], }, }, Essd: &ESSD{ @@ -284,7 +284,7 @@ var bytesTests = []struct { }, }, }, - want: buildPmtTimeLocationBytes(locationTstStr1[:]), + want: buildPmtWithMeta(locationBytes1[:]), }, } @@ -336,32 +336,32 @@ func TestTimeGet(t *testing.T) { // TestLocationGet checks that we can correctly get location data from a pmt table func TestLocationGet(t *testing.T) { - pb := standardPmtTimeLocation.Bytes() - err := UpdateLocation(pb, string(locationTstStr1[:])) + pb := standardPmtWithMeta.Bytes() + err := UpdateLocation(pb, string(locationBytes1[:])) if err != nil { - t.Errorf("Error for TestLocationGet UpdateLocation(pb, locationTstStr1): %v", err) + t.Errorf("Error for TestLocationGet UpdateLocation(pb, locationBytes1): %v", err) } g, err := LocationFrom(pb) if err != nil { t.Errorf("Error for TestLocationGet LocationOf(pb): %v", err) } - if g != string(locationTstStr1[:]) { - t.Errorf(errCmp, "TestLocationGet", locationTstStr1, g) + if g != string(locationBytes1[:]) { + t.Errorf(errCmp, "TestLocationGet", locationBytes1, g) } } // TestLocationUpdate checks to see if we can update the location string in a pmt correctly func TestLocationUpdate(t *testing.T) { - cpy := make([]byte, len(pmtTimeLocationBytes1)) - copy(cpy, pmtTimeLocationBytes1) + cpy := make([]byte, len(pmtWithMetaTst1)) + copy(cpy, pmtWithMetaTst1) cpy = addCrc(cpy) - err := UpdateLocation(cpy, string(locationTstStr2[:])) + err := UpdateLocation(cpy, string(locationBytes2[:])) cpy = cpy[:len(cpy)-4] if err != nil { t.Errorf("Update time returned err: %v", err) } - if !bytes.Equal(pmtTimeLocationBytes2, cpy) { - t.Errorf(errCmp, "TestLocationUpdate", pmtTimeLocationBytes2, cpy) + if !bytes.Equal(pmtWithMetaTst2, cpy) { + t.Errorf(errCmp, "TestLocationUpdate", pmtWithMetaTst2, cpy) } } @@ -377,7 +377,10 @@ func TestTrim(t *testing.T) { // buildPmtTimeLocationBytes is a helper function to help construct the byte slices // for pmts with time and location, as the location data field is 32 bytes, i.e. quite large // to type out -func buildPmtTimeLocationBytes(tstStr []byte) []byte { - return append(append(append(make([]byte, 0), pmtTimeLocationBytesPart1...), - tstStr...), pmtTimeLocationBytesPart2...) +func buildPmtWithMeta(tstStr []byte) []byte { + dst := make([]byte, len(pmtWithMetaHead)+32+len(pmtWithMetaTail)) + copy(dst, pmtWithMetaHead) + copy(dst[len(pmtWithMetaHead):], tstStr) + copy(dst[len(pmtWithMetaHead)+32:], pmtWithMetaTail) + return dst } From b69c990b214e92936df1cf229e72b4a59b03435a Mon Sep 17 00:00:00 2001 From: saxon Date: Sun, 20 Jan 2019 21:04:27 +1030 Subject: [PATCH 04/10] psi/psi_test.go: got rid of bytes declaration for location strigns --- stream/mts/psi/psi_test.go | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/stream/mts/psi/psi_test.go b/stream/mts/psi/psi_test.go index 7078e340..d08d9e90 100644 --- a/stream/mts/psi/psi_test.go +++ b/stream/mts/psi/psi_test.go @@ -124,19 +124,8 @@ const ( // GPS string for testing // TODO: make these realistic var ( - locationBytes1 = [LocationDataSize]byte{ - 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, - 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, - 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, - 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, - } - - locationBytes2 = [LocationDataSize]byte{ - 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, - 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, - 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, - 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, - } + locationTstStr1 = []byte("$GPGGA,123519,4807.038,N,01131.0") + locationTstStr2 = []byte("$GPGGA,183710,4902.048,N,02171.0") ) // err message @@ -186,10 +175,10 @@ var ( } // Bytes representing pmt with time1 and location1 - pmtWithMetaTst1 = buildPmtWithMeta(locationBytes1[:]) + pmtWithMetaTst1 = buildPmtWithMeta(locationTstStr1) // bytes representing pmt with with time1 and location 2 - pmtWithMetaTst2 = buildPmtWithMeta(locationBytes2[:]) + pmtWithMetaTst2 = buildPmtWithMeta(locationTstStr2) ) // bytesTests contains data for testing the Bytes() funcs for the PSI data struct @@ -273,7 +262,7 @@ var bytesTests = []struct { { Dt: LocationDescTag, Dl: LocationDataSize, - Dd: locationBytes1[:], + Dd: locationTstStr1, }, }, Essd: &ESSD{ @@ -284,7 +273,7 @@ var bytesTests = []struct { }, }, }, - want: buildPmtWithMeta(locationBytes1[:]), + want: buildPmtWithMeta(locationTstStr1), }, } @@ -337,16 +326,16 @@ func TestTimeGet(t *testing.T) { // TestLocationGet checks that we can correctly get location data from a pmt table func TestLocationGet(t *testing.T) { pb := standardPmtWithMeta.Bytes() - err := UpdateLocation(pb, string(locationBytes1[:])) + err := UpdateLocation(pb, string(locationTstStr1)) if err != nil { - t.Errorf("Error for TestLocationGet UpdateLocation(pb, locationBytes1): %v", err) + t.Errorf("Error for TestLocationGet UpdateLocation(pb, locationTstStr1): %v", err) } g, err := LocationFrom(pb) if err != nil { t.Errorf("Error for TestLocationGet LocationOf(pb): %v", err) } - if g != string(locationBytes1[:]) { - t.Errorf(errCmp, "TestLocationGet", locationBytes1, g) + if g != string(locationTstStr1) { + t.Errorf(errCmp, "TestLocationGet", locationTstStr1, g) } } @@ -355,7 +344,7 @@ func TestLocationUpdate(t *testing.T) { cpy := make([]byte, len(pmtWithMetaTst1)) copy(cpy, pmtWithMetaTst1) cpy = addCrc(cpy) - err := UpdateLocation(cpy, string(locationBytes2[:])) + err := UpdateLocation(cpy, string(locationTstStr2)) cpy = cpy[:len(cpy)-4] if err != nil { t.Errorf("Update time returned err: %v", err) From 3835ff7ce160827b5f98f24c9f84019cc9294b48 Mon Sep 17 00:00:00 2001 From: saxon Date: Sun, 20 Jan 2019 21:11:09 +1030 Subject: [PATCH 05/10] psi/psi_test.go: made location tsts strings again and have buildPmtWithMeta take a string instead of []byte --- stream/mts/psi/psi_test.go | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/stream/mts/psi/psi_test.go b/stream/mts/psi/psi_test.go index d08d9e90..ab173b58 100644 --- a/stream/mts/psi/psi_test.go +++ b/stream/mts/psi/psi_test.go @@ -124,8 +124,8 @@ const ( // GPS string for testing // TODO: make these realistic var ( - locationTstStr1 = []byte("$GPGGA,123519,4807.038,N,01131.0") - locationTstStr2 = []byte("$GPGGA,183710,4902.048,N,02171.0") + locationTstStr1 = "$GPGGA,123519,4807.038,N,01131.0" + locationTstStr2 = "$GPGGA,183710,4902.048,N,02171.0" ) // err message @@ -262,7 +262,7 @@ var bytesTests = []struct { { Dt: LocationDescTag, Dl: LocationDataSize, - Dd: locationTstStr1, + Dd: []byte(locationTstStr1), }, }, Essd: &ESSD{ @@ -326,7 +326,7 @@ func TestTimeGet(t *testing.T) { // TestLocationGet checks that we can correctly get location data from a pmt table func TestLocationGet(t *testing.T) { pb := standardPmtWithMeta.Bytes() - err := UpdateLocation(pb, string(locationTstStr1)) + err := UpdateLocation(pb, locationTstStr1) if err != nil { t.Errorf("Error for TestLocationGet UpdateLocation(pb, locationTstStr1): %v", err) } @@ -334,7 +334,7 @@ func TestLocationGet(t *testing.T) { if err != nil { t.Errorf("Error for TestLocationGet LocationOf(pb): %v", err) } - if g != string(locationTstStr1) { + if g != locationTstStr1 { t.Errorf(errCmp, "TestLocationGet", locationTstStr1, g) } } @@ -344,7 +344,7 @@ func TestLocationUpdate(t *testing.T) { cpy := make([]byte, len(pmtWithMetaTst1)) copy(cpy, pmtWithMetaTst1) cpy = addCrc(cpy) - err := UpdateLocation(cpy, string(locationTstStr2)) + err := UpdateLocation(cpy, locationTstStr2) cpy = cpy[:len(cpy)-4] if err != nil { t.Errorf("Update time returned err: %v", err) @@ -366,10 +366,8 @@ func TestTrim(t *testing.T) { // buildPmtTimeLocationBytes is a helper function to help construct the byte slices // for pmts with time and location, as the location data field is 32 bytes, i.e. quite large // to type out -func buildPmtWithMeta(tstStr []byte) []byte { - dst := make([]byte, len(pmtWithMetaHead)+32+len(pmtWithMetaTail)) - copy(dst, pmtWithMetaHead) - copy(dst[len(pmtWithMetaHead):], tstStr) - copy(dst[len(pmtWithMetaHead)+32:], pmtWithMetaTail) - return dst +func buildPmtWithMeta(tstStr string) []byte { + pmt := append(pmtWithMetaHead, []byte(tstStr)...) + pmt = append(pmt, pmtWithMetaTail...) + return pmt } From 239cebe34780425a17de712515bd19c228b13263 Mon Sep 17 00:00:00 2001 From: saxon Date: Sun, 20 Jan 2019 21:12:26 +1030 Subject: [PATCH 06/10] psi/psi_test.go: made location tsts const --- stream/mts/psi/psi_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stream/mts/psi/psi_test.go b/stream/mts/psi/psi_test.go index ab173b58..ff0b9034 100644 --- a/stream/mts/psi/psi_test.go +++ b/stream/mts/psi/psi_test.go @@ -123,7 +123,7 @@ const ( // GPS string for testing // TODO: make these realistic -var ( +const ( locationTstStr1 = "$GPGGA,123519,4807.038,N,01131.0" locationTstStr2 = "$GPGGA,183710,4902.048,N,02171.0" ) From c4990c946fe5148d152f07e6ae0de7404c9a7c9d Mon Sep 17 00:00:00 2001 From: saxon Date: Sun, 20 Jan 2019 21:39:07 +1030 Subject: [PATCH 07/10] psi/psi_test.go: not wrapp tstStr in []byte --- stream/mts/psi/psi_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stream/mts/psi/psi_test.go b/stream/mts/psi/psi_test.go index ff0b9034..1e9a30ef 100644 --- a/stream/mts/psi/psi_test.go +++ b/stream/mts/psi/psi_test.go @@ -367,7 +367,7 @@ func TestTrim(t *testing.T) { // for pmts with time and location, as the location data field is 32 bytes, i.e. quite large // to type out func buildPmtWithMeta(tstStr string) []byte { - pmt := append(pmtWithMetaHead, []byte(tstStr)...) + pmt := append(pmtWithMetaHead, tstStr...) pmt = append(pmt, pmtWithMetaTail...) return pmt } From a24e4ecb81e3ed3e248d56010eae5b6e3eba0221 Mon Sep 17 00:00:00 2001 From: saxon Date: Sun, 20 Jan 2019 21:48:34 +1030 Subject: [PATCH 08/10] psi/psi_test.go: not making it look like I'm appending directly to a global --- stream/mts/psi/psi_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stream/mts/psi/psi_test.go b/stream/mts/psi/psi_test.go index 1e9a30ef..5dd2d840 100644 --- a/stream/mts/psi/psi_test.go +++ b/stream/mts/psi/psi_test.go @@ -367,7 +367,9 @@ func TestTrim(t *testing.T) { // for pmts with time and location, as the location data field is 32 bytes, i.e. quite large // to type out func buildPmtWithMeta(tstStr string) []byte { - pmt := append(pmtWithMetaHead, tstStr...) + tmp := make([]byte, len(pmtWithMetaHead)) + copy(tmp, pmtWithMetaHead) + pmt := append(tmp, tstStr...) pmt = append(pmt, pmtWithMetaTail...) return pmt } From 67d952c6a755e458810496a615a343be81c1411f Mon Sep 17 00:00:00 2001 From: saxon Date: Sun, 20 Jan 2019 21:58:23 +1030 Subject: [PATCH 09/10] psi/psi_test.go: made buildPmtWithMeta() safer and readable --- stream/mts/psi/psi_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/stream/mts/psi/psi_test.go b/stream/mts/psi/psi_test.go index 5dd2d840..fdce41fe 100644 --- a/stream/mts/psi/psi_test.go +++ b/stream/mts/psi/psi_test.go @@ -367,9 +367,9 @@ func TestTrim(t *testing.T) { // for pmts with time and location, as the location data field is 32 bytes, i.e. quite large // to type out func buildPmtWithMeta(tstStr string) []byte { - tmp := make([]byte, len(pmtWithMetaHead)) - copy(tmp, pmtWithMetaHead) - pmt := append(tmp, tstStr...) - pmt = append(pmt, pmtWithMetaTail...) - return pmt + dst := make([]byte, len(pmtWithMetaHead)+32+len(pmtWithMetaTail)) + copy(dst, pmtWithMetaHead) + copy(dst[len(pmtWithMetaHead):], tstStr) + copy(dst[len(pmtWithMetaHead)+32:], pmtWithMetaTail) + return dst } From bc3a73bedcebb303227dc710486e09ad45e4e85f Mon Sep 17 00:00:00 2001 From: saxon Date: Mon, 21 Jan 2019 18:25:06 +1030 Subject: [PATCH 10/10] av/stream/psi/psi_test.go: updated comment for buildPmtWithMeta() --- stream/mts/psi/psi_test.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/stream/mts/psi/psi_test.go b/stream/mts/psi/psi_test.go index fdce41fe..e437066e 100644 --- a/stream/mts/psi/psi_test.go +++ b/stream/mts/psi/psi_test.go @@ -363,9 +363,7 @@ func TestTrim(t *testing.T) { } } -// buildPmtTimeLocationBytes is a helper function to help construct the byte slices -// for pmts with time and location, as the location data field is 32 bytes, i.e. quite large -// to type out +// buildPmtTimeLocationBytes returns a PMT with time and location from s. func buildPmtWithMeta(tstStr string) []byte { dst := make([]byte, len(pmtWithMetaHead)+32+len(pmtWithMetaTail)) copy(dst, pmtWithMetaHead)