Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewCodec ¶
NewCodec returns a Hex codec. It is safe for concurrent use.
Example ¶
package main
import (
"fmt"
"github.com/foomo/goencode/hex"
)
func main() {
c := hex.NewCodec()
encoded, err := c.Encode([]byte("hello"))
if err != nil {
fmt.Printf("Encode failed: %v\n", err)
return
}
fmt.Printf("Encoded: %s\n", string(encoded))
}
Output: Encoded: 68656c6c6f
func NewStreamCodec ¶
func NewStreamCodec() encoding.StreamCodec[[]byte]
NewStreamCodec returns a Hex stream codec. It is safe for concurrent use.
Example ¶
package main
import (
"bytes"
"fmt"
"github.com/foomo/goencode/hex"
)
func main() {
c := hex.NewStreamCodec()
var buf bytes.Buffer
if err := c.Encode(&buf, []byte("hello")); err != nil {
fmt.Printf("Encode failed: %v\n", err)
return
}
fmt.Printf("Encoded: %s\n", buf.String())
var decoded []byte
if err := c.Decode(&buf, &decoded); err != nil {
fmt.Printf("Decode failed: %v\n", err)
return
}
fmt.Printf("Decoded: %s\n", string(decoded))
}
Output: Encoded: 68656c6c6f Decoded: hello
func StreamDecoder ¶ added in v0.2.0
StreamDecoder decodes bytes from a hexadecimal stream.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.