Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Codec ¶
type Codec struct{}
Codec is a Codec[*pem.Block] backed by encoding/pem. It is safe for concurrent use.
Example ¶
package main
import (
stdpem "encoding/pem"
"fmt"
"github.com/foomo/goencode/pem"
)
func main() {
c := pem.NewCodec()
block := &stdpem.Block{
Type: "TEST",
Bytes: []byte("hello"),
}
encoded, err := c.Encode(block)
if err != nil {
fmt.Printf("Encode failed: %v\n", err)
return
}
fmt.Printf("Encoded:\n%s", string(encoded))
var decoded *stdpem.Block
if err := c.Decode(encoded, &decoded); err != nil {
fmt.Printf("Decode failed: %v\n", err)
return
}
fmt.Printf("Decoded Type: %s\n", decoded.Type)
fmt.Printf("Decoded Bytes: %s\n", string(decoded.Bytes))
}
Output: Encoded: -----BEGIN TEST----- aGVsbG8= -----END TEST----- Decoded Type: TEST Decoded Bytes: hello
type StreamCodec ¶
type StreamCodec struct{}
StreamCodec is a StreamCodec[*pem.Block] backed by encoding/pem. It is safe for concurrent use.
Example ¶
package main
import (
"bytes"
stdpem "encoding/pem"
"fmt"
"github.com/foomo/goencode/pem"
)
func main() {
c := pem.NewStreamCodec()
block := &stdpem.Block{
Type: "TEST",
Bytes: []byte("hello"),
}
var buf bytes.Buffer
if err := c.Encode(&buf, block); err != nil {
fmt.Printf("Encode failed: %v\n", err)
return
}
var decoded *stdpem.Block
if err := c.Decode(&buf, &decoded); err != nil {
fmt.Printf("Decode failed: %v\n", err)
return
}
fmt.Printf("Decoded Type: %s\n", decoded.Type)
fmt.Printf("Decoded Bytes: %s\n", string(decoded.Bytes))
}
Output: Decoded Type: TEST Decoded Bytes: hello
func NewStreamCodec ¶
func NewStreamCodec() *StreamCodec
NewStreamCodec returns a PEM stream serializer.
Click to show internal directories.
Click to hide internal directories.