public void deserialize(final InputStream inputStream) throws IOException {
    byte type = ReadWriteIOUtils.readByte(inputStream);

    String name;
    int childNum;
    final Stack<Pair<IConfigMNode, Boolean>> stack = new Stack<>();
    IConfigMNode databaseMNode;
    IConfigMNode internalMNode;
    IConfigMNode tableNode;

    if (type == STORAGE_GROUP_MNODE_TYPE) {
      databaseMNode = deserializeDatabaseMNode(inputStream);
      name = databaseMNode.getName();
      stack.push(new Pair<>(databaseMNode, true));
    } else if (type == TABLE_MNODE_TYPE) {
      tableNode = deserializeTableMNode(inputStream);
      name = tableNode.getName();
      stack.push(new Pair<>(tableNode, false));
    } else {
      // Currently internal mNode will not be the leaf node and thus will not be deserialized here
      // This is just in case
      internalMNode = deserializeInternalMNode(inputStream);
      ReadWriteIOUtils.readInt(inputStream);
      name = internalMNode.getName();
      stack.push(new Pair<>(internalMNode, false));
    }

    while (!PATH_ROOT.equals(name)) {
      type = ReadWriteIOUtils.readByte(inputStream);
      switch (type) {
        case INTERNAL_MNODE_TYPE:
          internalMNode = deserializeInternalMNode(inputStream);
          childNum = ReadWriteIOUtils.readInt(inputStream);
          boolean hasDB = false;
          while (childNum > 0) {
            hasDB = stack.peek().right;
            internalMNode.addChild(stack.pop().left);
            childNum--;
          }
          stack.push(new Pair<>(internalMNode, hasDB));
          name = internalMNode.getName();
          break;
        case STORAGE_GROUP_MNODE_TYPE:
          databaseMNode = deserializeDatabaseMNode(inputStream).getAsMNode();
          while (!stack.isEmpty() && Boolean.FALSE.equals(stack.peek().right)) {
            databaseMNode.addChild(stack.pop().left);
          }
          stack.push(new Pair<>(databaseMNode, true));
          name = databaseMNode.getName();
          break;
        case TABLE_MNODE_TYPE:
          tableNode = deserializeTableMNode(inputStream).getAsMNode();
          stack.push(new Pair<>(tableNode, false));
          name = tableNode.getName();
          break;
        default:
          logger.error("Unrecognized node type {} when recovering the mTree.", type);
          return;
      }
    }
    this.root = stack.peek().left;
  }
This method returns the templateId set on paths if the path set matches or is a prefix of input
path pattern.
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/schema/ConfigMTree.java