(output io.Writer, packet []byte)
| 72 | } |
| 73 | |
| 74 | func WritePacket(output io.Writer, packet []byte) error { |
| 75 | if len(packet) < 2 { |
| 76 | return nil |
| 77 | } |
| 78 | if packet[0] != '{' || packet[len(packet)-1] != '}' { |
| 79 | return fmt.Errorf("invalid packet, must start with '{' and end with '}'") |
| 80 | } |
| 81 | fullPacket := make([]byte, 0, len(packet)+5) |
| 82 | // we add the extra newline to make sure the ## appears at the beginning of the line |
| 83 | // since writer isn't buffered, we want to send this all at once |
| 84 | fullPacket = append(fullPacket, '\n', '#', '#', 'N') |
| 85 | fullPacket = append(fullPacket, packet...) |
| 86 | fullPacket = append(fullPacket, '\n') |
| 87 | _, err := output.Write(fullPacket) |
| 88 | return err |
| 89 | } |
no test coverage detected