Skip to main content
Hytale uses codecs (encode/decode pairs) to save and load components, send network packets, and persist data. HRTK’s CodecAssert class lets you verify that your codecs correctly round-trip data and properly reject bad input. Codec bugs are sneaky - a field that silently disappears when saving, a decode that produces garbage instead of an error, or a round-trip that corrupts precision. These bugs often go unnoticed until a player loads a corrupted save file. Automated codec tests catch them early.

CodecAssert Methods

MethodDescription
assertRoundTrip(codec, value)Encode then decode; assert result equals original
assertRoundTrip(codec, value, equalityCheck)Round-trip with custom equality predicate
assertDecodeEquals(codec, bsonValue, expected)Decode and assert result equals expected
assertDecodeThrows(codec, malformedBson)Assert decoding throws an exception

Complete Example Suite

If assertDecodeThrows does NOT get an error, the test fails with “Expected decode to throw but it succeeded”. This catches codecs that silently accept bad input instead of rejecting it, which could lead to corrupted data.

How It Works Internally

CodecAssert automatically finds and calls the encode() and decode() methods on your codec. It works with any codec that follows the standard Hytale pattern.
The codec parameter is typed as Object in the API so your mod doesn’t need the server JAR at compile time. At runtime, pass a Hytale Codec<T> instance.

When to Test Codecs

Codec tests are essential when:
  • You define custom components with serialization logic
  • You modify existing component codecs
  • You need regression tests for data persistence formats
  • You want to verify backward compatibility after schema changes

Next Steps