psi/helpers.go: modified UpdateLocation() to make updating of location in pmt cleaner, and also removed redundant conversion of string to byte slice

This commit is contained in:
saxon 2019-01-20 20:14:27 +10:30
parent 98d89a4e4e
commit 5c4795786e
1 changed files with 5 additions and 8 deletions

View File

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