EncodeIndent is like EncodeMessage, but honors indents. TODO(rfindley): refactor so that this concern is handled independently. Perhaps we should pass in a json.Encoder?
(msg Message, prefix, indent string)
| 159 | // TODO(rfindley): refactor so that this concern is handled independently. |
| 160 | // Perhaps we should pass in a json.Encoder? |
| 161 | func EncodeIndent(msg Message, prefix, indent string) ([]byte, error) { |
| 162 | wire := wireCombined{VersionTag: wireVersion} |
| 163 | msg.marshal(&wire) |
| 164 | var buf bytes.Buffer |
| 165 | enc := json.NewEncoder(&buf) |
| 166 | enc.SetEscapeHTML(false) |
| 167 | enc.SetIndent(prefix, indent) |
| 168 | if err := enc.Encode(&wire); err != nil { |
| 169 | return nil, fmt.Errorf("marshaling jsonrpc message: %w", err) |
| 170 | } |
| 171 | return bytes.TrimRight(buf.Bytes(), "\n"), nil |
| 172 | } |
| 173 | |
| 174 | func DecodeMessage(data []byte) (Message, error) { |
| 175 | msg := wireCombined{} |
searching dependent graphs…