bytesutil

package
v0.85.0-pre.1 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: BSD-3-Clause Imports: 6 Imported by: 0

README

kit/bytesutil

github.com/vormadev/vorma/kit/bytesutil

Small helpers for:

  • base64 (standard)
  • base64 URL-safe raw (no padding)
  • base32 raw (no padding)
  • gob encode/decode

Import

import "github.com/vormadev/vorma/kit/bytesutil"

Common Usage

Base64
raw := []byte("hello")
enc := bytesutil.ToBase64(raw)
dec, err := bytesutil.FromBase64(enc)
URL-safe token encoding
token := bytesutil.ToBase64URLRaw([]byte("user:123"))
plain, err := bytesutil.FromBase64URLRaw(token)
Gob round-trip
type Session struct {
	UserID string
	Role   string
}

payload, err := bytesutil.ToGob(Session{UserID: "u1", Role: "admin"})
if err != nil {
	return err
}

session, err := bytesutil.FromGob[Session](payload)
if err != nil {
	return err
}
_ = session
Decode into an existing destination
var session Session
if err := bytesutil.FromGobInto(payload, &session); err != nil {
	return err
}

Behavior Notes

  • ToGob returns an error for typed nil pointers.
  • FromGob and FromGobInto return errors for nil/invalid gob bytes.
  • FromGobInto expects a destination pointer.
  • If you encode interface values with gob, register concrete types as needed (encoding/gob rules apply).

API Reference

  • func ToBase64(b []byte) string
  • func FromBase64(s string) ([]byte, error)
  • func ToBase64URLRaw(b []byte) string
  • func FromBase64URLRaw(s string) ([]byte, error)
  • func ToBase32Raw(b []byte) string
  • func FromBase32Raw(s string) ([]byte, error)
  • func ToGob(src any) ([]byte, error)
  • func FromGob[T any](gobBytes []byte) (T, error)
  • func FromGobInto(gobBytes []byte, destPtr any) error

Documentation

Overview

Package bytesutil provides utility functions for byte slice operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromBase32Raw

func FromBase32Raw(s string) ([]byte, error)

FromBase32Raw decodes a base32-encoded string into a byte slice without padding.

func FromBase64

func FromBase64(s string) ([]byte, error)

FromBase64 decodes a base64-encoded string into a byte slice.

func FromBase64URLRaw

func FromBase64URLRaw(s string) ([]byte, error)

FromBase64URLRaw decodes a base64 URL-safe encoded string into a byte slice without padding.

func FromGob

func FromGob[T any](gobBytes []byte) (T, error)

FromGob decodes a gob-encoded byte slice into a value of type T.

func FromGobInto

func FromGobInto(gobBytes []byte, destPtr any) error

FromGobInto decodes a gob-encoded byte slice into a destination. The destination must be a pointer to the destination type.

func ToBase32Raw

func ToBase32Raw(b []byte) string

ToBase32Raw encodes a byte slice into a base32-encoded string without padding.

func ToBase64

func ToBase64(b []byte) string

ToBase64 encodes a byte slice into a base64-encoded string.

func ToBase64URLRaw

func ToBase64URLRaw(b []byte) string

ToBase64URLRaw encodes a byte slice into a base64 URL-safe encoded string without padding.

func ToGob

func ToGob(src any) ([]byte, error)

ToGob encodes an arbitrary value into a gob-encoded byte slice.

Types

This section is empty.

Jump to

Keyboard shortcuts

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