(input io.Reader, packetCh chan baseds.RpcInputChType, rawCh chan []byte)
| 46 | } |
| 47 | |
| 48 | func Parse(input io.Reader, packetCh chan baseds.RpcInputChType, rawCh chan []byte) error { |
| 49 | bufReader := bufio.NewReader(input) |
| 50 | defer close(packetCh) |
| 51 | defer close(rawCh) |
| 52 | for { |
| 53 | // note this line does have a trailing newline |
| 54 | line, err := bufReader.ReadBytes('\n') |
| 55 | if err == io.EOF { |
| 56 | return nil |
| 57 | } |
| 58 | if err != nil { |
| 59 | return err |
| 60 | } |
| 61 | if len(line) <= 1 { |
| 62 | // just a blank line |
| 63 | continue |
| 64 | } |
| 65 | if bytes.HasPrefix(line, []byte{'#', '#', 'N', '{'}) && bytes.HasSuffix(line, []byte{'}', '\n'}) { |
| 66 | // strip off the leading "##" and trailing "\n" (single byte) |
| 67 | packetCh <- baseds.RpcInputChType{MsgBytes: line[3 : len(line)-1]} |
| 68 | } else { |
| 69 | rawCh <- line |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | func WritePacket(output io.Writer, packet []byte) error { |
| 75 | if len(packet) < 2 { |
no outgoing calls
no test coverage detected