| 20 | } |
| 21 | |
| 22 | func ParseWithLinesChan(input chan utilfn.LineOutput, packetCh chan baseds.RpcInputChType, rawCh chan []byte) { |
| 23 | defer close(packetCh) |
| 24 | defer close(rawCh) |
| 25 | for { |
| 26 | // note this line doesn't have a trailing newline |
| 27 | line, ok := <-input |
| 28 | if !ok { |
| 29 | return |
| 30 | } |
| 31 | if line.Error != nil { |
| 32 | log.Printf("ParseWithLinesChan: error reading line: %v", line.Error) |
| 33 | return |
| 34 | } |
| 35 | if len(line.Line) <= 1 { |
| 36 | // just a blank line |
| 37 | continue |
| 38 | } |
| 39 | if bytes.HasPrefix([]byte(line.Line), []byte{'#', '#', 'N', '{'}) && bytes.HasSuffix([]byte(line.Line), []byte{'}'}) { |
| 40 | // strip off the leading "##" |
| 41 | packetCh <- baseds.RpcInputChType{MsgBytes: []byte(line.Line[3:len(line.Line)])} |
| 42 | } else { |
| 43 | rawCh <- []byte(line.Line) |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | func Parse(input io.Reader, packetCh chan baseds.RpcInputChType, rawCh chan []byte) error { |
| 49 | bufReader := bufio.NewReader(input) |