candid

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: May 17, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

README

Candid

Exceptions

Nat and Int Types

Since int and uint types are usually 32 bits wide on 32-bit systems and 64 bits wide on 64-bit systems we do not support them in Candid, except passing it to a idl.Nat and idl.Int respectively.

Vector Types

Note that for arrays, you must pass the correct amount of elements.

Variant Types

Variants always expect exactly one label and one value, labels are case-sensitive.

Mapping between Candid and Go Types

IDL Type Accepted Go Value(s) Accepted Go Type(s)
null idl.Null, nil *
bool bool bool
nat idl.Nat, uint, uint64, uint32, uint16, uint8 idl.Nat
int idl.Int, int, int64, int32, int16, int8 idl.Int
nat64 uint64, uint32, uint16, uint8 idl.Nat, uint64
nat32 uint32, uint16, uint8 idl.Nat, uint64, uint32
nat16 uint16, uint8 idl.Nat, uint64, uint32, uint16
nat8 uint8 idl.Nat, uint64, uint32, uint16, uint8
int64 int64, int32, int16, int8 idl.Int, int64
int32 int32, int16, int8 idl.Int, int64, int32
int16 int16, int8 idl.Int, int64, int32, int16
int8 int8 idl.Int, int64, int32, int16, int8
float64 float64, float32 float64
float32 float32 float64, float32
text string string
reserved N/A idl.Reserved
empty N/A idl.Empty
principal principal.Principal, []byte principal.Principal
opt {x} nil, {x} *{x}
vec {x} nil, []{x}, [i]{x}, []any, [i]{any}, []{x}, [i]{x}
record ...{x} struct{ ...{x} }, map[string]any struct{ ...{x} }, map[string]any
variant ...{x} struct{ ...{x} }, struct{ ...*{x} }, map[string]any struct{ ...*{x} }, map[string]any

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeValueString

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

DecodeValueString decodes the given value into a candid string.

func DecodeValuesString

func DecodeValuesString(types []idl.Type, values []any) (string, error)

DecodeValuesString decodes the given values into a candid string.

func EncodeValueString

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

EncodeValueString encodes the given candid string into a byte slice.

Example
package main

import (
	"fmt"

	"github.com/aviate-labs/agent-go/candid"
)

func main() {
	e, _ := candid.EncodeValueString("0")
	fmt.Printf("%x\n", e)
}
Output:

4449444c00017c00
Example (Blob)
package main

import (
	"fmt"

	"github.com/aviate-labs/agent-go/candid"
)

func main() {
	e, _ := candid.EncodeValueString("(blob \"deadbeef\")")
	fmt.Printf("%x\n", e)
}
Output:

4449444c016d7b0100086465616462656566

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
package main

import (
	"fmt"
	"os"

	"github.com/aviate-labs/agent-go/candid"
)

func main() {
	raw, _ := os.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