blob: 5f5a8292aafab66627f7b9af294eee58a240879a [file] [view]
---
paths: "protocols/**"
applyTo: "protocols/**"
---
<!-- GENERATED from .agents/rules/protocols.md by .agents/sync-adapters.sh. Edit the source, then run it. -->
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
# Protocol definitions (`protocols/`)
`protocols/<dir>/` holds a protocol's mspec files (`src/main/resources/protocols/<dir>/*.mspec`), the class that
registers them (`src/main/java/**/*Protocol.java`, `getName()` is the protocol name, which can differ from the
directory: `iec-60870` → `iec-60870-5-104`; one module can register several, `ads` and `ads.discovery`), and the
shared test suites (`src/test/resources/protocols/<dir>/`): `ParserSerializerTestsuite.xml` (bytes ↔ model) and
`DriverTestsuite.xml` (request/response sequences). Syntax: `website/asciidoc/modules/developers/pages/code-gen/protocol/mspec.adoc`.
## ⛔ An mspec change reaches every language that generates the protocol
Which languages generate it (Java, Go, C, Python via `plc4x-maven-plugin`; C# via its own generator):
```bash
p=s7 # the name from getName()
grep -rln --include=pom.xml "<protocolName>$p</protocolName>" plc4j plc4go plc4c plc4py | grep -v /target/
grep -n "\"$p\"" plc4net/tools/code-gen/generate_protocol_models.py
```
For each hit: regenerate (`regenerate-code` skill) and commit the result with the mspec change. The website matrix
(`website/asciidoc/modules/users/pages/protocols/index.adoc`) says which languages ship a driver; a language can
generate a model without shipping a driver, and it still needs the regenerated code.
- **`[manual ...]` fields and `STATIC_CALL("name", ...)`** call a hand-written helper in **every** generating
language: `plc4j/drivers/<p>/**/StaticHelper.java`, `plc4go/protocols/<p>/readwrite/model/StaticHelper.go`,
`plc4c/drivers/<p>/src/driver_<p>_static.c`, `plc4py/plc4py/protocols/<p>/StaticHelper.py`,
`plc4net/drivers/<p>/*.Manual.cs`. A new or changed call needs the helper in each of them.
- **Renaming a type, field or enum constant** renames generated API in every language; the hand-written driver
code that uses it changes too. Search each language's driver for the old name.
- **Test suites:** a parse or serialize change gets a `ParserSerializerTestsuite.xml` case. `plc4go` reads a
tracked copy in `plc4go/assets/testing/protocols/`, refreshed by the Maven build of `plc4go`
(`generate-resources`): commit the refreshed copy with the change.
- **Vendor data:** `bacnetip`, `knxnetip` and `opcua` regenerate part of their mspec from downloaded vendor data
(their `update-generated-code` profile). Do not hand-edit those generated mspec parts.
- **Wire data is untrusted** (`THREAT-MODEL.md`): lengths and counts read from the wire bound arrays and loops;
an `[assert]` or `[validation]` turns a bad value into a parse error.