base32768

package module
v0.0.0-...-18e6ce5 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2023 License: MIT Imports: 4 Imported by: 7

README

base32768

go implementation of base32768, optimized for UTF-16.

Check https://github.com/qntm/base32768 for information about base32768.

Example

message := "Hello, World"
d := []byte(message)
fmt.Println(message)
encoding := base32768.SafeEncoding

// Encode to string
e := encoding.EncodeToString(d)
fmt.Println(e)
// Decode string
d, _ = encoding.DecodeString(e)
fmt.Println(string(d))

// Encode
elen := encoding.EncodedLen(len(d))
eb := make([]byte, elen)
encoding.Encode(eb, d)
fmt.Println(eb)
// Decode
dlen := encoding.DecodedLen(len(eb))
db := make([]byte, dlen)
n, _ := encoding.Decode(db, eb)
fmt.Println(string(db[:n]))

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SafeEncoding = NewEncoding(safeAlphabet)

SafeEncoding is a base32768 encoding using only "safe" Unicode runes

View Source
var SafeEncodingCI = NewEncoding(safeAlphabetCI)

SafeEncodingCI is a base32768 encoding using only case insensitive "safe" Unicode runes

View Source
var ShortEncoding = NewEncoding(shortAlphabet)

ShortEncoding is a base32768 encoding use all codepoint from 0x00C0 - 0x0800 to optimize UTF-8 behavior

Functions

This section is empty.

Types

type CorruptInputError

type CorruptInputError int64

func (CorruptInputError) Error

func (e CorruptInputError) Error() string

type Encoding

type Encoding struct {
	// contains filtered or unexported fields
}

An Encoding is a radix 32768 encoding/decoding scheme, defined by a 32768-character alphabet.

func NewEncoding

func NewEncoding(encoder string) *Encoding

NewEncoding returns a new Encoding defined by the given alphabet, The alphabet must be a 1028 characters long and contains only BMP character and 32 block leading characters.

func (*Encoding) Decode

func (enc *Encoding) Decode(dst, src []byte) (n int, err error)

Decode decodes src using the encoding enc. It writes at most DecodedLen(len(src)) bytes to dst and returns the number of bytes written. If src contains invalid base32768 data, it will return the number of bytes successfully written and CorruptInputError. New line characters (\r and \n) are ignored.

func (*Encoding) DecodeString

func (enc *Encoding) DecodeString(s string) ([]byte, error)

DecodeString returns the bytes represented by the base32768 string s.

func (*Encoding) DecodedLen

func (enc *Encoding) DecodedLen(n int) int

DecodedLen returns the maximum length in bytes of the decoded data corresponding to n bytes of base32768-encoded data.

func (*Encoding) Encode

func (enc *Encoding) Encode(dst, src []byte)

Encode encodes src using the encoding enc, writing EncodedLen(len(src)) bytes to dst.

func (*Encoding) EncodeToString

func (enc *Encoding) EncodeToString(src []byte) string

EncodeToString returns the base32768 encoding of src.

func (*Encoding) EncodedLen

func (enc *Encoding) EncodedLen(n int) int

EncodedLen returns the length in bytes of the base32768 encoding of an input buffer of length n.

Jump to

Keyboard shortcuts

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