encodeWithContext method
- @override
- @protected
- Runtime value,
- SchemaContext context
override
Encodes a runtime value into a boundary value. The base class strips
null before calling this; subclasses receive a non-null value.
The default delegates to encodeAsBoundary, which is correct for schemas
where Boundary == Runtime. Schemas where the two types differ (codecs,
objects, lists, enums, …) override this to implement encoding logic.
Implementation
@override
@protected
SchemaResult<Boundary> encodeWithContext(
Runtime value,
SchemaContext context,
) {
final recursionContext = _enterRecursion(value, context);
final depthResult = _checkMaxDepth<Boundary>(recursionContext);
if (depthResult != null) return depthResult;
final ownChecked = applyConstraintsAndRefinements(value, context);
if (ownChecked.isFail) return SchemaResult.fail(ownChecked.getError());
final target = _target;
return target.encodeWithContext(ownChecked.getOrThrow()!, recursionContext);
}