ged

package module
v0.0.0-...-0ab05d7 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2021 License: MIT Imports: 4 Imported by: 0

README

GED - Global-purpose Encoding / Decoding library

Go

This library lets you use common encoding/decoding schemes and allows you to define custom ones.

Use standard hex encoding/decoding:

encoded := ged.EncodeHex([]byte("Hello World"))
// => 48656c6c6f20576f726c64
decoded, err := ged.DecodeHex(encoded)
// => Hello World

Use standard base58 encoding/decoding:

encoded := ged.Encode58([]byte("Hello World"))
// => JxF12TrwUP45BMd
decoded, err := ged.Decode58(encoded)
// => Hello World

Use a custom encoding:

alphabet := alphabet.MustCreate("ABCD1234")

encoded := ged.EncodeString([]byte("Hello World"), alphabet)
// => 11B12DDA33B24BAA2D224D1133B11
decoded, err := ged.DecodeString(encoded, alphabet)
// => Hello World

Documentation

Overview

Package ged implements a global-purpose encoding/decoding library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(data []byte, baseFrom uint) ([]byte, error)

Decode decodes data from a given base. baseTo SHOULD NOT be greater than 256.

func Decode58

func Decode58(encoded string) ([]byte, error)

DecodeBase58 decodes string from a base58 representation using the Bitcoin alphabet.

func DecodeHex

func DecodeHex(encoded string) ([]byte, error)

DecodeHex decodes encoded hex string.

func DecodeString

func DecodeString(encoded string, alphabet alphabet.Alphabet) ([]byte, error)

DecodeString decodes string using the provided alphabet.

func Encode

func Encode(data []byte, baseTo uint) []byte

Encode encodes data to a given base. baseTo SHOULD NOT be greater than 256.

func Encode58

func Encode58(data []byte) string

EncodeBase58 encodes data to a base58 representation using the Bitcoin alphabet.

func EncodeHex

func EncodeHex(data []byte) string

EncodeHex encodes data to hexadecimal. Uses the lower case letter form.

func EncodeString

func EncodeString(data []byte, alphabet alphabet.Alphabet) string

EncodeString encodes data using a provided alphabet.

func Transform

func Transform(data []byte, baseFrom, baseTo uint) ([]byte, error)

Transform is a low-level generic function to transform bytes from a given base to a target base. Returns an error if an element in data is greater or equal than the given base: if the baseFrom is 128, then all elements from data must be lower than 128. baseFrom and baseTo SHOULD NOT be greater than 256 and MUST NOT be lower than 2.

Types

This section is empty.

Directories

Path Synopsis
Package alphabet defines character sets for encoding/decoding.
Package alphabet defines character sets for encoding/decoding.

Jump to

Keyboard shortcuts

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