diff options
author | Kevin Cheng <kevin.cheng@arm.com> | 2021-10-20 12:12:02 -0700 |
---|---|---|
committer | Kevin Cheng <kevin.cheng@arm.com> | 2021-10-26 08:27:53 -0700 |
commit | e6563f52231c603b409638b22530d016757542c8 (patch) | |
tree | 43700371a56ce6b23052924b59c4e5ab43f286ca /include/tosa_serialization_handler.h | |
parent | b97cb1d46690321235f814e5a52cb8186380bce3 (diff) | |
download | serialization_lib-e6563f52231c603b409638b22530d016757542c8.tar.gz |
Bring back TosaVersion struct
- check fails only when major/minor mismatches
- dump warning if major/minor matches but patch/draft mismatches
Signed-off-by: Kevin Cheng <kevin.cheng@arm.com>
Change-Id: I0464f1018faa69b81fa93d42e51e1afd7412977a
Diffstat (limited to 'include/tosa_serialization_handler.h')
-rw-r--r-- | include/tosa_serialization_handler.h | 62 |
1 files changed, 59 insertions, 3 deletions
diff --git a/include/tosa_serialization_handler.h b/include/tosa_serialization_handler.h index 7fd8282..61c02db 100644 --- a/include/tosa_serialization_handler.h +++ b/include/tosa_serialization_handler.h @@ -26,6 +26,7 @@ #include <string> #include <vector> +// Keep version number in sync with the version default value with schema/tosa.fbs #define TOSA_VERSION_MAJOR 0 #define TOSA_VERSION_MINOR 23 #define TOSA_VERSION_PATCH 0 @@ -47,6 +48,62 @@ enum tosa_err_t NUM_TOSA_ERROR }; +struct TosaVersion +{ + int32_t _major; + int32_t _minor; + int32_t _patch; + bool _draft; + + enum class compat_t + { + COMPLETELY_COMPATIBLE, + PARTIALLY_COMPATIBLE, + NOT_COMPATIBLE + }; + + TosaVersion() = default; + TosaVersion(int32_t major, int32_t minor, int32_t patch, bool draft) + { + set_version(major, minor, patch, draft); + } + + void set_version(int32_t major, int32_t minor, int32_t patch, bool draft) + { + _major = major; + _minor = minor; + _patch = patch; + _draft = draft; + } + + std::string to_string() const + { + std::string str; + str += std::to_string(_major) + "."; + str += std::to_string(_minor) + "."; + str += std::to_string(_patch); + if (_draft) + str += "d"; + return str; + } + + compat_t is_compatible(const TosaVersion& rhs) const + { + if (rhs._major == _major && rhs._minor == _minor) + { + if (rhs._patch == _patch && rhs._draft == _draft) + { + return TosaVersion::compat_t::COMPLETELY_COMPATIBLE; + } + else + { + return TosaVersion::compat_t::PARTIALLY_COMPATIBLE; + } + } + return TosaVersion::compat_t::NOT_COMPATIBLE; + } +}; + class TosaSerializationHandler; class TosaSerializationTensor @@ -247,7 +304,7 @@ public: static tosa_err_t ConvertU8toBool(const std::vector<uint8_t>& in, uint32_t out_size, std::vector<bool>& out); // version - const std::string& GetVersionStr() + const TosaVersion& GetVersion() { return _version; } @@ -296,10 +353,9 @@ protected: tosa_err_t Clear(); tosa_err_t Deserialize(const uint8_t* buf); tosa_err_t Serialize(); - std::string VersionToStr(int32_t major, int32_t minor, int32_t patch, bool draft); private: - std::string _version; /* version string */ + TosaVersion _version; /* version struct */ flatbuffers::FlatBufferBuilder _builder; /* flatbuffer builder */ flatbuffers::Parser _parser; /* flatbuffer parser, used for json parsing */ std::vector<TosaSerializationBasicBlock*> _blocks; /* array structure to store all TosaSerializationBasicBlock */ |