80 lines
2.3 KiB
C++
80 lines
2.3 KiB
C++
#pragma once
|
|
|
|
#include <mln/particle/field/field_profile_validator.hpp>
|
|
|
|
#include <cstdint>
|
|
#include <memory>
|
|
#include <span>
|
|
#include <string>
|
|
|
|
namespace mln::particle::ingress {
|
|
|
|
struct EncodedFieldRuntimeMetadata {
|
|
std::string fieldID;
|
|
uint64_t generation = 0;
|
|
uint64_t dataVersion = 0;
|
|
};
|
|
|
|
enum class QbinDecodeErrorCode : uint8_t {
|
|
Accepted,
|
|
InvalidRuntimeMetadata,
|
|
InputTooSmall,
|
|
BadMagic,
|
|
UnsupportedVersion,
|
|
UnsupportedLayout,
|
|
UnsupportedProjection,
|
|
UnsupportedSampleOrder,
|
|
UnsupportedGridRegistration,
|
|
InvalidHeader,
|
|
InvalidBounds,
|
|
InvalidTime,
|
|
LimitExceeded,
|
|
LengthMismatch,
|
|
ReservedNonZero,
|
|
InvalidDescriptor,
|
|
NonCanonicalDescriptorOrder,
|
|
DuplicatePlaneKey,
|
|
NonCanonicalPacking,
|
|
NonZeroPadding,
|
|
CrcMismatch,
|
|
InvalidValidity,
|
|
InvalidCellPayload,
|
|
InvalidFrame,
|
|
MalformedRice,
|
|
ResidualOutOfRange,
|
|
};
|
|
|
|
using QbinV2DecodeErrorCode = QbinDecodeErrorCode;
|
|
|
|
struct QbinV2DecodeResult {
|
|
QbinDecodeErrorCode code = QbinDecodeErrorCode::InvalidHeader;
|
|
std::string detail;
|
|
std::shared_ptr<const DecodedFieldFrame> frame;
|
|
bool accepted() const { return code == QbinDecodeErrorCode::Accepted && static_cast<bool>(frame); }
|
|
};
|
|
|
|
class QbinV2Decoder final {
|
|
public:
|
|
static QbinV2DecodeResult decode(const EncodedFieldRuntimeMetadata&, std::span<const uint8_t>);
|
|
};
|
|
|
|
enum class EncodedFieldIngressCode : uint8_t { Accepted, DecodeRejected, ContractMissing, ContractRejected };
|
|
|
|
struct EncodedFieldIngressResult {
|
|
EncodedFieldIngressCode code = EncodedFieldIngressCode::DecodeRejected;
|
|
std::string detail;
|
|
QbinDecodeErrorCode decodeCode = QbinDecodeErrorCode::InvalidHeader;
|
|
FieldProfileValidationCode contractCode = FieldProfileValidationCode::InvalidContract;
|
|
std::shared_ptr<const DecodedFieldFrame> frame;
|
|
bool accepted() const { return code == EncodedFieldIngressCode::Accepted && static_cast<bool>(frame); }
|
|
};
|
|
|
|
class EncodedFieldIngress final {
|
|
public:
|
|
static EncodedFieldIngressResult decodeAndValidate(const EncodedFieldRuntimeMetadata&,
|
|
const ResolvedFieldProfileContract* contract,
|
|
std::span<const uint8_t>);
|
|
};
|
|
|
|
} // namespace mln::particle::ingress
|