使用消息傳遞時的提示 - AWS SimSpace Weaver

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

使用消息傳遞時的提示

從位置或應用程式名稱解析端點

您可以使用此AllPartitions函數來取得決定郵件分割區 ID 和郵件目的地所需的空間界限和網域識別碼。但是,如果您知道要發送消息的位置,但不知道其分區 ID,則可以使用該 MessageEndpointResolver 功能。

/** * Resolves MessageEndpoint's from various inputs **/ class MessageEndpointResolver { public: /** * Resolves MessageEndpoint from position information **/ Result<MessageEndpoint> ResolveEndpointFromPosition( const DomainId& domainId, const weaver_vec3_f32_t& pos); /** * Resolves MessageEndpoint from custom app name **/ Result<MessageEndpoint> ResolveEndpointFromCustomAppName( const DomainId& domainId, const char* agentName); };

序列化和反序列化消息有效負載

您可以使用下列函數來建立和讀取訊息承載。如需詳細資訊,請參閱本機系統上應用程式 SDK 程式庫中的 MessagingUtils .h。

/** * Utility function to create MessagePayload from a custom type * * @return The @c MessagePayload. */ template <class T> AWS_WEAVERRUNTIME_API MessagePayload CreateMessagePayload(const T& message) noexcept { const std::uint8_t* raw_data = reinterpret_cast<const std::uint8_t*>(&message); MessagePayload payload; std::move(raw_data, raw_data + sizeof(T), std::back_inserter(payload.data)); return payload; } /** * Utility function to convert MessagePayload to custom type */ template <class T> AWS_WEAVERRUNTIME_API T ExtractMessage(const MessagePayload& payload) noexcept { return *reinterpret_cast<const T*>(payload.data.data()); }