getCheckFunction function

CheckFunc getCheckFunction(
  1. int fieldType

Returns a function for validating items in a repeated field.

For most types this is a not-null check, except for floats, and signed and unsigned 32 bit ints where there also is a range check.


CheckFunc getCheckFunction(int fieldType) {
  switch (fieldType & ~0x7) {
    case PbFieldType._BOOL_BIT:
    case PbFieldType._BYTES_BIT:
    case PbFieldType._STRING_BIT:
    case PbFieldType._DOUBLE_BIT:
    case PbFieldType._ENUM_BIT:
    case PbFieldType._GROUP_BIT:
    case PbFieldType._MESSAGE_BIT:

    case PbFieldType._INT64_BIT:
    case PbFieldType._SINT64_BIT:
    case PbFieldType._SFIXED64_BIT:
    case PbFieldType._UINT64_BIT:
    case PbFieldType._FIXED64_BIT:
      // We always use the full range of the same Dart type.
      // It's up to the caller to treat the Int64 as signed or unsigned.
      // See:
      return _checkNotNull;

    case PbFieldType._FLOAT_BIT:
      return _checkFloat;

    case PbFieldType._INT32_BIT:
    case PbFieldType._SINT32_BIT:
    case PbFieldType._SFIXED32_BIT:
      return _checkSigned32;

    case PbFieldType._UINT32_BIT:
    case PbFieldType._FIXED32_BIT:
      return _checkUnsigned32;
  throw ArgumentError('check function not implemented: $fieldType');