#ifndef MEDIAPIPE_FRAMEWORK_PACKET_H_
#define MEDIAPIPE_FRAMEWORK_PACKET_H_
#include <cstddef>
#include <cstdint>
#include <memory>
#include <ostream>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
#include "absl/base/attributes.h"
#include "absl/base/macros.h"
#include "absl/base/optimization.h"
#include "absl/functional/any_invocable.h"
#include "absl/log/absl_check.h"
#include "absl/log/absl_log.h"
#include "absl/memory/memory.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/str_cat.h"
#include "absl/synchronization/mutex.h"
#include "google/protobuf/message.h"
#include "google/protobuf/message_lite.h"
#include "mediapipe/framework/deps/no_destructor.h"
#include "mediapipe/framework/deps/registration.h"
#include "mediapipe/framework/port.h"
#include "mediapipe/framework/port/canonical_errors.h"
#include "mediapipe/framework/port/logging.h"
#include "mediapipe/framework/port/proto_ns.h"
#include "mediapipe/framework/port/ret_check.h"
#include "mediapipe/framework/port/status.h"
#include "mediapipe/framework/port/status_builder.h"
#include "mediapipe/framework/port/status_macros.h"
#include "mediapipe/framework/port/statusor.h"
#include "mediapipe/framework/timestamp.h"
#include "mediapipe/framework/tool/type_util.h"
#include "mediapipe/framework/type_map.h"
namespace mediapipe {
class Packet;
namespace packet_internal {
class HolderBase;
Packet Create(HolderBase* holder);
Packet Create(HolderBase* holder, Timestamp timestamp);
Packet Create(std::shared_ptr<const HolderBase> holder, Timestamp timestamp);
const HolderBase* GetHolder(const Packet& packet);
const std::shared_ptr<const HolderBase>& GetHolderShared(const Packet& packet);
std::shared_ptr<const HolderBase> GetHolderShared(Packet&& packet);
absl::StatusOr<Packet> PacketFromDynamicProto(const std::string& type_name,
const std::string& serialized);
}
class Packet { … };
template <typename T>
Packet Adopt(const T* ptr);
template <typename T>
Packet PointToForeign(const T* ptr,
absl::AnyInvocable<void()> cleanup = nullptr);
template <typename T>
Packet AdoptAsUniquePtr(T* ptr) { … }
class SyncedPacket { … };
template <typename T>
Packet AdoptAsSyncedPacket(const T* ptr) { … }
template <typename T,
typename std::enable_if<!std::is_array<T>::value>::type* = nullptr,
typename... Args>
Packet MakePacket(Args&&... args) { … }
template <typename T,
typename std::enable_if<std::is_array<T>::value>::type* = nullptr,
typename... Args>
Packet MakePacket(Args&&... args) { … }
template <typename T>
T* GetFromUniquePtr(const Packet& packet) { … }
template <typename T>
ABSL_DEPRECATED("Use Packet::Share<T>() instead.")
std::shared_ptr<const T> SharedPtrWithPacket(const Packet& packet) { … }
namespace packet_internal {
template <typename T>
class Holder;
template <typename T>
class ForeignHolder;
class HolderBase { … };
template <typename T>
const proto_ns::MessageLite* ConvertToProtoMessageLite(const T* data,
std::false_type) { … }
template <typename T>
const proto_ns::MessageLite* ConvertToProtoMessageLite(const T* data,
std::true_type) { … }
template <typename Type>
struct is_proto_vector : public std::false_type { … };
is_proto_vector<std::vector<ItemT, Allocator>>;
template <typename T>
absl::StatusOr<std::vector<const proto_ns::MessageLite*>>
ConvertToVectorOfProtoMessageLitePtrs(const T* data,
std::false_type) { … }
template <typename T>
absl::StatusOr<std::vector<const proto_ns::MessageLite*>>
ConvertToVectorOfProtoMessageLitePtrs(const T* data,
std::true_type) { … }
class MessageHolderRegistry
: public GlobalFactoryRegistry<std::unique_ptr<HolderBase>> { … };
template <typename T>
struct is_concrete_proto_t
: public std::integral_constant<
bool, std::is_base_of<proto_ns::MessageLite, T>{ … };
template <typename T>
std::unique_ptr<HolderBase> CreateMessageHolder() { … }
MEDIAPIPE_STATIC_REGISTRATOR_TEMPLATE(…)
template <typename T, typename Enable = void>
struct HolderPayloadRegistrator { … };
template <typename T>
struct HolderPayloadRegistrator<
T, typename std::enable_if<is_concrete_proto_t<T>{}>::type>
: private MessageRegistrator<typename std::remove_cv<T>::type> {};
template <typename T>
class Holder : public HolderBase, private HolderPayloadRegistrator<T> { … };
template <typename T>
class ForeignHolder : public Holder<T> { … };
template <typename T>
Holder<T>* HolderBase::AsMutable() const { … }
template <typename T>
const Holder<T>* HolderBase::As() const { … }
}
inline Packet::Packet(const Packet& packet)
: … { … }
inline Packet& Packet::operator=(const Packet& packet) { … }
template <typename T>
inline absl::StatusOr<std::unique_ptr<T>> Packet::Consume() { … }
template <typename T>
inline absl::StatusOr<std::unique_ptr<T>> Packet::ConsumeOrCopy(
bool* was_copied,
typename std::enable_if<!std::is_array<T>::value>::type*) { … }
template <typename T>
inline absl::StatusOr<std::unique_ptr<T>> Packet::ConsumeOrCopy(
bool* was_copied,
typename std::enable_if<std::is_array<T>::value &&
std::extent<T>::value != 0>::type*) { … }
template <typename T>
inline absl::StatusOr<std::unique_ptr<T>> Packet::ConsumeOrCopy(
bool* was_copied,
typename std::enable_if<std::is_array<T>::value &&
std::extent<T>::value == 0>::type*) { … }
inline Packet::Packet(Packet&& packet) { … }
inline Packet& Packet::operator=(Packet&& packet) { … }
inline bool Packet::IsEmpty() const { … }
inline TypeId Packet::GetTypeId() const { … }
template <typename T>
inline const T& Packet::Get() const { … }
template <typename T>
inline absl::StatusOr<std::shared_ptr<const T>> Packet::Share() const { … }
inline Timestamp Packet::Timestamp() const { … }
template <typename T>
Packet Adopt(const T* ptr) { … }
template <typename T>
Packet PointToForeign(const T* ptr, absl::AnyInvocable<void()> cleanup) { … }
inline bool operator==(const Packet& p1, const Packet& p2) { … }
inline bool operator!=(const Packet& p1, const Packet& p2) { … }
namespace packet_internal {
inline const std::shared_ptr<const HolderBase>& GetHolderShared(
const Packet& packet) { … }
inline std::shared_ptr<const HolderBase> GetHolderShared(Packet&& packet) { … }
}
}
#endif