diff --git a/driver/netconf/message.go b/driver/netconf/message.go index 323ef70..102c9fc 100644 --- a/driver/netconf/message.go +++ b/driver/netconf/message.go @@ -12,21 +12,25 @@ type message struct { Payload interface{} `xml:",innerxml"` } -func (m *message) serialize(v string) ([]byte, error) { - message, err := xml.Marshal(m) +func (m *message) serialize(v string, forceSelfClosingTags bool) ([]byte, error) { + msg, err := xml.Marshal(m) if err != nil { return nil, err } - message = append([]byte(xmlHeader), message...) + msg = append([]byte(xmlHeader), msg...) + + if forceSelfClosingTags { + msg = ForceSelfClosingTags(msg) + } switch v { case V1Dot0: - message = append(message, []byte(v1Dot0Delim)...) + msg = append(msg, []byte(v1Dot0Delim)...) case V1Dot1: - message = append([]byte(fmt.Sprintf("#%d\n", len(message))), message...) - message = append(message, []byte("\n##")...) + msg = append([]byte(fmt.Sprintf("#%d\n", len(msg))), msg...) + msg = append(msg, []byte("\n##")...) } - return message, nil + return msg, nil } diff --git a/driver/netconf/rpc.go b/driver/netconf/rpc.go index 0cf0e0d..ee0d257 100644 --- a/driver/netconf/rpc.go +++ b/driver/netconf/rpc.go @@ -43,15 +43,13 @@ func (d *Driver) sendRPC( m *message, op *OperationOptions, ) (*response.NetconfResponse, error) { - b, err := m.serialize(d.SelectedVersion) - if err != nil { - return nil, err - } - if d.ForceSelfClosingTags { d.Logger.Debug("ForceSelfClosingTags is true, enforcing...") + } - b = ForceSelfClosingTags(b) + b, err := m.serialize(d.SelectedVersion, d.ForceSelfClosingTags) + if err != nil { + return nil, err } d.Logger.Debugf("sending finalized rpc payload:\n%s", string(b))