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/asn1. It is safe for concurrent use.
Example ¶
package main
import (
"fmt"
"github.com/foomo/goencode/asn1"
)
func main() {
c := asn1.NewCodec[int]()
encoded, err := c.Encode(42)
if err != nil {
fmt.Printf("Encode failed: %v\n", err)
return
}
var decoded int
if err := c.Decode(encoded, &decoded); err != nil {
fmt.Printf("Decode failed: %v\n", err)
return
}
fmt.Printf("Decoded: %d\n", decoded)
}
Output: Decoded: 42
type StreamCodec ¶
type StreamCodec[T any] struct{}
StreamCodec is a StreamCodec[T] backed by encoding/asn1. It is safe for concurrent use.
Example ¶
package main
import (
"bytes"
"fmt"
"github.com/foomo/goencode/asn1"
)
func main() {
c := asn1.NewStreamCodec[int]()
var buf bytes.Buffer
if err := c.Encode(&buf, 42); err != nil {
fmt.Printf("Encode failed: %v\n", err)
return
}
var decoded int
if err := c.Decode(&buf, &decoded); err != nil {
fmt.Printf("Decode failed: %v\n", err)
return
}
fmt.Printf("Decoded: %d\n", decoded)
}
Output: Decoded: 42
func NewStreamCodec ¶
func NewStreamCodec[T any]() *StreamCodec[T]
NewStreamCodec returns an ASN1 stream serializer for T.
Click to show internal directories.
Click to hide internal directories.