vex

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2020 License: MIT Imports: 2 Imported by: 0

README

vex

Vex is a variable-length, lexicographically-sortable hex format for uint64 values. It can be used instead of fmt.Sprintf("%016x", v) for shorter strings.

Usage

Values can be formatted to strings using the Format() function and formatted strings can be parsed using the Parse() function. Easy peasy.

Format(v uint64) string
Parse(s string) (uint64, error)

How it works

Vex simply formats a value as an unpadded hex-encoded number and then prepends the length of the resulting string (minus 1) as a hex value.

Here are some examples of encodings:

DECIMAL   HEX   VEX    ZERO-PADDED
0         0     00     0000000000000000
1         1     01     0000000000000001
2         2     02     0000000000000002
10        a     0a     000000000000000a
15        f     0f     000000000000000f
16        10    110    0000000000000110
288       120   2120   0000000000002120

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Format

func Format(v uint64) string

Format v into a hex string with a leading digit indicating its length.

func Parse

func Parse(s string) (uint64, error)

Parse s as a hex string with the leading digit indicating its length.

Types

This section is empty.

Jump to

Keyboard shortcuts

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