Make the 'single record inlining' behavior optional

This commit is contained in:
Zahary Karadjov 2019-10-23 13:01:53 +03:00
parent 517adbbbca
commit 52b5ca9c9c
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609
1 changed files with 7 additions and 4 deletions

View File

@ -60,6 +60,7 @@ type
version*: int version*: int
timeouts*: int64 timeouts*: int64
useRequestIds*: bool useRequestIds*: bool
useSingeRecordInlining*: bool
rlpxName*: string rlpxName*: string
outgoingRequestDecorator*: NimNode outgoingRequestDecorator*: NimNode
incomingRequestDecorator*: NimNode incomingRequestDecorator*: NimNode
@ -371,7 +372,7 @@ proc newMsg(protocol: P2PProtocol, kind: MessageKind, id: int,
chooseFieldType(paramType), # some types such as openarray chooseFieldType(paramType), # some types such as openarray
newEmptyNode()) # are automatically remapped newEmptyNode()) # are automatically remapped
if recFields.len == 1: if recFields.len == 1 and protocol.useSingeRecordInlining:
# When we have a single parameter, it's treated as the transferred message # When we have a single parameter, it's treated as the transferred message
# type. `recName` will be resolved to the message type that's intended # type. `recName` will be resolved to the message type that's intended
# for serialization while `strongRecName` will be a distinct type over # for serialization while `strongRecName` will be a distinct type over
@ -536,6 +537,8 @@ proc writeParamsAsRecord*(params: openarray[NimNode],
writer, recordWriterCtx, writer, recordWriterCtx,
newLit($param), param) newLit($param), param)
# TODO: this doesn't respect the `useSingeRecordInlining` option.
# Right now, it's not a problem because it's used only in the libp2p back-end
if params.len > 1: if params.len > 1:
result = quote do: result = quote do:
mixin init, writerType, beginRecord, endRecord mixin init, writerType, beginRecord, endRecord
@ -638,11 +641,11 @@ proc genAwaitUserHandler*(msg: Message, receivedMsg: NimNode,
var userHandlerCall = newCall(msg.userHandler.name, leadingParams) var userHandlerCall = newCall(msg.userHandler.name, leadingParams)
var params = toSeq(msg.procDef.typedParams(skip = 1)) var params = toSeq(msg.procDef.typedParams(skip = 1))
if params.len > 1: if params.len == 1 and msg.protocol.useSingeRecordInlining:
userHandlerCall.add receivedMsg
else:
for p in params: for p in params:
userHandlerCall.add newDotExpr(receivedMsg, p[0]) userHandlerCall.add newDotExpr(receivedMsg, p[0])
else:
userHandlerCall.add receivedMsg
return newCall("await", userHandlerCall) return newCall("await", userHandlerCall)