MCPcopy
hub / github.com/wavetermdev/waveterm / Parse

Function Parse

pkg/util/packetparser/packetparser.go:48–72  ·  view source on GitHub ↗
(input io.Reader, packetCh chan baseds.RpcInputChType, rawCh chan []byte)

Source from the content-addressed store, hash-verified

46}
47
48func 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
74func WritePacket(output io.Writer, packet []byte) error {
75 if len(packet) < 2 {

Callers 2

SetupPacketRpcClientFunction · 0.92
serverRunRouterFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected