def FormatFieldType(type_context, field):
    'Format a FieldDescriptorProto type description.\n\n  Adds cross-refs for message types.\n  TODO(htuch): Add cross-refs for enums as well.\n\n  Args:\n    type_context: contextual information for message/enum/field.\n    field: FieldDescriptor proto.\n  Return: RST formatted field type.\n  '
    if (field.type_name.startswith(ENVOY_API_NAMESPACE_PREFIX) or field.type_name.startswith(ENVOY_PREFIX)):
        type_name = NormalizeFieldTypeName(field.type_name)
        if (field.type == field.TYPE_MESSAGE):
            if (type_context.map_typenames and (TypeNameFromFQN(field.type_name) in type_context.map_typenames)):
                return ('map<%s, %s>' % tuple(map(functools.partial(FormatFieldType, type_context), type_context.map_typenames[TypeNameFromFQN(field.type_name)])))
            return FormatInternalLink(type_name, MessageCrossRefLabel(type_name))
        if (field.type == field.TYPE_ENUM):
            return FormatInternalLink(type_name, EnumCrossRefLabel(type_name))
    elif field.type_name.startswith(WKT_NAMESPACE_PREFIX):
        wkt = field.type_name[len(WKT_NAMESPACE_PREFIX):]
        return FormatExternalLink(wkt, ('https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#%s' % wkt.lower()))
    elif field.type_name.startswith(RPC_NAMESPACE_PREFIX):
        rpc = field.type_name[len(RPC_NAMESPACE_PREFIX):]
        return FormatExternalLink(rpc, ('https://cloud.google.com/natural-language/docs/reference/rpc/google.rpc#%s' % rpc.lower()))
    elif field.type_name:
        return field.type_name
    pretty_type_names = {field.TYPE_DOUBLE: 'double', field.TYPE_FLOAT: 'float', field.TYPE_INT32: 'int32', field.TYPE_SFIXED32: 'int32', field.TYPE_SINT32: 'int32', field.TYPE_FIXED32: 'uint32', field.TYPE_UINT32: 'uint32', field.TYPE_INT64: 'int64', field.TYPE_SFIXED64: 'int64', field.TYPE_SINT64: 'int64', field.TYPE_FIXED64: 'uint64', field.TYPE_UINT64: 'uint64', field.TYPE_BOOL: 'bool', field.TYPE_STRING: 'string', field.TYPE_BYTES: 'bytes'}
    if (field.type in pretty_type_names):
        return FormatExternalLink(pretty_type_names[field.type], 'https://developers.google.com/protocol-buffers/docs/proto#scalar')
    raise ProtodocError(('Unknown field type ' + str(field.type)))
Format a FieldDescriptorProto type description.

Adds cross-refs for message types.
TODO(htuch): Add cross-refs for enums as well.

Args:
  type_context: contextual information for message/enum/field.
  field: FieldDescriptor proto.
Return: RST formatted field type.
def FormatFieldType(type_context, field):
    'Format a FieldDescriptorProto type description.\n\n  Adds cross-refs for message types.\n  TODO(htuch): Add cross-refs for enums as well.\n\n  Args:\n    type_context: contextual information for message/enum/field.\n    field: FieldDescriptor proto.\n  Return: RST formatted field type.\n  '
    if (field.type_name.startswith(ENVOY_API_NAMESPACE_PREFIX) or field.type_name.startswith(ENVOY_PREFIX)):
        type_name = NormalizeFieldTypeName(field.type_name)
        if (field.type == field.TYPE_MESSAGE):
            if (type_context.map_typenames and (TypeNameFromFQN(field.type_name) in type_context.map_typenames)):
                return ('map<%s, %s>' % tuple(map(functools.partial(FormatFieldType, type_context), type_context.map_typenames[TypeNameFromFQN(field.type_name)])))
            return FormatInternalLink(type_name, MessageCrossRefLabel(type_name))
        if (field.type == field.TYPE_ENUM):
            return FormatInternalLink(type_name, EnumCrossRefLabel(type_name))
    elif field.type_name.startswith(WKT_NAMESPACE_PREFIX):
        wkt = field.type_name[len(WKT_NAMESPACE_PREFIX):]
        return FormatExternalLink(wkt, ('https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#%s' % wkt.lower()))
    elif field.type_name.startswith(RPC_NAMESPACE_PREFIX):
        rpc = field.type_name[len(RPC_NAMESPACE_PREFIX):]
        return FormatExternalLink(rpc, ('https://cloud.google.com/natural-language/docs/reference/rpc/google.rpc#%s' % rpc.lower()))
    elif field.type_name:
        return field.type_name
    pretty_type_names = {field.TYPE_DOUBLE: 'double', field.TYPE_FLOAT: 'float', field.TYPE_INT32: 'int32', field.TYPE_SFIXED32: 'int32', field.TYPE_SINT32: 'int32', field.TYPE_FIXED32: 'uint32', field.TYPE_UINT32: 'uint32', field.TYPE_INT64: 'int64', field.TYPE_SFIXED64: 'int64', field.TYPE_SINT64: 'int64', field.TYPE_FIXED64: 'uint64', field.TYPE_UINT64: 'uint64', field.TYPE_BOOL: 'bool', field.TYPE_STRING: 'string', field.TYPE_BYTES: 'bytes'}
    if (field.type in pretty_type_names):
        return FormatExternalLink(pretty_type_names[field.type], 'https://developers.google.com/protocol-buffers/docs/proto#scalar')
    raise ProtodocError(('Unknown field type ' + str(field.type)))