Skip to content

Commit a990b1c

Browse files
deftioclaude
andcommitted
README: add per-language install and usage examples for all 10 bindings
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7249dc9 commit a990b1c

1 file changed

Lines changed: 130 additions & 39 deletions

File tree

README.md

Lines changed: 130 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -39,58 +39,164 @@ All bindings are native implementations that read/write the `.trp` binary format
3939

4040
## Quick Start
4141

42+
### C / C++
43+
4244
```bash
43-
# Build
44-
cmake -B build -DBUILD_TESTS=ON
45+
# Install
46+
git clone https://github.com/deftio/triepack.git
47+
cd triepack
48+
cmake -B build -DBUILD_TESTS=ON -DBUILD_JSON=ON
4549
cmake --build build
46-
47-
# Run tests
4850
ctest --test-dir build --output-on-failure
4951
```
5052

51-
### C API
52-
5353
```c
5454
#include "triepack/triepack.h"
55-
#include <stdio.h>
56-
#include <stdlib.h>
5755

58-
/* Encode */
5956
tp_encoder *enc = NULL;
6057
tp_encoder_create(&enc);
61-
6258
tp_value v = tp_value_int(42);
6359
tp_encoder_add(enc, "hello", &v);
64-
65-
v = tp_value_string("foo");
66-
tp_encoder_add(enc, "world", &v);
67-
68-
uint8_t *buf = NULL;
69-
size_t len = 0;
60+
uint8_t *buf = NULL; size_t len = 0;
7061
tp_encoder_build(enc, &buf, &len);
7162

72-
/* Decode */
7363
tp_dict *dict = NULL;
7464
tp_dict_open(&dict, buf, len);
75-
7665
tp_value val;
7766
if (tp_dict_lookup(dict, "hello", &val) == TP_OK)
7867
printf("hello -> %lld\n", (long long)val.data.int_val);
79-
8068
tp_dict_close(&dict);
8169
tp_encoder_destroy(&enc);
8270
free(buf);
8371
```
8472
85-
### C++ API
73+
### Python
74+
75+
```bash
76+
# Install (from source, PyPI package coming soon)
77+
cd bindings/python
78+
pip install -e .
79+
```
80+
81+
```python
82+
from triepack import encode, decode
83+
84+
buf = encode({"hello": 42, "world": "foo"})
85+
result = decode(buf)
86+
print(result) # {'hello': 42, 'world': 'foo'}
87+
```
88+
89+
### JavaScript
90+
91+
```bash
92+
# Install (from source, npm package coming soon)
93+
cd bindings/javascript
94+
npm install
95+
```
96+
97+
```js
98+
const { encode, decode } = require('./src/index');
99+
100+
const buf = encode({ hello: 42, world: 'foo' });
101+
const result = decode(buf);
102+
console.log(result); // { hello: 42, world: 'foo' }
103+
```
104+
105+
### TypeScript
106+
107+
```bash
108+
cd bindings/typescript
109+
npm install
110+
```
111+
112+
```ts
113+
import { encode, decode } from './src/index';
114+
115+
const buf = encode({ hello: 42, world: 'foo' });
116+
const result = decode(buf);
117+
```
118+
119+
### Go
86120

87-
```cpp
88-
#include <triepack/triepack.hpp>
121+
```bash
122+
# Copy bindings/go/ into your project
123+
cp -r bindings/go/triepack your_project/
124+
```
89125

90-
triepack::Encoder enc;
91-
// ... add entries, build, lookup via triepack::Dict
126+
```go
127+
data := map[string]interface{}{"hello": 42, "world": "foo"}
128+
buf, _ := triepack.Encode(data)
129+
result, _ := triepack.Decode(buf)
92130
```
93131

132+
### Rust
133+
134+
```bash
135+
# Add to Cargo.toml (from source, crates.io coming soon)
136+
# [dependencies]
137+
# triepack = { path = "bindings/rust" }
138+
```
139+
140+
```rust
141+
use triepack::{encode, decode, Value};
142+
use std::collections::HashMap;
143+
144+
let mut data = HashMap::new();
145+
data.insert("hello".into(), Value::UInt(42));
146+
let buf = encode(&data).unwrap();
147+
let result = decode(&buf).unwrap();
148+
```
149+
150+
### Swift
151+
152+
```bash
153+
# Add to Package.swift dependencies
154+
# .package(path: "bindings/swift")
155+
```
156+
157+
```swift
158+
import Triepack
159+
160+
let data: [String: TriepackValue] = ["hello": .uint(42)]
161+
let buf = try Triepack.encode(data)
162+
let result = try Triepack.decode(buf)
163+
```
164+
165+
### Kotlin
166+
167+
```bash
168+
# Add bindings/kotlin/ to your Gradle project
169+
cd bindings/kotlin
170+
./gradlew test
171+
```
172+
173+
```kotlin
174+
import com.deftio.triepack.*
175+
176+
val data = mapOf("hello" to TpValue.UInt(42))
177+
val buf = encode(data)
178+
val result = decode(buf)
179+
```
180+
181+
### Java
182+
183+
```bash
184+
# Add bindings/java/ to your Gradle project
185+
cd bindings/java
186+
./gradlew test
187+
```
188+
189+
```java
190+
import com.deftio.triepack.*;
191+
192+
Map<String, TpValue> data = new LinkedHashMap<>();
193+
data.put("hello", TpValue.ofUInt(42));
194+
byte[] buf = TriePack.encode(data);
195+
Map<String, TpValue> result = TriePack.decode(buf);
196+
```
197+
198+
See [Examples](docs/guide/examples.md) for more detailed usage including JSON round-trips, file I/O, and cross-language interop.
199+
94200
## Library Stack
95201

96202
```
@@ -113,21 +219,6 @@ Each layer can be used independently. `triepack_wrapper` provides C++11 RAII wra
113219
| `BUILD_DOCS` | OFF | Build Doxygen documentation |
114220
| `ENABLE_COVERAGE` | OFF | Enable code coverage instrumentation |
115221

116-
## Language Bindings
117-
118-
All bindings are native implementations that read/write the `.trp` format directly (no FFI).
119-
120-
| Language | Status | Directory |
121-
|----------|--------|-----------|
122-
| Python | Implemented | `bindings/python/` |
123-
| JavaScript | Implemented | `bindings/javascript/` |
124-
| TypeScript | Implemented (wraps JS) | `bindings/typescript/` |
125-
| Go | Implemented | `bindings/go/` |
126-
| Swift | Implemented | `bindings/swift/` |
127-
| Rust | Implemented | `bindings/rust/` |
128-
| Kotlin | Implemented | `bindings/kotlin/` |
129-
| Java | Implemented | `bindings/java/` |
130-
131222
## File Format
132223

133224
- Magic bytes: `TRP\0` (`0x54 0x52 0x50 0x00`)

0 commit comments

Comments
 (0)