Coder Social home page Coder Social logo

thehowl / cford32 Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 42 KB

Package cford32 implements a base32-like encoding/decoding package, with the encoding scheme specified by Douglas Crockford.

License: BSD 3-Clause "New" or "Revised" License

Go 100.00%

cford32's Introduction

cford32 Go Reference go test

Package cford32 implements a base32-like encoding/decoding package, with the encoding scheme specified by Douglas Crockford.

From the website, the requirements of said encoding scheme are to:

  • Be human readable and machine readable.
  • Be compact. Humans have difficulty in manipulating long strings of arbitrary symbols.
  • Be error resistant. Entering the symbols must not require keyboarding gymnastics.
  • Be pronounceable. Humans should be able to accurately transmit the symbols to other humans using a telephone.

This is slightly different from a simple difference in encoding table from the Go's stdlib encoding/base32, as when decoding the characters i I l L are parsed as 1, and o O is parsed as 0.

This package additionally provides ways to encode uint64's efficiently, as well as efficient encoding to a lowercase variation of the encoding. The encodings never use paddings.

Why?

The main purpose I envision for this package is to create small, friendly, case-insensitive IDs. The encoding and decoding functions exist to match the API of similar packages like the standard library base32, and as such supporting adapting the code of this package for other use cases.

Examples

package main

import (
	"fmt"
	"math/rand"

	"github.com/thehowl/cford32"
)

func main() {
	gen := rand.New(rand.NewSource(12345))

	for i := 0; i < 6; i++ {
		// 1 << 35 allows us to show diverse set of compact/extended
		n := uint64(gen.Int63n(1 << 35))
		fmt.Printf("%11d: %s\n", n, string(cford32.PutCompact(n)))
	}

	// Output:
	// 14334683418: db6kt8t
	// 34093059390: g00000zr1nk9y
	//   417819965: 0ceev9x
	// 17538543416: g00000gap1vsr
	//  5407252823: 514r8aq
	// 16008560262: ex2yfm6
}

cford32's People

Contributors

thehowl avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.