public static Topic parse(String topic) {
        List<Level> levels = new ArrayList<>();
        Set<String> labels = new HashSet<>();

        for (String level : topic.split("/")) {
            if (level.contains("#") || level.contains("+")) {
                throw new TopicSyntaxException(format(
                        "Wildcard levels are not allowed in MQTT topics. Found `%s` in `%s`",
                        level,
                        topic));
            } else if (level.startsWith("{") && level.endsWith("}")) {
                String label = level.substring(1, level.length() - 1);
                if (!LABEL_PATTERN.matcher(label).matches()) {
                    throw new TopicSyntaxException(format(
                            "Invalid topic label name `%s` found in `%s`",
                            label,
                            topic));
                } else if (labels.contains(label)) {
                    throw new TopicSyntaxException(format("Duplicate topic label `%s` found in `%s`", label, topic));
                }
                labels.add(label);
                levels.add(new Level(label, true));
            } else if (level.contains("{") || level.contains("}")) {
                throw new TopicSyntaxException(format(
                        "Topic labels must span an entire level. Found `%s` in `%s`",
                        level,
                        topic));
            } else {
                levels.add(new Level(level, false));
            }
        }

        return new Topic(topic, levels);
    }
Parses an MQTT topic and labels.

@param topic Topic to parse.
@return Returns the parsed topic.
@throws TopicSyntaxException if the topic is malformed.
smithy-mqtt-traits/src/main/java/software/amazon/smithy/mqtt/traits/Topic.java