candid

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2022 License: Apache-2.0 Imports: 8 Imported by: 1

README

Candid Library written in Golang

Candid is an Interface Description Language (IDL). Its primary purpose is to describe the public interface of a canister that runs on the Internet Computer.

This is still entirely experimental.

Contains:
  • Parser for the Candid IDL signatures.
  • Binary formatting.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeValue

func DecodeValue(value []byte) (string, error)

func DecodeValues

func DecodeValues(types []idl.Type, values []interface{}) (string, error)

func EncodeValue

func EncodeValue(value string) ([]byte, error)
Example
e, _ := candid.EncodeValue("0")
fmt.Printf("%x\n", e)
Output:

4449444c00017c00

func HashId

func HashId(id string) (hash int)

HashId calculates the the hash of the given id.

The hash function is specified as: hash(id) = ( Sum_(i=0..k) utf8(id)[i] * 223^(k-i) ) mod 2^32 where k = |utf8(id)|-1

Example
fmt.Println(HashId("test"))
fmt.Println(HashId("a_very_long_test"))
Output:

1291438162
1731570314

func ParseDID

func ParseDID(raw []byte) (did.Description, error)

ParseDID parses the given raw .did files and returns the Program that is defined in it.

Example
raw, _ := ioutil.ReadFile("testdata/counter.did")
p, _ := candid.ParseDID(raw)
fmt.Println(p)
Output:

service : {
  inc : () -> nat;
}

Types

This section is empty.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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