Uploaded image for project: 'yangtools'
  1. yangtools
  2. YANGTOOLS-1392

Reformulate ImmutableNodes.fromInstanceId() in terms of NormalizedNodeStreamWriter

XMLWordPrintable

    • Icon: New Feature New Feature
    • Resolution: Done
    • Icon: Medium Medium
    • 8.0.0
    • None
    • data-api, data-impl
    • None

      We have a way to construct a NormalizedNode hierarchy, which is sadly tied to a particular implementation. There are a few use cases, where we really mean to push the state of a YangInstanceIdentifier into a NormalizedNodeStreamWriter and then emit a number of NormalizedNodes and close the identifier.

      Refactoring this utility method would allow users side-step the NormalizedNode representation and ditch quite a bit of complexity – with the following construct:

      YangInstanceIdentifier id = ...;
      NormalizedNodeStreamWriter writer = ...;
      
      try (var nnWriter = NormalizedNodeWriter.forStreamWriter(writer)) {
        try (var idCtx = nnWriter.enterPath(id)) {
           // here we have emitted the events to 'enter' structure indicated by the id
           // and can proceed to, for example
           nnWriter.writeNormalizedNode(...);
         }
         // here we are again outside of the id, having rolled back the changes
      }
      

            tcere Tomas Cere
            rovarga Robert Varga
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: