Class BerMutations

java.lang.Object
org.snmp4j.mcp.tool.snmp.ber.BerMutations

public final class BerMutations extends Object
Applies declarative mutations and computes permutations over a BER node tree (the plain Map/List form parsed from the snmp_message_ber JSON).

Mutations and permutation dimensions address nodes with a small subset of JSON Pointer (RFC 6901): "" is the root, "/children/1/children/0" descends into arrays and object members. Supported operations set the encoder's per-node fields (see BerJsonEncoder): setTag, setValue, setValueHex, overrideLength, lengthForm, truncate, omit, appendHex, setRawHex, and flipBit (flip one bit of the addressed leaf's current content).

Since:
0.1.0
  • Method Details

    • applyMutations

      public static void applyMutations(Object root, List<?> mutations)
      Applies a list of mutation operations in order, in place, to root.
      Parameters:
      root - the node tree
      mutations - a list of maps, each {"path":..,"op":..,"value":..}
    • applyOp

      public static void applyOp(Object nodeObj, String op, Object value)
      Applies a single operation to a target node.
      Parameters:
      nodeObj - the target node (must be a JSON object)
      op - the operation name
      value - the operation argument (may be null)
    • expand

      public static BerMutations.Expansion expand(Object base, Map<String,Object> spec, int limit)
      Expands a permutation spec into a set of mutated node trees.
      Parameters:
      base - the template node tree (already mutated, if applicable)
      spec - the permutation spec: {"mode":"cartesian|zip","limit":N,"dimensions":[...]}
      limit - the maximum number of trees to produce
      Returns:
      the expansion result
    • resolveNode

      public static Object resolveNode(Object root, String pointer)
      Resolves a JSON Pointer against the tree and returns the addressed node.
      Parameters:
      root - the tree
      pointer - an RFC 6901 pointer ("" for root)
      Returns:
      the addressed object
      Throws:
      IllegalArgumentException - if the pointer does not resolve
    • deepCopy

      public static Object deepCopy(Object node)
      Deep-copies a Map/List/primitive tree so mutations don't touch the template.
      Parameters:
      node - the node to deep-copy
      Returns:
      the deep-copy of the node