From 52b5ca9c9c9bf40705d51f6edb81d0521a8bb63f Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Wed, 23 Oct 2019 13:01:53 +0300 Subject: [PATCH] Make the 'single record inlining' behavior optional --- eth/p2p/p2p_protocol_dsl.nim | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/eth/p2p/p2p_protocol_dsl.nim b/eth/p2p/p2p_protocol_dsl.nim index 195fc6a..f1199ed 100644 --- a/eth/p2p/p2p_protocol_dsl.nim +++ b/eth/p2p/p2p_protocol_dsl.nim @@ -60,6 +60,7 @@ type version*: int timeouts*: int64 useRequestIds*: bool + useSingeRecordInlining*: bool rlpxName*: string outgoingRequestDecorator*: NimNode incomingRequestDecorator*: NimNode @@ -371,7 +372,7 @@ proc newMsg(protocol: P2PProtocol, kind: MessageKind, id: int, chooseFieldType(paramType), # some types such as openarray 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 # type. `recName` will be resolved to the message type that's intended # for serialization while `strongRecName` will be a distinct type over @@ -536,6 +537,8 @@ proc writeParamsAsRecord*(params: openarray[NimNode], writer, recordWriterCtx, 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: result = quote do: mixin init, writerType, beginRecord, endRecord @@ -638,11 +641,11 @@ proc genAwaitUserHandler*(msg: Message, receivedMsg: NimNode, var userHandlerCall = newCall(msg.userHandler.name, leadingParams) 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: userHandlerCall.add newDotExpr(receivedMsg, p[0]) - else: - userHandlerCall.add receivedMsg return newCall("await", userHandlerCall)