updating structure and documentation
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -18,3 +18,4 @@
|
||||
/.idea/modules.xml
|
||||
/.idea/transcribe.iml
|
||||
/.idea/vcs.xml
|
||||
/.idea/
|
||||
|
||||
@@ -9,7 +9,7 @@ microservice, including simple concurrency
|
||||
|
||||
This tutorial demonstrates the use of almost every possible and important
|
||||
feature of Go. A "toy" implementation of a gRPC/protobuf microservice is added
|
||||
in order to illustrate almost everything.
|
||||
in order to illustrate almost everything else.
|
||||
|
||||
In order to demonstrate synchronisation primitives, waitgroups, atomics and
|
||||
mutexes, the service will keep track of the number of invocations, print this
|
||||
|
||||
@@ -8,7 +8,9 @@
|
||||
package bech32
|
||||
|
||||
import (
|
||||
"github.com/cybriq/transcribe/codec"
|
||||
"fmt"
|
||||
"github.com/cosmos/btcutil/bech32"
|
||||
codec "github.com/quanterall/kitchensink"
|
||||
)
|
||||
|
||||
// Spec is the collection of elements derived from the codec type definition
|
||||
@@ -30,3 +32,28 @@ var Spec = codec.Codec{
|
||||
return false
|
||||
},
|
||||
}
|
||||
|
||||
// ConvertAndEncode converts from a base64 encoded byte string to base32 encoded byte string and then to bech32.
|
||||
func ConvertAndEncode(hrp string, data []byte) (string, error) {
|
||||
converted, err := bech32.ConvertBits(data, 8, 5, true)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("encoding bech32 failed: %w", err)
|
||||
}
|
||||
|
||||
return bech32.Encode(hrp, converted)
|
||||
}
|
||||
|
||||
// DecodeAndConvert decodes a bech32 encoded string and converts to base64 encoded bytes.
|
||||
func DecodeAndConvert(bech string) (string, []byte, error) {
|
||||
hrp, data, err := bech32.Decode(bech, 1023)
|
||||
if err != nil {
|
||||
return "", nil, fmt.Errorf("decoding bech32 failed: %w", err)
|
||||
}
|
||||
|
||||
converted, err := bech32.ConvertBits(data, 5, 8, false)
|
||||
if err != nil {
|
||||
return "", nil, fmt.Errorf("decoding bech32 failed: %w", err)
|
||||
}
|
||||
|
||||
return hrp, converted, nil
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
# codec
|
||||
|
||||
codec is an example and framework for building custom human readable binary
|
||||
transcription encoders.
|
||||
|
||||
The type definition found in [types.go](./types.go) is intended to be used
|
||||
by external definitions that fill in all the fields with the concrete
|
||||
implementation details.
|
||||
17
codec/doc.go
17
codec/doc.go
@@ -1,17 +0,0 @@
|
||||
// Package codec is a generalised encoder and decoder for encoding short
|
||||
// binary values such as used in cryptocurrency addresses, accounts and
|
||||
// transaction hashes.
|
||||
//
|
||||
// This codec is intended to be extended via implementations adding the
|
||||
// functions specific to an implementation to the generalised implementation
|
||||
// provided in this package that invokes these implementation specific features
|
||||
// and configurations.
|
||||
//
|
||||
// This is part of a tutorial for teaching the correct way to create a Go
|
||||
// library, which includes this file that provides the header for the godoc
|
||||
// output.
|
||||
//
|
||||
// All exported symbols in Go code should have proper and informative comments
|
||||
// added above them as this adds to the head of the package identifier. No
|
||||
// released code should be without these on every identifier.
|
||||
package codec
|
||||
@@ -1,10 +1,10 @@
|
||||
package codec
|
||||
package transcribe
|
||||
|
||||
import (
|
||||
. "github.com/cybriq/transcribe/codec/codecer"
|
||||
"github.com/quanterall/kitchensink/codecer"
|
||||
)
|
||||
|
||||
func NewCodec(cdc *Codec) Codecer {
|
||||
func NewCodec(cdc *Codec) codecer.Codecer {
|
||||
// Make sure the provided codec has all the parts that are used in the
|
||||
// interface
|
||||
if cdc.Encoder == nil ||
|
||||
@@ -1,4 +1,4 @@
|
||||
package codec
|
||||
package transcribe
|
||||
|
||||
import (
|
||||
"github.com/cybriq/transcribe/codec/codecer"
|
||||
Reference in New Issue
Block a user