{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Wirdigen Protocol Description",
  "description": "A Wirdigen Protocol Description: one protocol's identity, its Registration and the layout of its payload.",
  "type": "object",
  "properties": {
    "name": {
      "description": "Filter name of the protocol, such as `dns`: lowercase letters, digits, `_` and `-`, starting with a letter, 2 to 32 characters. Its uppercase is the short name shown in the Protocol column.",
      "type": "string",
      "minLength": 2,
      "maxLength": 32,
      "pattern": "^[a-z][a-z0-9_-]+$"
    },
    "title": {
      "description": "Full name of the protocol at the tree root; defaults to the short name. One line.",
      "type": "string",
      "minLength": 1
    },
    "registration": {
      "description": "The ports the Dissector claims by default. Leaving it out means Decode As only; every Dissector is offered in Decode As on UDP and TCP ports.",
      "allOf": [
        {
          "$ref": "#/definitions/Registration"
        }
      ]
    },
    "framing": {
      "description": "How each Message is found in a TCP stream.",
      "allOf": [
        {
          "$ref": "#/definitions/Framing"
        }
      ]
    },
    "endian": {
      "description": "Default byte order of the protocol.",
      "allOf": [
        {
          "$ref": "#/definitions/ByteOrder"
        }
      ]
    },
    "info": {
      "description": "Info column template, such as `\"{msg_type} id={id}\"`: Field Paths in braces, `{{` and `}}` for literal braces. Without it, the Info column shows the outermost `switch` Field's case.",
      "type": "string"
    },
    "fields": {
      "description": "The top-level layout: the Fields of a Message, read one after another.",
      "type": "array",
      "items": {
        "$ref": "#/definitions/Entry"
      },
      "minItems": 1
    },
    "types": {
      "description": "Named, reusable groups of Fields, by Type name (`[A-Z][A-Za-z0-9]*`).",
      "type": "object",
      "additionalProperties": {
        "$ref": "#/definitions/Type"
      },
      "propertyNames": {
        "pattern": "^[A-Z][A-Za-z0-9]*$"
      }
    },
    "enums": {
      "description": "Named tables of labels for integer values, by Enum name (`[A-Z][A-Za-z0-9]*`), used as `values: <EnumName>`.",
      "type": "object",
      "additionalProperties": {
        "$ref": "#/definitions/Table"
      },
      "propertyNames": {
        "pattern": "^[A-Z][A-Za-z0-9]*$"
      }
    },
    "allow": {
      "description": "Names of warnings to silence in this description. Errors cannot be silenced.",
      "type": "array",
      "items": {
        "anyOf": [
          {
            "enum": [
              "unreachable-value",
              "unreachable-field",
              "unreachable-expect",
              "unused-enum",
              "unused-type",
              "unknown-allow",
              "tcp-without-framing",
              "protocol-name-taken"
            ]
          },
          {
            "type": "string"
          }
        ]
      }
    }
  },
  "additionalProperties": false,
  "required": [
    "name",
    "fields"
  ],
  "definitions": {
    "Registration": {
      "description": "The ports a Dissector claims by default.",
      "type": "object",
      "properties": {
        "ports": {
          "description": "Ports per transport, each a number or a `\"low-high\"` range string.",
          "allOf": [
            {
              "$ref": "#/definitions/Ports"
            }
          ]
        }
      },
      "additionalProperties": false
    },
    "Ports": {
      "description": "Ports per transport.",
      "type": "object",
      "properties": {
        "udp": {
          "description": "UDP ports, such as `[5000, \"6000-6010\"]`.",
          "type": "array",
          "items": {
            "anyOf": [
              {
                "type": "integer",
                "minimum": 1,
                "maximum": 65535
              },
              {
                "type": "string",
                "pattern": "^\\s*(0x[0-9a-fA-F]+|0o[0-7]+|[-+]?[0-9]+)\\s*-\\s*(0x[0-9a-fA-F]+|0o[0-7]+|[-+]?[0-9]+)\\s*$"
              }
            ]
          },
          "minItems": 1
        },
        "tcp": {
          "description": "TCP ports, such as `[5000]`. TCP without `framing:` dissects each segment as one Message.",
          "type": "array",
          "items": {
            "anyOf": [
              {
                "type": "integer",
                "minimum": 1,
                "maximum": 65535
              },
              {
                "type": "string",
                "pattern": "^\\s*(0x[0-9a-fA-F]+|0o[0-7]+|[-+]?[0-9]+)\\s*-\\s*(0x[0-9a-fA-F]+|0o[0-7]+|[-+]?[0-9]+)\\s*$"
              }
            ]
          },
          "minItems": 1
        }
      },
      "additionalProperties": false
    },
    "Framing": {
      "description": "How each Message is found in a TCP stream: a header of constant size, and the whole Message's length computed from it.",
      "type": "object",
      "properties": {
        "header": {
          "description": "The number of bytes `length` is computed from, at least 1.",
          "type": "integer",
          "minimum": 1
        },
        "length": {
          "description": "The whole Message's length, header included: a constant, or an Expression over top-level Fields, and their sub-Fields, within the first `header` bytes. `_offset` and `_remaining` are not allowed.",
          "type": [
            "integer",
            "string"
          ]
        }
      },
      "additionalProperties": false,
      "required": [
        "header",
        "length"
      ]
    },
    "ByteOrder": {
      "description": "A byte order: most significant byte first (`big`) or last (`little`).",
      "type": "string",
      "enum": [
        "big",
        "little"
      ]
    },
    "Entry": {
      "description": "One entry of a structure: a Field, or unnamed Padding.",
      "anyOf": [
        {
          "$ref": "#/definitions/Field"
        },
        {
          "$ref": "#/definitions/Padding"
        }
      ]
    },
    "Field": {
      "description": "A Field: exactly one of `type`, `fields` or `switch` says what it is.",
      "type": "object",
      "properties": {
        "name": {
          "description": "The Field's name: lowercase letters, digits and `_`, starting with a letter. It is part of its filter name and of the Field Paths of Expressions.",
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]*$"
        },
        "type": {
          "description": "A built-in type, or the name of a Type.",
          "anyOf": [
            {
              "enum": [
                "uint8",
                "uint16",
                "uint24",
                "uint32",
                "uint40",
                "uint48",
                "uint56",
                "uint64",
                "int8",
                "int16",
                "int24",
                "int32",
                "int40",
                "int48",
                "int56",
                "int64",
                "bool",
                "float32",
                "float64",
                "string",
                "bytes",
                "ipv4",
                "ipv6",
                "ether",
                "eui64",
                "guid",
                "abs_time",
                "rel_time"
              ]
            },
            {
              "type": "string",
              "pattern": "^[A-Z][A-Za-z0-9]*$"
            }
          ]
        },
        "fields": {
          "description": "An inline structure: the Fields of this Field, read one after another.",
          "type": "array",
          "items": {
            "$ref": "#/definitions/Entry"
          },
          "minItems": 1
        },
        "switch": {
          "description": "The Subject of a switch: an Expression whose value picks one of `cases`.",
          "type": [
            "integer",
            "string"
          ]
        },
        "cases": {
          "description": "The Cases of a `switch`, by value or `\"low-high\"` range: each a Type name or inline Fields.",
          "type": "object",
          "additionalProperties": {
            "$ref": "#/definitions/Case"
          }
        },
        "default": {
          "description": "The Case of a `switch` when no other matches.",
          "allOf": [
            {
              "$ref": "#/definitions/Case"
            }
          ]
        },
        "bits": {
          "description": "The sub-Fields of a fixed-size unsigned integer, most significant bit first; widths add up to the integer's size.",
          "type": "array",
          "items": {
            "$ref": "#/definitions/Bit"
          },
          "minItems": 1
        },
        "count": {
          "description": "An Array: the number of elements, a constant or an Expression.",
          "type": [
            "integer",
            "string"
          ]
        },
        "repeat": {
          "description": "An Array read until its enclosing structure or the Message ends.",
          "allOf": [
            {
              "$ref": "#/definitions/Repeat"
            }
          ]
        },
        "endian": {
          "description": "The byte order of this Field, or of the Fields of an inline structure.",
          "allOf": [
            {
              "$ref": "#/definitions/ByteOrder"
            }
          ]
        },
        "size": {
          "description": "The length in bytes of a `string` or `bytes`: a constant, an Expression, or `\"_remaining\"` to read to the end of the enclosing structure or Message.",
          "type": [
            "integer",
            "string"
          ]
        },
        "prefix": {
          "description": "The unsigned integer type the length of a `string` or `bytes` is read from, just before it.",
          "enum": [
            "uint8",
            "uint16",
            "uint24",
            "uint32",
            "uint40",
            "uint48",
            "uint56",
            "uint64"
          ]
        },
        "terminator": {
          "description": "The byte a `string` or `bytes` ends at, consumed but not part of the value.",
          "type": "integer",
          "minimum": 0,
          "maximum": 255
        },
        "encoding": {
          "description": "How a `string`'s text or a timestamp's bytes are read.",
          "enum": [
            "utf8",
            "ascii",
            "utf16",
            "ucs2",
            "latin1",
            "secs",
            "secs_nsecs",
            "ntp",
            "msecs",
            "usecs",
            "nsecs"
          ]
        },
        "display": {
          "description": "How the value is shown.",
          "enum": [
            "dec",
            "hex",
            "oct",
            "dec_hex",
            "hex_dec",
            "plain",
            "dot",
            "dash",
            "colon",
            "space",
            "local",
            "utc",
            "doy_utc"
          ]
        },
        "values": {
          "description": "Labels for an integer's values: an inline table or the name of an Enum.",
          "allOf": [
            {
              "$ref": "#/definitions/Values"
            }
          ]
        },
        "true": {
          "description": "The label of a true `bool`.",
          "type": "string"
        },
        "false": {
          "description": "The label of a false `bool`.",
          "type": "string"
        },
        "unit": {
          "description": "The unit shown after a number: a string, or `[singular, plural]`.",
          "allOf": [
            {
              "$ref": "#/definitions/Unit"
            }
          ]
        },
        "expect": {
          "description": "The values the Field should hold; another value gets a warning in Wireshark.",
          "allOf": [
            {
              "$ref": "#/definitions/Expect"
            }
          ]
        },
        "dissector": {
          "description": "The name of a Wireshark dissector the bytes of a `bytes` Field are handed to.",
          "type": "string",
          "pattern": "^\\S+$"
        },
        "label": {
          "description": "The text shown in the tree; defaults to the name with `_` as spaces, first letter capitalised. One line.",
          "type": "string",
          "minLength": 1
        },
        "description": {
          "description": "A one-line description of the Field, shown as its filter's blurb.",
          "type": "string"
        },
        "hidden": {
          "description": "Read the Field but leave it out of the tree; it can still be filtered and used in Expressions.",
          "type": "boolean"
        },
        "if": {
          "description": "Read the Field only when this Expression is not zero.",
          "type": [
            "integer",
            "string"
          ]
        }
      },
      "additionalProperties": false,
      "required": [
        "name"
      ]
    },
    "Case": {
      "description": "A Case of a `switch`: a Type name, or inline Fields.",
      "anyOf": [
        {
          "type": "string",
          "pattern": "^[A-Z][A-Za-z0-9]*$"
        },
        {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Entry"
          },
          "minItems": 1
        }
      ]
    },
    "Bit": {
      "description": "One entry of `bits:`: a sub-Field, or unnamed bits skipped.",
      "anyOf": [
        {
          "$ref": "#/definitions/SubField"
        },
        {
          "$ref": "#/definitions/BitPadding"
        }
      ]
    },
    "SubField": {
      "description": "A sub-Field of a Bitfield: a boolean when it is one bit wide, an unsigned integer otherwise.",
      "type": "object",
      "properties": {
        "name": {
          "description": "The sub-Field's name: lowercase letters, digits and `_`, starting with a letter.",
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]*$"
        },
        "width": {
          "description": "The number of bits.",
          "type": "integer",
          "minimum": 1
        },
        "display": {
          "description": "How the value is shown; makes a one-bit sub-Field an integer.",
          "enum": [
            "dec",
            "hex",
            "oct",
            "dec_hex",
            "hex_dec",
            "plain",
            "dot",
            "dash",
            "colon",
            "space",
            "local",
            "utc",
            "doy_utc"
          ]
        },
        "values": {
          "description": "Labels for the values: an inline table or the name of an Enum. Makes a one-bit sub-Field an integer.",
          "allOf": [
            {
              "$ref": "#/definitions/Values"
            }
          ]
        },
        "unit": {
          "description": "The unit shown after the value; makes a one-bit sub-Field an integer.",
          "allOf": [
            {
              "$ref": "#/definitions/Unit"
            }
          ]
        },
        "true": {
          "description": "The label of a set one-bit sub-Field.",
          "type": "string"
        },
        "false": {
          "description": "The label of a clear one-bit sub-Field.",
          "type": "string"
        },
        "hidden": {
          "description": "Read the sub-Field but leave it out of the tree.",
          "type": "boolean"
        },
        "expect": {
          "description": "The values the sub-Field should hold; another value gets a warning in Wireshark.",
          "allOf": [
            {
              "$ref": "#/definitions/Expect"
            }
          ]
        },
        "label": {
          "description": "The text shown in the tree. One line.",
          "type": "string",
          "minLength": 1
        },
        "description": {
          "description": "A one-line description, shown as the filter's blurb.",
          "type": "string"
        }
      },
      "additionalProperties": false,
      "required": [
        "name",
        "width"
      ]
    },
    "Values": {
      "description": "Labels for an integer's values: an inline table, or the name of an Enum.",
      "anyOf": [
        {
          "type": "string",
          "pattern": "^[A-Z][A-Za-z0-9]*$"
        },
        {
          "$ref": "#/definitions/Table"
        }
      ]
    },
    "Table": {
      "description": "Labels for values, by integer or `\"low-high\"` range string.",
      "type": "object",
      "additionalProperties": {
        "type": "string"
      }
    },
    "Unit": {
      "description": "A unit: one string, or `[singular, plural]`.",
      "anyOf": [
        {
          "type": "string",
          "minLength": 1
        },
        {
          "type": "array",
          "items": {
            "type": "string"
          },
          "minItems": 2,
          "maxItems": 2
        }
      ]
    },
    "Expect": {
      "description": "One expected value or range, or a list of them.",
      "anyOf": [
        {
          "anyOf": [
            {
              "type": "integer"
            },
            {
              "type": "string",
              "pattern": "^\\s*(0x[0-9a-fA-F]+|0o[0-7]+|[-+]?[0-9]+)\\s*-\\s*(0x[0-9a-fA-F]+|0o[0-7]+|[-+]?[0-9]+)\\s*$"
            }
          ]
        },
        {
          "type": "array",
          "items": {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "string",
                "pattern": "^\\s*(0x[0-9a-fA-F]+|0o[0-7]+|[-+]?[0-9]+)\\s*-\\s*(0x[0-9a-fA-F]+|0o[0-7]+|[-+]?[0-9]+)\\s*$"
              }
            ]
          },
          "minItems": 1
        }
      ]
    },
    "BitPadding": {
      "description": "Unnamed bits that are skipped.",
      "type": "object",
      "properties": {
        "padding": {
          "description": "The number of bits skipped.",
          "type": "integer",
          "minimum": 1
        }
      },
      "additionalProperties": false,
      "required": [
        "padding"
      ]
    },
    "Repeat": {
      "description": "An Array read until its enclosing structure or the Message ends.",
      "type": "string",
      "enum": [
        "to_end"
      ]
    },
    "Padding": {
      "description": "Unnamed space that is skipped.",
      "type": "object",
      "properties": {
        "padding": {
          "description": "The number of bytes skipped: a constant, or an Expression over earlier Fields.",
          "type": [
            "integer",
            "string"
          ]
        }
      },
      "additionalProperties": false,
      "required": [
        "padding"
      ]
    },
    "Type": {
      "description": "A Type: a named, reusable group of Fields.",
      "type": "object",
      "properties": {
        "fields": {
          "description": "The Fields of the Type, read one after another.",
          "type": "array",
          "items": {
            "$ref": "#/definitions/Entry"
          },
          "minItems": 1
        },
        "endian": {
          "description": "The byte order the Type is read in, whatever structure uses it; defaults to the top level's.",
          "allOf": [
            {
              "$ref": "#/definitions/ByteOrder"
            }
          ]
        }
      },
      "additionalProperties": false,
      "required": [
        "fields"
      ]
    }
  }
}
