https://github.com/diodechain/candid
Elixir library for encoding and decoding candid. The binary encoding format for the Internet Computer (ICP).
https://github.com/diodechain/candid
Last synced: 11 days ago
JSON representation
Elixir library for encoding and decoding candid. The binary encoding format for the Internet Computer (ICP).
- Host: GitHub
- URL: https://github.com/diodechain/candid
- Owner: diodechain
- License: apache-2.0
- Created: 2024-10-16T18:08:23.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-01-22T13:37:45.000Z (10 months ago)
- Last Synced: 2025-04-10T23:04:56.495Z (7 months ago)
- Language: Elixir
- Size: 18.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-internet-computer - candid - Elixir library for encoding/decoding Candid. (Candid / Candid implementations)
README
# Candid
Candid is a binary encoding format for the Internet Computer (ICP).
This library allows to encode and decode Candid messages.
## Installation
This package can be installed
by adding `candid` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:candid, "~> 1.0.0"}
]
end
```
## Usage
```elixir
type_spec = [{:vec, {:record, [{0, :blob}, {1, :blob}]}}]
messages = [
{"key1", "hello world"},
{"key2," "hello candid"}
]
^messages = Candid.encode_parameters(type_spec, messages)
|> Candid.decode_parameters()
```
## Support types and shorthands:
For convenience there are type shorthands for :variant, and :record
- Record: `%{name => type_value}` e.g. %{a: :text}
- Variant: `[type]` e.g. `[{:ok, :text}, :error]`
Other complex types have to be defined as tuples:
- Opt: `{:opt, type}` e.g. `{:opt, :nat}`
- Vec: `{:vec, type}` e.g. `{:vec, :nat}`
And simple types are just atoms:
- `:null`
- `:bool`
- `:nat` (`:nat8`, `:nat16`, `:nat32`, `:nat64`)
- `:int` (`:int8`, `:int16`, `:int32`, `:int64`)
- `:float32`, `:float64`
- `:text`
- `:principal`
- `:blob`
- `:empty`
## Completion
This library does not yet support loading of .did file specifications. PRs and contributions to extend this library are welcome though!
## Documentation
The documentation for this library can be found at [https://hexdocs.pm/candid](https://hexdocs.pm/candid).