b64

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2017 License: MIT Imports: 1 Imported by: 2

README

b64

Go library convert Int64 or Uint64 variable to string(11 symbols), and convert 11 symbols string back to int64 or uint64

GoDoc

What is it?

Library converts a single intenger to a string of 1 to 11 characters. Conversion is to reduce number characters when writing a long string of numbers.

Example: 1048575 (7 symbols) -> "D___" (4 symbols)

Yes, it is a regular base64 for use in a URL, but it works faster than the standard library "encoding/base64" And it made a little more comfortable when using a conversion of only one number

How to use?

######Convert from number to string package main

import "gopkg.in/webnice/b64.v1"

func main() {
    o := b64.NewUint64(10485251)
    print(o.String(), "\n")
	print(o.Uint64(), "\n")
}

Result:

n_4D
10485251

--

######Convert from string to number

package main

import "gopkg.in/webnice/b64.v1"

func main() {
	obj := b64.NewString("P____A____1")
	if obj.Error() != nil {
		panic(obj.Error())
	}
	print(obj.Uint64(), "\n")
	print(obj.Int64(), "\n")
}

Result:

18446744006063816693
-67645734923

--

Dependencies
NONE
Install
go get gopkg.in/webnice/b64.v1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorUnknownSymbolInString = errors.New(`Unknown symbol in string`)

ErrorUnknownSymbolInString The error occurs when you convert from a string to a number

Functions

This section is empty.

Types

type B64

type B64 interface {
	String() string // Return 64 bit integer in 64-based scale of notation
	Uint64() uint64 // Return 64 bit unsigned integer
	Int64() int64   // Return 64 bit signed integer
	Bits() string   // Return 64 bit integer by bits - string of 0 or 1, string length 64 symbols
	Error() error   // Return last error after conversion
}

B64 Type of interface of converter

func NewInt64

func NewInt64(inp int64) B64

NewInt64 Creating an object converter from signed integer64

func NewString

func NewString(inp string) B64

NewString Creating an object converter from string

func NewUint64

func NewUint64(inp uint64) B64

NewUint64 Creating an object converter from unsigned integer64

Jump to

Keyboard shortcuts

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