copyScalar method

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

Implementation

Object? copyScalar(Object? value, {required String field}) {
  _rejectReentrantMetadataAccess();
  final int byteCount;
  if (value is int) {
    byteCount = value.toString().length;
  } else if (value is double) {
    if (!value.isFinite) {
      throw FormatException(
        'Invalid $_resource $field: expected a finite JSON scalar.',
      );
    }
    byteCount = value.toString().length;
  } else if (value is bool) {
    byteCount = value ? 4 : 5;
  } else if (value == null) {
    byteCount = 4;
  } else {
    throw FormatException(
      'Invalid $_resource $field: expected a JSON scalar.',
    );
  }
  _consume(nodes: 1, bytes: byteCount, field: field);
  return value;
}