Quick Start
Choose an SDK for your language and follow the steps below.
Rust
Add to Cargo.toml:
[dependencies]
twilic = { git = "https://github.com/twilic/twilic-rust.git" }Encode and decode a value:
use twilic::{decode, encode, Value};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let value = Value::Map(vec![
("id".to_string(), Value::U64(1001)),
("name".to_string(), Value::String("alice".to_string())),
("score".to_string(), Value::F64(98.6)),
]);
let bytes = encode(&value)?;
let decoded = decode(&bytes)?;
assert_eq!(value, decoded);
Ok(())
}Go
Install:
go get github.com/twilic/twilic-goEncode and decode a value:
package main
import (
"fmt"
twilic "github.com/twilic/twilic-go"
)
func main() {
value := twilic.NewMap(
twilic.Entry("id", twilic.NewU64(1001)),
twilic.Entry("name", twilic.NewString("alice")),
twilic.Entry("score", twilic.NewF64(98.6)),
)
bytes, err := twilic.Encode(value)
if err != nil {
panic(err)
}
decoded, err := twilic.Decode(bytes)
if err != nil {
panic(err)
}
fmt.Println(decoded)
}Python
Install:
pip install twilicOr with uv:
uv add twilicEncode and decode a value:
import twilic
value = twilic.new_map(
twilic.entry("id", twilic.new_u64(1001)),
twilic.entry("name", twilic.new_string("alice")),
twilic.entry("score", twilic.new_f64(98.6)),
)
data = twilic.encode(value)
decoded = twilic.decode(data)
assert decoded == valueJavaScript / TypeScript
Install:
npm install @twilic/core
# or
pnpm add @twilic/coreEncode and decode a value:
import { init, encode, decode } from "@twilic/core";
await init();
const value = {
id: 1001n,
name: "alice",
score: 98.6,
};
const bytes = encode(value);
const decoded = decode(bytes);Java
Add to your build file (Maven/Gradle) or install from the local path:
import io.twilic.Twilic;
import io.twilic.Value;
public class Main {
public static void main(String[] args) throws Exception {
Value value = Value.map(
Value.entry("id", Value.u64(1001)),
Value.entry("name", Value.string("alice")),
Value.entry("score", Value.f64(98.6))
);
byte[] bytes = Twilic.encode(value);
Value decoded = Twilic.decode(bytes);
}
}Scala
Add to build.sbt:
libraryDependencies += "io.twilic" %% "twilic" % "3.0.0"import io.twilic.Twilic
import io.twilic.internal.core.*
val value = Twilic.newMap(
Twilic.entry("id", Twilic.newU64(1001)),
Twilic.entry("name", Twilic.newString("alice")),
)
val bytes = Twilic.encode(value)
val decoded = Twilic.decode(bytes)Ruby
Install:
gem install twilicEncode and decode a value:
require "twilic"
value = Twilic.new_map(
Twilic.entry("id", Twilic.new_u64(1001)),
Twilic.entry("name", Twilic.new_string("alice")),
Twilic.entry("score", Twilic.new_f64(98.6))
)
data = Twilic.encode(value)
decoded = Twilic.decode(data)R
Install from source:
git clone https://github.com/twilic/twilic-r.git
cd twilic-r && R CMD INSTALL .library(twilic)
value <- new_map(
entry("id", new_u64(1001)),
entry("name", new_string("alice"))
)
bytes <- encode(value)
decoded <- decode(bytes)Zig
Add to your build.zig.zon and import:
const std = @import("std");
const twilic = @import("twilic");
pub fn main() !void {
const allocator = std.heap.page_allocator;
var entries = try allocator.alloc(twilic.model.ValueMapEntry, 2);
entries[0] = .{ .key = "id", .value = .{ .U64 = 1001 } };
entries[1] = .{ .key = "name", .value = .{ .String = "alice" } };
const value = twilic.model.Value{ .Map = entries };
const bytes = try twilic.encode(allocator, value);
const decoded = try twilic.decode(allocator, bytes);
_ = decoded;
}PHP
Install with Composer (from GitHub until Packagist):
composer require twilic/twilic:@dev<?php
require 'vendor/autoload.php';
use function Twilic\{decode, encode, entry, new_map, new_string, new_u64};
$value = new_map(
entry('id', new_u64(1001)),
entry('name', new_string('alice')),
);
$data = encode($value);
$decoded = decode($data);Kotlin
Add from GitHub (Maven Central when published):
dependencies {
implementation("io.twilic:twilic:3.0.0")
}import io.twilic.Twilic
import io.twilic.internal.core.MapEntry
val value = Twilic.newMap(
MapEntry("id", Twilic.newU64(1001)),
MapEntry("name", Twilic.newString("alice")),
)
val encoded = Twilic.encode(value)
val decoded = Twilic.decode(encoded)Dart
Add to pubspec.yaml:
dependencies:
twilic:
git:
url: https://github.com/twilic/twilic-dart.gitimport 'package:twilic/twilic.dart';
final value = newMap([
entry('id', newU64(1001)),
entry('name', newString('alice')),
]);
final bytes = encode(value);
final decoded = decode(bytes);Elixir
Add to mix.exs:
{:twilic, git: "https://github.com/twilic/twilic-elixir.git"}value =
Twilic.new_map([
Twilic.entry("id", Twilic.new_u64(1001)),
Twilic.entry("name", Twilic.new_string("alice")),
])
encoded = Twilic.encode(value)
decoded = Twilic.decode(encoded)Lua
Install via LuaRocks or set LUA_PATH to the source tree:
git clone https://github.com/twilic/twilic-lua.git
cd twilic-lua
export LUA_PATH="$(pwd)/src/?.lua;$(pwd)/src/?/init.lua;;"local twilic = require("twilic")
local value = twilic.map({
id = twilic.u64(1001),
name = twilic.string("alice"),
})
local bytes = twilic.encode(value)
local decoded = twilic.decode(bytes)C
Build from source:
git clone https://github.com/twilic/twilic-c.git
cd twilic-c && cmake -B build && cmake --build build#include "twilic/twilic.h"
twilic_map_entry_t entries[] = {
twilic_entry("id", twilic_u64(1001)),
twilic_entry("name", twilic_string("alice")),
};
twilic_value_t value = twilic_map(entries, 2);
twilic_buffer_t encoded = {0};
twilic_error_t err = {0};
twilic_encode(&value, &encoded, &err);C++
Build from source:
git clone https://github.com/twilic/twilic-cpp.git
cd twilic-cpp && cmake -B build && cmake --build build#include "twilic/twilic.hpp"
auto value = twilic::new_map({
twilic::entry("id", twilic::new_u64(1001)),
twilic::entry("name", twilic::new_string("alice")),
});
auto bytes = twilic::encode(value);
auto decoded = twilic::decode(bytes);C Sharp
Clone and build:
git clone https://github.com/twilic/twilic-csharp.git
cd twilic-csharp && dotnet buildusing Twilic;
var value = Twilic.NewMap(
Twilic.Entry("id", Twilic.NewU64(1001)),
Twilic.Entry("name", Twilic.NewString("alice")));
byte[] bytes = Twilic.Encode(value);
var decoded = Twilic.Decode(bytes);Swift
Add to Package.swift:
.package(url: "https://github.com/twilic/twilic-swift.git", from: "0.1.0"),import Twilic
let value = newMap([
entry("id", newU64(1001)),
entry("name", newString("alice")),
])
let data = try encode(value)
let decoded = try decode(data)See the SDK overview for requirements, packages, and interoperability notes for all eighteen languages.