hex

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: MIT Imports: 2 Imported by: 0

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[[]byte] backed by encoding/hex. 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 NewCodec

func NewCodec() *Codec

NewCodec returns a Hex serializer.

func (Codec) Decode

func (Codec) Decode(b []byte, v *[]byte) error

func (Codec) Encode

func (Codec) Encode(v []byte) ([]byte, error)

type StreamCodec

type StreamCodec struct{}

StreamCodec is a StreamCodec[[]byte] backed by encoding/hex. 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 NewStreamCodec

func NewStreamCodec() *StreamCodec

NewStreamCodec returns a Hex stream serializer.

func (StreamCodec) Decode

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

func (StreamCodec) Encode

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

Jump to

Keyboard shortcuts

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