Reply deferred Body parsing doesn't work with multiple elements under the root. #62
Labels
No labels
breaking-change
bug
dependencies
duplicate
enhancement
go
good first issue
help wanted
invalid
investigation
proposal
proposal-accepted
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
nemith/netconf#62
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The
<rpc-reply>element defined in RFC6241 has really two uses.message-id)So far this has been done with the
Replyobject by added aBody []bytexml:,innerxmlto capture the remaining nodes to allowed for deferred xml deoding. Even theReplystruct has a method calledDecodeused to decode theBodyinto a Go struct. This was very much modeled after jsonsjson.RawMessage` API and assumed to work similarly.This works 90% of the time as the reply message is a single element and a single element looks like document to XML. This, however, breaks when there are multiple elements.
Multiple nodes
For example the following doesn't work: Assume the netconf server replies with the message
Because
encoding/xmlexpects a document (i.e a single root element)Decodemethod onReplydoesn't DO ANYTHING and just silently fails. The fields insiderespare of the zero type and nothing happens.The RFC explicitly allows for this behavior:
https://www.rfc-editor.org/rfc/rfc6241#section-4.2 (emphasis mine):
This also comes up in a lot of
JunosRPCs that may return a<ok/>along with data elements (even though it's a bit redundant and against the RFSingle nodes as well
This also just breaks with a single element. We have defined in the library the following
If passed the same way into
reply.Decode()(orsession.Call()) the<ok/>is never parsed and is always false. This only really works if the resp structure has aXMLNodedefined or the name of the struct itself is the single xml node.Potential fixes
The easy solution is to allow the user to re-decode the entire
rpc-replymessage. Elements<rpc-error>can be omitted if the user doesn't want to parse it. This is probably the direction to go in and gives the most flexibility while fitting the original goals of this library.some sort of fancy "rewrapping" of objects to make them documents to allow for parsing (i.e adding a fake root node) to the input data and the parsing data to appease the decoder. This is probably doable but also needs a lot of testing around corner cases to work properly and is a bit too "weird"
Nothing. We return the bytes up to the caller to handle parsing (i.e parsing multiple "documents"). This seems the least useful and more hostile to the users of the library..
Either way I am glad I ran into this issue now as it will be a breaking API change to solve it.