Merge pull request #9 from csucu/fix-relayAsyncEvents

Modified parsing of eventcode in relayAsyncEvents
This commit is contained in:
Chad Retz 2018-07-24 10:20:39 -05:00 committed by GitHub
commit a3771891b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 4 deletions

View File

@ -271,11 +271,16 @@ func (c *Conn) relayAsyncEvents(resp *Response) {
var dataArray []string
if len(resp.Data) == 1 {
// If there is a single line of data, first line of it is the code, rest of the first line is data
firstNewline := strings.Index(resp.Data[0], "\r\n")
if firstNewline == -1 {
return
// Find the index which specfies the char after the event code, either space or newline
index := strings.Index(resp.Data[0], " ")
if index == -1 {
index = strings.Index(resp.Data[0], "\r\n")
if index == -1 {
return
}
}
code, data = resp.Data[0][:firstNewline], resp.Data[0][firstNewline+2:]
code, data = resp.Data[0][:index], resp.Data[0][index+2:]
} else if len(resp.Data) > 0 {
// If there are multiple lines, the entire first line is the code
code, dataArray = resp.Data[0], resp.Data[1:]