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').

Note: there is intentionally no 'TYPE_GROUP' case. By design a group is represented as TYPE_MESSAGE + message_encoding = DELIMITED (the editions-canonical form); the DELIMITED wire type is chosen by the caller from the resolved feature, not from the type string. The absence of a TYPE_GROUP branch is therefore deliberate, not a bug.

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