updating structure and documentation

This commit is contained in:
David Vennik
2022-02-28 08:52:07 +02:00
parent c335b97a33
commit 8a73a2f8a5
8 changed files with 34 additions and 31 deletions

1
.gitignore vendored
View File

@@ -18,3 +18,4 @@
/.idea/modules.xml /.idea/modules.xml
/.idea/transcribe.iml /.idea/transcribe.iml
/.idea/vcs.xml /.idea/vcs.xml
/.idea/

View File

@@ -9,7 +9,7 @@ microservice, including simple concurrency
This tutorial demonstrates the use of almost every possible and important This tutorial demonstrates the use of almost every possible and important
feature of Go. A "toy" implementation of a gRPC/protobuf microservice is added 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 In order to demonstrate synchronisation primitives, waitgroups, atomics and
mutexes, the service will keep track of the number of invocations, print this mutexes, the service will keep track of the number of invocations, print this

View File

@@ -8,7 +8,9 @@
package bech32 package bech32
import ( 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 // Spec is the collection of elements derived from the codec type definition
@@ -30,3 +32,28 @@ var Spec = codec.Codec{
return false 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
}

View File

@@ -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.

View File

@@ -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

View File

@@ -1,10 +1,10 @@
package codec package transcribe
import ( 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 // Make sure the provided codec has all the parts that are used in the
// interface // interface
if cdc.Encoder == nil || if cdc.Encoder == nil ||

View File

@@ -1,4 +1,4 @@
package codec package transcribe
import ( import (
"github.com/cybriq/transcribe/codec/codecer" "github.com/cybriq/transcribe/codec/codecer"