github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/examples/gno.land/p/demo/cford32/README.md (about)

     1  # cford32
     2  
     3  ```
     4  package cford32 // import "gno.land/p/demo/cford32"
     5  
     6  Package cford32 implements a base32-like encoding/decoding package, with the
     7  encoding scheme specified by Douglas Crockford.
     8  
     9  From the website, the requirements of said encoding scheme are to:
    10  
    11    - Be human readable and machine readable.
    12    - Be compact. Humans have difficulty in manipulating long strings of arbitrary
    13      symbols.
    14    - Be error resistant. Entering the symbols must not require keyboarding
    15      gymnastics.
    16    - Be pronounceable. Humans should be able to accurately transmit the symbols
    17      to other humans using a telephone.
    18  
    19  This is slightly different from a simple difference in encoding table from
    20  the Go's stdlib `encoding/base32`, as when decoding the characters i I l L are
    21  parsed as 1, and o O is parsed as 0.
    22  
    23  This package additionally provides ways to encode uint64's efficiently, as well
    24  as efficient encoding to a lowercase variation of the encoding. The encodings
    25  never use paddings.
    26  
    27  # Uint64 Encoding
    28  
    29  Aside from lower/uppercase encoding, there is a compact encoding, allowing to
    30  encode all values in [0,2^34), and the full encoding, allowing all values in
    31  [0,2^64). The compact encoding uses 7 characters, and the full encoding uses 13
    32  characters. Both are parsed unambiguously by the Uint64 decoder.
    33  
    34  The compact encodings have the first character between ['0','f'], while the
    35  full encoding's first character ranges between ['g','z']. Practically, in your
    36  usage of the package, you should consider which one to use and stick with it,
    37  while considering that the compact encoding, once it reaches 2^34, automatically
    38  switches to the full encoding. The properties of the generated strings are still
    39  maintained: for instance, any two encoded uint64s x,y consistently generated
    40  with the compact encoding, if the numeric value is x < y, will also be x < y in
    41  lexical ordering. However, values [0,2^34) have a "double encoding", which if
    42  mixed together lose the lexical ordering property.
    43  
    44  The Uint64 encoding is most useful for generating string versions of Uint64 IDs.
    45  Practically, it allows you to retain sleek and compact IDs for your applcation
    46  for the first 2^34 (>17 billion) entities, while seamlessly rolling over to the
    47  full encoding should you exceed that. You are encouraged to use it unless you
    48  have a requirement or preferences for IDs consistently being always the same
    49  size.
    50  
    51  To use the cford32 encoding for IDs, you may want to consider using package
    52  gno.land/p/demo/seqid.
    53  
    54  [specified by Douglas Crockford]: https://www.crockford.com/base32.html
    55  
    56  func AppendCompact(id uint64, b []byte) []byte
    57  func AppendDecode(dst, src []byte) ([]byte, error)
    58  func AppendEncode(dst, src []byte) []byte
    59  func AppendEncodeLower(dst, src []byte) []byte
    60  func Decode(dst, src []byte) (n int, err error)
    61  func DecodeString(s string) ([]byte, error)
    62  func DecodedLen(n int) int
    63  func Encode(dst, src []byte)
    64  func EncodeLower(dst, src []byte)
    65  func EncodeToString(src []byte) string
    66  func EncodeToStringLower(src []byte) string
    67  func EncodedLen(n int) int
    68  func NewDecoder(r io.Reader) io.Reader
    69  func NewEncoder(w io.Writer) io.WriteCloser
    70  func NewEncoderLower(w io.Writer) io.WriteCloser
    71  func PutCompact(id uint64) []byte
    72  func PutUint64(id uint64) [13]byte
    73  func PutUint64Lower(id uint64) [13]byte
    74  func Uint64(b []byte) (uint64, error)
    75  type CorruptInputError int64
    76  ```