MarshalDoc serializes a NetworkTrafficDoc to bytes in the specified format. For YAML, it marshals the doc directly (using yaml.Node for Spec). For JSON, it converts yaml.Node Spec to json.RawMessage via a round-trip.
(format Format, doc *NetworkTrafficDoc)
| 96 | // For YAML, it marshals the doc directly (using yaml.Node for Spec). |
| 97 | // For JSON, it converts yaml.Node Spec to json.RawMessage via a round-trip. |
| 98 | func MarshalDoc(format Format, doc *NetworkTrafficDoc) ([]byte, error) { |
| 99 | switch format { |
| 100 | case FormatJSON: |
| 101 | jsonDoc, err := DocToJSON(doc) |
| 102 | if err != nil { |
| 103 | return nil, err |
| 104 | } |
| 105 | return json.Marshal(jsonDoc) |
| 106 | default: |
| 107 | return yamlLib.Marshal(doc) |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | // MarshalDocIndent is like MarshalDoc but produces indented output for JSON. |
| 112 | func MarshalDocIndent(format Format, doc *NetworkTrafficDoc) ([]byte, error) { |