From 233d6d726baa0b2d9c7c2694c76521dfefa57a46 Mon Sep 17 00:00:00 2001 From: Ivan FB Date: Tue, 5 May 2026 15:14:28 +0200 Subject: [PATCH] add RawString type in serial --- ffi/serial.nim | 11 +++++++++++ 1 file changed, 11 insertions(+) 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)