19 lines
481 B
Go
19 lines
481 B
Go
package orbit
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
)
|
|
|
|
// marshalWire 不做 HTML 转义,保持 RawMessage 精确数字及受控载荷大小。
|
|
// 这些文档只用于 JSON/WS 通道,不能直接嵌入 HTML。
|
|
func marshalWire(value any) ([]byte, error) {
|
|
var buffer bytes.Buffer
|
|
encoder := json.NewEncoder(&buffer)
|
|
encoder.SetEscapeHTML(false)
|
|
if err := encoder.Encode(value); err != nil {
|
|
return nil, err
|
|
}
|
|
return bytes.TrimSuffix(buffer.Bytes(), []byte{'\n'}), nil
|
|
}
|