'Encode the nested protobuf into wire format.'

def ConvertToWireFormat(self, value):

    if hasattr(value.__class__, 'protobuf'):
        if value.__class__.protobuf:
            type_name = ('type.googleapis.com/%s' % value.__class__.protobuf.__name__)
        else:
            type_name = value.__class__.__name__
        data = value.SerializeToString()
    elif hasattr(value.__class__, 'data_store_type'):
        wrapper_cls = self.__class__.WRAPPER_BY_TYPE[value.__class__.data_store_type]
        wrapped_data = wrapper_cls()
        wrapped_data.value = value.SerializeToDataStore()
        type_name = ('type.googleapis.com/google.protobuf.%s' % wrapper_cls.__name__)
        data = wrapped_data.SerializeToString()
    else:
        raise ValueError(("Can't    convert    value    %s    to    an    protobuf.Any    value." % value))
    any_value = AnyValue(type_url=type_name, value=data)
    output = SerializeEntries(any_value.GetRawData().itervalues())
    return (self.encoded_tag, VarintEncode(len(output)), output)
