Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Codec ¶
type Codec[T any] struct{}
Codec is a Codec[T] backed by encoding/json. It is safe for concurrent use.
Example ¶
type Data struct {
Name string
}
c := json.NewCodec[Data]()
encoded, err := c.Encode(Data{Name: "example-123"})
if err != nil {
fmt.Printf("Encode failed: %v\n", err)
return
}
fmt.Printf("Encoded: %s\n", string(encoded))
var decoded Data
if err := c.Decode(encoded, &decoded); err != nil {
fmt.Printf("Decode failed: %v\n", err)
return
}
fmt.Printf("Decoded Name: %s\n", decoded.Name)
Output: Encoded: {"Name":"example-123"} Decoded Name: example-123
type StreamCodec ¶
type StreamCodec[T any] struct{}
StreamCodec is a StreamCodec[T] backed by encoding/json. It is safe for concurrent use.
Example ¶
type Data struct {
Name string
}
c := json.NewStreamCodec[Data]()
var buf bytes.Buffer
if err := c.Encode(&buf, Data{Name: "example-123"}); err != nil {
fmt.Printf("Encode failed: %v\n", err)
return
}
var decoded Data
if err := c.Decode(&buf, &decoded); err != nil {
fmt.Printf("Decode failed: %v\n", err)
return
}
fmt.Printf("Decoded Name: %s\n", decoded.Name)
Output: Decoded Name: example-123
func NewStreamCodec ¶
func NewStreamCodec[T any]() *StreamCodec[T]
NewStreamCodec returns a JSON stream serializer for T.
Click to show internal directories.
Click to hide internal directories.