diff --git a/ffi/serial.nim b/ffi/serial.nim index d0f3cf8..28ff240 100644 --- a/ffi/serial.nim +++ b/ffi/serial.nim @@ -2,6 +2,17 @@ import std/[json, macros, options] import results import ./codegen/meta +## RawString passes the C string through as-is, with no JSON encoding/decoding. +## Use this when the C caller provides a value that should not be treated as a +## JSON-encoded string (e.g. a raw config JSON blob, a multiaddress, an ENR). +type RawString* = distinct string + +proc ffiSerialize*(x: RawString): string = + string(x) + +proc ffiDeserialize*(s: cstring, _: typedesc[RawString]): Result[RawString, string] = + ok(RawString($s)) + proc ffiSerialize*(x: string): string = $(%*x)