wireTypeForFieldType function

int wireTypeForFieldType(
  1. String type
)

Returns the wire type for a protobuf field type string.

The type must be one of the TYPE_* constants from FieldDescriptorProto.Type (e.g. 'TYPE_INT32', 'TYPE_STRING').

Throws ArgumentError for unrecognized type strings.

Implementation

int wireTypeForFieldType(String type) {
  switch (type) {
    case 'TYPE_INT32':
    case 'TYPE_INT64':
    case 'TYPE_UINT32':
    case 'TYPE_UINT64':
    case 'TYPE_SINT32':
    case 'TYPE_SINT64':
    case 'TYPE_BOOL':
    case 'TYPE_ENUM':
      return _wtVarint;

    case 'TYPE_FIXED64':
    case 'TYPE_SFIXED64':
    case 'TYPE_DOUBLE':
      return _wtI64;

    case 'TYPE_STRING':
    case 'TYPE_BYTES':
    case 'TYPE_MESSAGE':
      return _wtLen;

    case 'TYPE_FIXED32':
    case 'TYPE_SFIXED32':
    case 'TYPE_FLOAT':
      return _wtI32;

    default:
      throw ArgumentError('Unknown protobuf field type: $type');
  }
}