Documentation
¶
Overview ¶
Package content preserves arbitrary tool-response bytes in a readable JSON representation. Valid UTF-8 remains text; other bytes use explicit base64.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrInvalidContent = errors.New("tools/content: invalid encoded bytes")
Functions ¶
This section is empty.
Types ¶
type Content ¶
type Content struct {
// contains filtered or unexported fields
}
Content owns an immutable byte sequence. Its zero value is empty content. A UTF-8 prefix cut in the middle of a character remains recoverable bytes; encoding never replaces invalid bytes with a Unicode replacement character.
Example ¶
package main
import (
jsonv2 "encoding/json/v2"
"fmt"
"github.com/Tangerg/scope/tools/content"
)
func main() {
value := content.New([]byte{0xff, 0x00})
encoded, err := jsonv2.Marshal(value)
if err != nil {
panic(err)
}
fmt.Println(string(encoded))
fmt.Printf("%x\n", value.Bytes())
}
Output: {"encoding":"base64","data":"/wA="} ff00
func (Content) JSONSchemaModel ¶ added in v0.60.0
func (Content) MarshalJSON ¶
func (Content) Text ¶
Text reports whether the entire content is valid UTF-8. It never guesses an encoding or repairs a truncated sequence.
func (*Content) UnmarshalJSON ¶
Click to show internal directories.
Click to hide internal directories.