base58

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2025 License: MIT Imports: 2 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

base58

CI codecov Go Report Card Go Reference GitHub license

About

This base58 package implements Logic optimized for unsigned int64.

Install

$ go get -u github.com/osamingo/bae58

Usage

package main

import (
	"log"

	"github.com/osamingo/base58"
)

func main() {

	enc, err := base58.NewEncoder(base58.StandardSource)
	if err != nil {
		log.Fatal("failed to generate base58.Encoder", err)
	}

	src := uint64(9223372036854775808)
	dst := enc.Encode(src)

	log.Println(dst)
	// Output: NQm6nKp8qFD

	ret, err := enc.Decode(dst)
	if err != nil {
		log.Fatal("failed to decode, dst = "+dst, err)
	}

	log.Println(ret)
	// Output: 9223372036854775808
}

Benchmark

# Machine: MacBook Pro (13-inch, 2018, Four Thunderbolt 3 Ports)
# CPU    : 2.7 GHz Intel Core i7
# Memory : 16 GB 2133 MHz LPDDR3

goos: darwin
goarch: amd64
pkg: github.com/osamingo/base58
BenchmarkEncoder_Encode-8   	15775299        71.5 ns/op      46 B/op      1 allocs/op
BenchmarkEncoder_Decode-8   	36928071        29.8 ns/op       0 B/op      0 allocs/op
PASS

License

Released under the MIT License.

Documentation

Index

Constants

View Source
const (
	// A CharacterLength defines source characters length.
	CharacterLength = 58
	// A StandardSource defines standard characters of base58.
	StandardSource = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
)

Variables

View Source
var (
	// ErrInvalidArgument expresses invalid argument error.
	ErrInvalidArgument = errors.New("base58: invalid argument")
	// ErrUnknownCharacter expresses contains an unknown character error.
	ErrUnknownCharacter = errors.New("base58: contains an unknown character")
)

Functions

This section is empty.

Types

type Encoder

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

An Encoder implements encoding and decoding of base58.

func MustNewEncoder

func MustNewEncoder(source string) *Encoder

MustNewEncoder returns new base58.Encoder.

func NewEncoder

func NewEncoder(source string) (*Encoder, error)

NewEncoder returns new base58.Encoder.

func (*Encoder) Decode

func (enc *Encoder) Decode(id string) (uint64, error)

Decode returns decoded unsigned int64 by base58.

func (*Encoder) Encode

func (enc *Encoder) Encode(id uint64) string

Encode returns encoded string by base58.

Jump to

Keyboard shortcuts

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