Documentation
¶
Index ¶
- func Encode(argumentTypes []Type, arguments []interface{}) ([]byte, error)
- func Hash(s string) *big.Int
- type Bool
- type DecodeError
- type Empty
- type Field
- type FieldValue
- type Float
- type FormatError
- type Func
- type Int
- type Method
- type Nat
- type Null
- type Opt
- type PrimType
- type Principal
- type PrincipalMethod
- type Rec
- type Reserved
- type Service
- type Text
- type Tuple
- type Type
- type TypeDefinitionTable
- type Variant
- type Vec
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Bool ¶
type Bool struct {
// contains filtered or unexported fields
}
Example ¶
test([]idl.Type{new(idl.Bool)}, []interface{}{true})
test([]idl.Type{new(idl.Bool)}, []interface{}{false})
test([]idl.Type{new(idl.Bool)}, []interface{}{0})
test([]idl.Type{new(idl.Bool)}, []interface{}{"false"})
Output: 4449444c00017e01 4449444c00017e00 enc: invalid argument: 0 enc: invalid argument: false
func (Bool) AddTypeDefinition ¶
func (Bool) AddTypeDefinition(_ *TypeDefinitionTable) error
func (Bool) EncodeType ¶
func (Bool) EncodeType(_ *TypeDefinitionTable) ([]byte, error)
func (Bool) EncodeValue ¶
type DecodeError ¶
func (DecodeError) Error ¶
func (e DecodeError) Error() string
type Empty ¶
type Empty struct {
// contains filtered or unexported fields
}
func (Empty) AddTypeDefinition ¶
func (Empty) AddTypeDefinition(_ *TypeDefinitionTable) error
func (Empty) EncodeType ¶
func (Empty) EncodeType(_ *TypeDefinitionTable) ([]byte, error)
func (Empty) EncodeValue ¶
type FieldValue ¶
type FieldValue struct {
Name string
Value interface{}
}
type Float ¶
type Float struct {
Base uint8
// contains filtered or unexported fields
}
func Float32 ¶
func Float32() *Float
Example ¶
test([]idl.Type{idl.Float32()}, []interface{}{big.NewFloat(-0.5)})
test([]idl.Type{idl.Float32()}, []interface{}{big.NewFloat(0)})
test([]idl.Type{idl.Float32()}, []interface{}{big.NewFloat(0.5)})
test([]idl.Type{idl.Float32()}, []interface{}{big.NewFloat(3)})
Output: 4449444c000173000000bf 4449444c00017300000000 4449444c0001730000003f 4449444c00017300004040
func Float64 ¶
func Float64() *Float
Example ¶
test([]idl.Type{idl.Float64()}, []interface{}{big.NewFloat(-0.5)})
test([]idl.Type{idl.Float64()}, []interface{}{big.NewFloat(0)})
test([]idl.Type{idl.Float64()}, []interface{}{big.NewFloat(0.5)})
test([]idl.Type{idl.Float64()}, []interface{}{big.NewFloat(3)})
Output: 4449444c000172000000000000e0bf 4449444c0001720000000000000000 4449444c000172000000000000e03f 4449444c0001720000000000000840
func (Float) AddTypeDefinition ¶
func (Float) AddTypeDefinition(_ *TypeDefinitionTable) error
func (Float) EncodeType ¶
func (f Float) EncodeType(_ *TypeDefinitionTable) ([]byte, error)
func (Float) EncodeValue ¶
type FormatError ¶
type FormatError struct {
Description string
}
func (FormatError) Error ¶
func (e FormatError) Error() string
type Func ¶
Example ¶
p, _ := principal.Decode("w7x7r-cok77-xa")
test_(
[]idl.Type{
idl.NewFunc(
[]idl.Type{new(idl.Text)},
[]idl.Type{new(idl.Nat)},
nil,
),
},
[]interface{}{
idl.PrincipalMethod{
Principal: p,
Method: "foo",
},
},
)
Output: 4449444c016a0171017d000100010103caffee03666f6f
func (Func) AddTypeDefinition ¶
func (f Func) AddTypeDefinition(tdt *TypeDefinitionTable) error
func (Func) EncodeType ¶
func (f Func) EncodeType(tdt *TypeDefinitionTable) ([]byte, error)
func (Func) EncodeValue ¶
type Int ¶
type Int struct {
Base uint8
// contains filtered or unexported fields
}
Example ¶
test([]idl.Type{new(idl.Int)}, []interface{}{big.NewInt(0)})
test([]idl.Type{new(idl.Int)}, []interface{}{big.NewInt(42)})
test([]idl.Type{new(idl.Int)}, []interface{}{big.NewInt(1234567890)})
test([]idl.Type{new(idl.Int)}, []interface{}{big.NewInt(-1234567890)})
test([]idl.Type{new(idl.Int)}, []interface{}{func() *big.Int {
bi, _ := new(big.Int).SetString("60000000000000000", 10)
return bi
}()})
Output: 4449444c00017c00 4449444c00017c2a 4449444c00017cd285d8cc04 4449444c00017caefaa7b37b 4449444c00017c808098f4e9b5caea00
func Int8 ¶
func Int8() *Int
Example ¶
test([]idl.Type{idl.Int8()}, []interface{}{big.NewInt(-129)})
test([]idl.Type{idl.Int8()}, []interface{}{big.NewInt(-128)})
test([]idl.Type{idl.Int8()}, []interface{}{big.NewInt(-42)})
test([]idl.Type{idl.Int8()}, []interface{}{big.NewInt(-1)})
test([]idl.Type{idl.Int8()}, []interface{}{big.NewInt(0)})
test([]idl.Type{idl.Int8()}, []interface{}{big.NewInt(1)})
test([]idl.Type{idl.Int8()}, []interface{}{big.NewInt(42)})
test([]idl.Type{idl.Int8()}, []interface{}{big.NewInt(127)})
test([]idl.Type{idl.Int8()}, []interface{}{big.NewInt(128)})
Output: enc: invalid value: -129 4449444c00017780 4449444c000177d6 4449444c000177ff 4449444c00017700 4449444c00017701 4449444c0001772a 4449444c0001777f enc: invalid value: 128
func Int32 ¶
func Int32() *Int
Example ¶
test([]idl.Type{idl.Int32()}, []interface{}{big.NewInt(-1234567890)})
test([]idl.Type{idl.Int32()}, []interface{}{big.NewInt(-42)})
test([]idl.Type{idl.Int32()}, []interface{}{big.NewInt(42)})
test([]idl.Type{idl.Int32()}, []interface{}{big.NewInt(1234567890)})
Output: 4449444c0001752efd69b6 4449444c000175d6ffffff 4449444c0001752a000000 4449444c000175d2029649
func (Int) AddTypeDefinition ¶
func (Int) AddTypeDefinition(_ *TypeDefinitionTable) error
func (Int) EncodeType ¶
func (n Int) EncodeType(_ *TypeDefinitionTable) ([]byte, error)
func (Int) EncodeValue ¶
type Nat ¶
type Nat struct {
Base uint8
// contains filtered or unexported fields
}
Example ¶
test([]idl.Type{new(idl.Nat)}, []interface{}{big.NewInt(-1)})
test([]idl.Type{new(idl.Nat)}, []interface{}{big.NewInt(0)})
test([]idl.Type{new(idl.Nat)}, []interface{}{big.NewInt(42)})
test([]idl.Type{new(idl.Nat)}, []interface{}{big.NewInt(1234567890)})
test([]idl.Type{new(idl.Nat)}, []interface{}{func() *big.Int {
bi, _ := new(big.Int).SetString("60000000000000000", 10)
return bi
}()})
Output: enc: can not leb128 encode negative values 4449444c00017d00 4449444c00017d2a 4449444c00017dd285d8cc04 4449444c00017d808098f4e9b5ca6a
func Nat8 ¶
func Nat8() *Nat
Example ¶
test([]idl.Type{idl.Nat8()}, []interface{}{big.NewInt(0)})
test([]idl.Type{idl.Nat8()}, []interface{}{big.NewInt(42)})
test([]idl.Type{idl.Nat8()}, []interface{}{big.NewInt(255)})
test([]idl.Type{idl.Nat8()}, []interface{}{big.NewInt(256)})
Output: 4449444c00017b00 4449444c00017b2a 4449444c00017bff enc: invalid value: 256
func Nat16 ¶
func Nat16() *Nat
Example ¶
test([]idl.Type{idl.Nat16()}, []interface{}{big.NewInt(0)})
test([]idl.Type{idl.Nat16()}, []interface{}{big.NewInt(42)})
test([]idl.Type{idl.Nat16()}, []interface{}{big.NewInt(65535)})
test([]idl.Type{idl.Nat16()}, []interface{}{big.NewInt(65536)})
Output: 4449444c00017a0000 4449444c00017a2a00 4449444c00017affff enc: invalid value: 65536
func Nat32 ¶
func Nat32() *Nat
Example ¶
test([]idl.Type{idl.Nat32()}, []interface{}{big.NewInt(0)})
test([]idl.Type{idl.Nat32()}, []interface{}{big.NewInt(42)})
test([]idl.Type{idl.Nat32()}, []interface{}{big.NewInt(4294967295)})
test([]idl.Type{idl.Nat32()}, []interface{}{big.NewInt(4294967296)})
Output: 4449444c00017900000000 4449444c0001792a000000 4449444c000179ffffffff enc: invalid value: 4294967296
func Nat64 ¶
func Nat64() *Nat
Example ¶
test([]idl.Type{idl.Nat64()}, []interface{}{big.NewInt(0)})
test([]idl.Type{idl.Nat64()}, []interface{}{big.NewInt(42)})
test([]idl.Type{idl.Nat64()}, []interface{}{big.NewInt(1234567890)})
Output: 4449444c0001780000000000000000 4449444c0001782a00000000000000 4449444c000178d202964900000000
func (Nat) AddTypeDefinition ¶
func (Nat) AddTypeDefinition(_ *TypeDefinitionTable) error
func (Nat) EncodeType ¶
func (n Nat) EncodeType(_ *TypeDefinitionTable) ([]byte, error)
func (Nat) EncodeValue ¶
type Null ¶
type Null struct {
// contains filtered or unexported fields
}
Example ¶
test([]idl.Type{new(idl.Null)}, []interface{}{nil})
Output: 4449444c00017f
func (Null) AddTypeDefinition ¶
func (Null) AddTypeDefinition(_ *TypeDefinitionTable) error
func (Null) EncodeType ¶
func (Null) EncodeType(_ *TypeDefinitionTable) ([]byte, error)
func (Null) EncodeValue ¶
type Opt ¶
type Opt struct {
Type Type
}
Example ¶
test([]idl.Type{idl.NewOpt(new(idl.Nat))}, []interface{}{nil})
test([]idl.Type{idl.NewOpt(new(idl.Nat))}, []interface{}{big.NewInt(1)})
Output: 4449444c016e7d010000 4449444c016e7d01000101
func (Opt) AddTypeDefinition ¶
func (o Opt) AddTypeDefinition(tdt *TypeDefinitionTable) error
func (Opt) EncodeType ¶
func (o Opt) EncodeType(tdt *TypeDefinitionTable) ([]byte, error)
func (Opt) EncodeValue ¶
type Principal ¶
type Principal struct {
// contains filtered or unexported fields
}
Example ¶
p, _ := principal.Decode("gvbup-jyaaa-aaaah-qcdwa-cai")
test([]idl.Type{new(idl.Principal)}, []interface{}{p})
Output: 4449444c000168010a0000000000f010ec0101
func (Principal) AddTypeDefinition ¶
func (Principal) AddTypeDefinition(_ *TypeDefinitionTable) error
func (Principal) EncodeType ¶
func (t Principal) EncodeType(_ *TypeDefinitionTable) ([]byte, error)
func (Principal) EncodeValue ¶
type PrincipalMethod ¶
type Rec ¶
type Rec struct {
Fields []Field
}
Example ¶
test([]idl.Type{idl.NewRec(nil)}, []interface{}{nil})
test_([]idl.Type{idl.NewRec(map[string]idl.Type{
"foo": new(idl.Text),
"bar": new(idl.Int),
})}, []interface{}{
map[string]interface{}{
"foo": "💩",
"bar": big.NewInt(42),
"baz": big.NewInt(0),
},
})
Output: 4449444c016c000100 4449444c016c02d3e3aa027c868eb7027101002a04f09f92a9
func (Rec) AddTypeDefinition ¶
func (r Rec) AddTypeDefinition(tdt *TypeDefinitionTable) error
func (Rec) EncodeType ¶
func (r Rec) EncodeType(tdt *TypeDefinitionTable) ([]byte, error)
func (Rec) EncodeValue ¶
type Reserved ¶
type Reserved struct {
// contains filtered or unexported fields
}
func (Reserved) AddTypeDefinition ¶
func (Reserved) AddTypeDefinition(_ *TypeDefinitionTable) error
func (Reserved) EncodeType ¶
func (Reserved) EncodeType(_ *TypeDefinitionTable) ([]byte, error)
func (Reserved) EncodeValue ¶
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Example ¶
p, _ := principal.Decode("w7x7r-cok77-xa")
test(
[]idl.Type{idl.NewService(
map[string]*idl.Func{
"foo": idl.NewFunc(
[]idl.Type{new(idl.Text)},
[]idl.Type{new(idl.Nat)},
nil,
),
},
)},
[]interface{}{
p,
},
)
Output: 4449444c026a0171017d00690103666f6f0001010103caffee
func NewService ¶
func (Service) AddTypeDefinition ¶
func (s Service) AddTypeDefinition(tdt *TypeDefinitionTable) error
func (Service) EncodeType ¶
func (s Service) EncodeType(tdt *TypeDefinitionTable) ([]byte, error)
func (Service) EncodeValue ¶
type Text ¶
type Text struct {
// contains filtered or unexported fields
}
Example ¶
test([]idl.Type{new(idl.Text)}, []interface{}{""})
test([]idl.Type{new(idl.Text)}, []interface{}{"Motoko"})
test([]idl.Type{new(idl.Text)}, []interface{}{"Hi ☃\n"})
Output: 4449444c00017100 4449444c000171064d6f746f6b6f 4449444c00017107486920e298830a
func (Text) AddTypeDefinition ¶
func (Text) AddTypeDefinition(_ *TypeDefinitionTable) error
func (Text) EncodeType ¶
func (t Text) EncodeType(_ *TypeDefinitionTable) ([]byte, error)
func (Text) EncodeValue ¶
type Type ¶
type Type interface {
// AddTypeDefinition adds itself to the definition table if it is not a primitive type.
AddTypeDefinition(*TypeDefinitionTable) error
// Decodes the value from the reader.
Decode(*bytes.Reader) (interface{}, error)
// Encodes the type.
EncodeType(*TypeDefinitionTable) ([]byte, error)
// Encodes the value.
EncodeValue(v interface{}) ([]byte, error)
fmt.Stringer
}
type TypeDefinitionTable ¶
func (*TypeDefinitionTable) Add ¶
func (tdt *TypeDefinitionTable) Add(t Type, bs []byte)
type Variant ¶
type Variant struct {
Fields []Field
}
Example ¶
result := map[string]idl.Type{
"ok": new(idl.Text),
"err": new(idl.Text),
}
test_([]idl.Type{idl.NewVariant(result)}, []interface{}{idl.FieldValue{
Name: "ok",
Value: "good",
}})
test_([]idl.Type{idl.NewVariant(result)}, []interface{}{idl.FieldValue{
Name: "err",
Value: "uhoh",
}})
Output: 4449444c016b029cc20171e58eb4027101000004676f6f64 4449444c016b029cc20171e58eb402710100010475686f68
func NewVariant ¶
func (Variant) AddTypeDefinition ¶
func (v Variant) AddTypeDefinition(tdt *TypeDefinitionTable) error
func (Variant) EncodeType ¶
func (v Variant) EncodeType(tdt *TypeDefinitionTable) ([]byte, error)
func (Variant) EncodeValue ¶
type Vec ¶
type Vec struct {
Type Type
}
Example ¶
test([]idl.Type{idl.NewVec(new(idl.Int))}, []interface{}{
[]interface{}{big.NewInt(0), big.NewInt(1), big.NewInt(2), big.NewInt(3)},
})
Output: 4449444c016d7c01000400010203
func (Vec) AddTypeDefinition ¶
func (v Vec) AddTypeDefinition(tdt *TypeDefinitionTable) error
func (Vec) EncodeType ¶
func (v Vec) EncodeType(tdt *TypeDefinitionTable) ([]byte, error)
func (Vec) EncodeValue ¶
Click to show internal directories.
Click to hide internal directories.