mirror of
https://github.com/logos-storage/nim-json-rpc.git
synced 2026-02-23 23:23:13 +00:00
Add comments in wrapper generator
This commit is contained in:
parent
a6475e49b2
commit
97d19b9583
@ -46,6 +46,17 @@ proc setupConversion(reqParams, params: NimNode): NimNode =
|
||||
`reqParams`.positional.add encode(JrpcConv, `parName`).JsonString
|
||||
|
||||
proc createRpcFromSig*(clientType, rpcDecl: NimNode, alias = NimNode(nil)): NimNode =
|
||||
## This procedure will generate something like this:
|
||||
## - Currently it always send posisitional parameters to the server
|
||||
##
|
||||
## proc rpcApi(client: RpcClient; paramA: TypeA; paramB: TypeB): Future[RetType] =
|
||||
## {.gcsafe.}:
|
||||
## var reqParams = RequestParamsTx(kind: rpPositional)
|
||||
## reqParams.positional.add encode(JrpcConv, paramA).JsonString
|
||||
## reqParams.positional.add encode(JrpcConv, paramB).JsonString
|
||||
## let res = await client.call("rpcApi", reqParams)
|
||||
## result = decode(JrpcConv, res.string, typeof RetType)
|
||||
|
||||
# Each input parameter in the rpc signature is converted
|
||||
# to json using JrpcConv.encode.
|
||||
# Return types are then converted back to native Nim types.
|
||||
|
||||
@ -241,7 +241,13 @@ proc wrapServerHandler*(methName: string, params, procBody, procWrapper: NimNode
|
||||
## rpcVar.paramA = params.unpack(paramA of ParamAType)
|
||||
## rpcVar.paramB = params.unpack(paramB of ParamBType)
|
||||
## else:
|
||||
## rpcVar = params.unpack(named of RpcType)
|
||||
## # missing parameters is ok in named mode
|
||||
## # the default value will be used
|
||||
## for x in params.named:
|
||||
## case x.name
|
||||
## of "paramA": rpcVar.paramA = params.unpack(paramA of ParamAType)
|
||||
## of "paramB": rpcVar.paramB = params.unpack(paramB of ParamBType)
|
||||
## else: discard
|
||||
##
|
||||
## let res = await rpcHandler(rpcVar.paramA, rpcVar.paramB)
|
||||
## return JrpcConv.encode(res).JsonString
|
||||
@ -285,6 +291,9 @@ proc wrapServerHandler*(methName: string, params, procBody, procWrapper: NimNode
|
||||
else:
|
||||
`named`
|
||||
else:
|
||||
# even though there is no parameters expected
|
||||
# but the numbers of received params should
|
||||
# still be checked (RPC spec)
|
||||
setup.add quote do:
|
||||
if `paramsIdent`.kind == rpPositional:
|
||||
`posSetup`
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user