Giter Club home page Giter Club logo

goscale's Introduction

SCALE codec implementation in Go compatible with a Tinygo based toolchain

codecov

The SCALE types in Go are represented by a set of custom-defined types that implement the Encodable interface. There is also a Decode function for each type. Note that the type to which data should be decoded is inferred by the context, it is not self-contained in the SCALE encoded data.

One exception is the Tuple type, which does not have methods attached, but instead, there are EncodeTuple / DecodeTuple functions that can be called with any custom struct that embeds the Tuple interface.

Implementation Notes

  • custom defined types and usage of generics help to minimize the reflection usage.
  • there is a FixedSequence type (with the same representation as the Sequence type), but it makes possible encoding of arrays (which are fixed-size sequences) that can not be represented by the Sequence type. Note that there are no type checks on the size
SCALE/Rust Go
bool goscale.Bool
SCALE/Rust Go
i8 goscale.I8
u8 goscale.U8
i16 goscale.I16
u16 goscale.U16
i32 goscale.I32
u32 goscale.U32
i64 goscale.I64
u64 goscale.U64
i128 goscale.I128
u128 goscale.U128
SCALE/Rust Go
Compact<u8> goscale.Compact
Compact<u16> goscale.Compact
Compact<u32> goscale.Compact
Compact<u64> goscale.Compact
Compact<u128> goscale.Compact
SCALE/Rust Go
bytes goscale.Sequence[U8]
[u8; u8] goscale.FixedSequence[U8]
string goscale.Str
SCALE/Rust Go
goscale.Dictionary[K, V]
SCALE/Rust Go
SCALE/Rust Go
Enumeration(tagged-union) goscale.VaryingData
SCALE/Rust Go
Option<bool> Option[goscale.Bool]
Option<i8> Option[goscale.I8]
Option<u8> Option[goscale.U8]
Option<i16> Option[goscale.I16]
Option<u16> Option[goscale.U16]
Option<i32> Option[goscale.I32]
Option<u32> Option[goscale.U32]
Option<i64> Option[goscale.I64]
Option<u64> Option[goscale.U64]
Option<i128> Option[goscale.I128]
Option<u128> Option[goscale.U128]
Option<bytes> Option[Sequence[U8]]
OptionBool OptionBool
None nil
SCALE/Rust Go

Go structs are encoded as SCALE Tuple, where each struct field is encoded in a sequence containing all the fields. To decode SCALE encoded structs, it is required to have prior knowledge of the destination data type.

SCALE Go
struct goscale.Tuple

Run Tests

go test -v

goscale's People

Contributors

radkomih avatar failfmi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.