copyString method
Implementation
String copyString(Object? value, {required String field}) {
_rejectReentrantMetadataAccess();
if (value is! String) {
throw FormatException('Invalid $_resource $field: expected a string.');
}
final byteCount = _boundedChatUtf8Length(
value,
limit: _budget.maxStructuredStringBytes,
onExceeded: (observedAtLeast) => _throwLimit(
field: field,
kind: 'string bytes',
limit: _budget.maxStructuredStringBytes,
observedAtLeast: observedAtLeast,
),
);
_consume(nodes: 1, bytes: byteCount, field: field);
return value;
}