hex

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decoder added in v0.2.0

func Decoder(b []byte, v *[]byte) error

Decoder decodes hexadecimal bytes.

func Encoder added in v0.2.0

func Encoder(v []byte) ([]byte, error)

Encoder encodes bytes to hexadecimal.

func NewCodec

func NewCodec() encoding.Codec[[]byte, []byte]

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

func StreamDecoder(r io.Reader, v *[]byte) error

StreamDecoder decodes bytes from a hexadecimal stream.

func StreamEncoder added in v0.2.0

func StreamEncoder(w io.Writer, v []byte) error

StreamEncoder encodes bytes to a hexadecimal stream.

Types

This section is empty.

Jump to

Keyboard shortcuts

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