copyString method

String copyString(
  1. Object? value, {
  2. required String field,
})

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;
}