MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / ParseWithLinesChan

Function ParseWithLinesChan

pkg/util/packetparser/packetparser.go:22–46  ·  view source on GitHub ↗
(input chan utilfn.LineOutput, packetCh chan baseds.RpcInputChType, rawCh chan []byte)

Source from the content-addressed store, hash-verified

20}
21
22func 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
48func Parse(input io.Reader, packetCh chan baseds.RpcInputChType, rawCh chan []byte) error {
49 bufReader := bufio.NewReader(input)

Callers 1

HandleStdIOClientFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected