content

package
v0.58.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

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 New

func New(data []byte) Content

func (Content) Bytes

func (c Content) Bytes() []byte

func (Content) MarshalJSON

func (c Content) MarshalJSON() ([]byte, error)

func (Content) Text

func (c Content) Text() (string, bool)

Text reports whether the entire content is valid UTF-8. It never guesses an encoding or repairs a truncated sequence.

func (*Content) UnmarshalJSON

func (c *Content) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL