ProtoDef-validator is a Node.js library specifically engineered to validate protocol definitions structured using the ProtoDef schema language. It offers a programmatic interface for verifying that custom data types and complete protocol schemas adhere to established structural and semantic rules. Currently stable at version 1.4.0, the package demonstrates an active release cadence with minor updates and dependency bumps, indicating ongoing maintenance. Its core utility lies in preempting issues in protocol definition files by programmatically enforcing their correctness, a critical function for ensuring data integrity and compatibility in binary serialization and network communication. A key differentiator is its singular focus on validating the structural soundness of the schema itself, rather than performing data serialization or deserialization, thereby acting as a foundational tool for developers working within the ProtoDef ecosystem.
npm install protodef-validatorVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to instantiate a Validator, add a custom type, define a simple protocol, and then validate both the custom type and the full protocol schema.
Refer to the ProtoDef specification for the version you are targeting and update your protocol definition JSON files accordingly. Monitor the ProtoDef-io/ProtoDef repository for major changes.
When upgrading `protodef-validator`, review the `ajv` changelog for any breaking changes in schema validation behavior. Test your protocol definitions thoroughly against the new version.
Always explicitly define the schema when adding complex custom types using `Validator.addType(name, schema)` to prevent generic validation that might miss specific structural requirements.
Before validating, ensure all referenced custom types are added using `validator.addType(name, schema)` or `validator.addTypes(schemas)`.
Review your protocol definition JSON for `fieldName` and its surrounding structure. Ensure all properties and their values adhere to the ProtoDef schema specification (e.g., `type`, `name`, `countType`, `endian`).
Check for typos or extraneous properties in your ProtoDef JSON. Ensure you are only using properties (like `name`, `type`, `countType`) that are valid within the ProtoDef schema context.