mirror of
https://github.com/logos-messaging/nim-ffi.git
synced 2026-05-11 20:59:32 +00:00
add RawString type in serial
This commit is contained in:
parent
ed099ba314
commit
233d6d726b
@ -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)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user