Class VersionedCodec.Builder<T>
java.lang.Object
org.jwcarman.codec.versioned.VersionedCodec.Builder<T>
- Type Parameters:
T- the type the codec converts
- Enclosing class:
VersionedCodec
Collects the per-version codecs and the version to write, and validates them.
-
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds the codec.Registers the codec that reads (and, if named bywriting(int), writes) a version.writing(int version) Names the versionCodec.encode(T)writes.
-
Method Details
-
version
Registers the codec that reads (and, if named bywriting(int), writes) a version.- Parameters:
version- the format version, 1-255; 0 is reservedcodec- the codec that produced and can read that version's payloads- Returns:
- this builder
- Throws:
IllegalArgumentException- ifversionis outside 1-255IllegalStateException- ifversionis already registeredNullPointerException- ifcodecis null
-
writing
Names the versionCodec.encode(T)writes. Required. A later call replaces an earlier one — there is exactly one write version, and the last call wins.- Parameters:
version- the format version to write, 1-255- Returns:
- this builder
- Throws:
IllegalArgumentException- ifversionis outside 1-255
-
build
Builds the codec.- Returns:
- an immutable versioned codec
- Throws:
IllegalStateException- if no version was registered, ifwriting(int)was never called, or if it names a version with no registered codec
-