Prevent multiple newlines being emitted in encoding, newlines added as extra data in decoding
This commit is contained in:
parent
b4e6435498
commit
44ed702c86
|
@ -26,7 +26,10 @@ func Decode(data []byte) (stream *Stream, err error) {
|
|||
}
|
||||
|
||||
if d[0] != ':' {
|
||||
currentRegion.Extra = append(currentRegion.Extra, strings.Trim(d, "\r\n"))
|
||||
extra := strings.Trim(d, "\r\n")
|
||||
if len(extra) > 0 {
|
||||
currentRegion.Extra = append(currentRegion.Extra, extra)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ func Encode(stream *Stream) (hex []byte, err error) {
|
|||
var entries []string
|
||||
|
||||
emitRecord := func(r Record) {
|
||||
entries = append(entries, r.String()+"\r\n")
|
||||
entries = append(entries, r.String())
|
||||
}
|
||||
|
||||
emitAddress := func(addr uint32) error {
|
||||
|
@ -43,7 +43,7 @@ func Encode(stream *Stream) (hex []byte, err error) {
|
|||
|
||||
// Add extra entries as needed
|
||||
for _, e := range r.Extra {
|
||||
entries = append(entries, e+"\r\n")
|
||||
entries = append(entries, e)
|
||||
}
|
||||
|
||||
endAddress := r.Address + uint32(len(r.Data))
|
||||
|
|
|
@ -41,7 +41,7 @@ func (r Record) String() string {
|
|||
buf[3] = uint8(r.Code)
|
||||
copy(buf[4:], r.Data)
|
||||
buf[len(buf)-1] = Checksum(buf[:len(buf)-1])
|
||||
return ":" + strings.ToUpper(hex.EncodeToString(buf)) + "\r\n"
|
||||
return ":" + strings.ToUpper(hex.EncodeToString(buf))
|
||||
}
|
||||
|
||||
func RecordFromString(data string) (Record, error) {
|
||||
|
|
Loading…
Reference in a new issue