Skip to content

Add ASN.1 protocol schema (Tier A) with round-trip validation#42

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/discover-wire-format
Draft

Add ASN.1 protocol schema (Tier A) with round-trip validation#42
Copilot wants to merge 2 commits intomainfrom
copilot/discover-wire-format

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 12, 2026

No machine-readable schema exists for the REST API wire format. Added an ASN.1 schema documenting all message types exchanged between web-client and backend, with constrained types and round-trip smoke tests.

Discovery determined Tier A (Schema Only) is appropriate: serialization is standard Spring Boot Jackson (not hand-rolled), models are typed Java classes (not stringly-typed maps), and no existing .proto/.thrift/OpenAPI spec was found.

Schema (protocol.asn)

  • 11 message types: LoginRequest, LoginResponse, Command, RulerDecision, RulerStats, Army, Tile, GameState, ErrorResponse, BaronyRequest, BaronyResponse
  • Constrained primitives (Morale ::= INTEGER (0..200), Coordinate ::= INTEGER (0..19), etc.) derived from clamping logic in model setters
  • ENUMERATED for magic strings (CommandType, TileType, policy enums)
  • CHOICE dispatch unions (BaronyRequest, BaronyResponse) with extension markers
  • Block comment above each type references the source file it documents

Build system (asn1/Makefile)

  • Compiles protocol.asn via asn1c submodule (mouse07410/asn1c)
  • Builds per-PDU converter binaries for encode/decode testing
  • make test runs XER→DER→XER round-trip for all 11 types

Documentation

  • asn1/DISCOVERY.md — wire format analysis, message inventory, call sites, tier justification
  • asn1/SCHEMA.md — type reference with field-level mapping to Java sources and XER examples

Example XER encoding

<Command>
    <type><move/></type>
    <armyId>1</armyId>
    <targetX>5</targetX>
    <targetY>3</targetY>
    <splitAmount>0</splitAmount>
</Command>

All 137 existing backend tests unaffected. Generated files excluded via .gitignore.

Copilot AI and others added 2 commits April 12, 2026 21:54
- protocol.asn at repo root with all message types
- asn1/DISCOVERY.md with full discovery report (Tier A selected)
- asn1/SCHEMA.md with type reference documentation
- asn1/Makefile to compile schema and build converter binaries
- asn1/run-tests.sh round-trip smoke tests (11/11 pass)
- asn1/test-data/ with XER samples for all types
- mouse07410/asn1c added as git submodule at asn1c/
- .gitignore updated for generated files

Agent-Logs-Url: https://github.com/Preponderous-Software/barony/sessions/1cda833b-4f09-4480-b272-5e3f97de6e10

Co-authored-by: dmccoystephenson <21204351+dmccoystephenson@users.noreply.github.com>
…an target in Makefile

Agent-Logs-Url: https://github.com/Preponderous-Software/barony/sessions/1cda833b-4f09-4480-b272-5e3f97de6e10

Co-authored-by: dmccoystephenson <21204351+dmccoystephenson@users.noreply.github.com>
@dmccoystephenson
Copy link
Copy Markdown
Member

@copilot what is the purpose of including an ASN.1 schema if it is not directly used by the project?

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 12, 2026

@copilot what is the purpose of including an ASN.1 schema if it is not directly used by the project?

The schema isn't wired into the runtime — it's a Tier A (documentation-only) deliverable. Its purpose is to provide a machine-readable, language-neutral contract for the REST API data types that currently exist only as Java class definitions.

Concrete benefits:

  • Validation: The round-trip tests (XER→DER→XER) verify that every field, constraint, and enum value in the schema matches the actual Java models. If someone changes a model field or range, the schema can catch the drift.
  • Documentation: protocol.asn captures constraints (e.g., Morale ::= INTEGER (0..200), Coordinate ::= INTEGER (0..19)) that are buried in setter clamping logic. SCHEMA.md maps each ASN.1 type back to the exact Java source file.
  • Future interop: If the project ever needs a non-Java client, binary encoding (UPER/DER), or formal protocol specification, the schema is already written and tested.

That said, if the project doesn't see value in maintaining a separate schema alongside the Java models, this is entirely reasonable to decline — the existing Jackson serialization works well and the models are already typed. Happy to close the PR if this isn't a direction you want to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants