mirror of
https://github.com/zap-proto/nim.git
synced 2026-10-30 15:04:34 +00:00
Rename the capnp/ module set to zap/ and the capnpc compiler to zapc; rename all .capnp schemas and fixtures to .zap; update every import, include guard (isInZap), generated-code emission, exception type (ZapFormatError), and the macro-generated zapUnpackStructImpl/ zapPackStructImpl identifiers to the ZAP brand. Zero capnp/Cap'n Proto references remain in source or build files; upstream MIT attribution (Sandstorm, Michał Zieliński) is preserved. Raise the nimble nim floor from the fictional 0.12.0 to the locked, verified 0.15.2 (matches nimenv.cfg/build.sh; code carries fixes through Nim 0.18). Rewrite TODO.md as honest, source-anchored known-limitations (two-word intersegment pointers, nested/named-union codegen, RPC interface inheritance) instead of a bare wishlist.
36 lines
1.3 KiB
Nim
36 lines
1.3 KiB
Nim
import examples/persondef, zap, collections, examples/calculator_schema, caprpc
|
|
|
|
let expr = Calculator_Expression(kind: Calculator_ExpressionKind.call,
|
|
function: Calculator_Function.createFromCap(nothingImplemented),
|
|
params: @[
|
|
Calculator_Expression(kind: Calculator_ExpressionKind.literal, literal: 1),
|
|
Calculator_Expression(kind: Calculator_ExpressionKind.literal, literal: 2)])
|
|
|
|
let params = Calculator_evaluate_Params(expression: expr)
|
|
|
|
let p = newPacker()
|
|
p.capToIndex = proc(c: CapServer): int = return 0
|
|
p.packPointer(0, params)
|
|
let packed = p.buffer
|
|
echo packed.encodeHex
|
|
|
|
proc makeUnpacker(buffer: string): Unpacker =
|
|
result = newUnpackerFlat(buffer)
|
|
result.getCap = proc(i: int): CapServer =
|
|
echo "unpack cap ", i
|
|
return nothingImplemented
|
|
|
|
discard makeUnpacker(packed).unpackPointer(0, type(params))
|
|
|
|
let packer1 = newPacker()
|
|
copyPointer(newUnpackerFlat(packed), 0, packer1, 0)
|
|
|
|
echo packer1.buffer.encodeHex
|
|
|
|
let params_ptr = params.toAnyPointer
|
|
let packer2 = newPacker()
|
|
packer2.buffer &= newZeroString(8)
|
|
copyPointer(newUnpackerFlat(packed), 0, packer2, 8)
|
|
|
|
assert packer2.buffer[8..^1] == packer1.buffer
|