summaryrefslogtreecommitdiff
path: root/source/core/slang-riff.h
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-10-23 13:25:58 -0400
committerGitHub <noreply@github.com>2019-10-23 13:25:58 -0400
commit73dcec672a2be0082945b71fc7848d9be0233f56 (patch)
treeb628912a14463457c45d1f442be993dafe2b68be /source/core/slang-riff.h
parent85f858c6d1b91fd2ed89844aae7535a48e51a4c8 (diff)
Version information on repro binary format. (#1090)
* * Added semantic versioning and hashing test on repro data. * Added RiffSemanticVersion type * Fix linux build warning.
Diffstat (limited to 'source/core/slang-riff.h')
-rw-r--r--source/core/slang-riff.h58
1 files changed, 55 insertions, 3 deletions
diff --git a/source/core/slang-riff.h b/source/core/slang-riff.h
index f6854310b..f681d6d68 100644
--- a/source/core/slang-riff.h
+++ b/source/core/slang-riff.h
@@ -17,6 +17,59 @@ struct RiffFourCC
static const uint32_t kRiff = SLANG_FOUR_CC('R', 'I', 'F', 'F');
};
+// Follows semantic version rules
+// https://semver.org/
+//
+// major.minor.patch
+// Patch versions indicate a change.
+// Minor means a change that is backwards compatible with previous minor versions. A step in minor and/or major zeros patch.
+// Major means a non compatible change. A step in major, zeros minor and patch.
+struct RiffSemanticVersion
+{
+ typedef RiffSemanticVersion ThisType;
+ typedef uint32_t RawType;
+
+ /// ==
+ bool operator==(const ThisType& rhs) const { return m_raw == rhs.m_raw; }
+ bool operator!=(const ThisType& rhs) const { return !(*this == rhs); }
+
+ /// A patch change indices a different version but does not change the compatibility of the format
+ int getPatch() const { return m_raw & 0xff; }
+ /// A minor change implies a format change that is backwards compatible
+ int getMinor() const { return (m_raw >> 8) & 0xff; }
+ /// A major change is binary incompatible by default
+ int getMajor() const { return (m_raw >> 16); }
+
+ static RawType makeRaw(int major, int minor, int patch)
+ {
+ SLANG_ASSERT((major | minor | patch) >= 0);
+ SLANG_ASSERT(major < 0x10000 && minor < 0x100 && patch < 0x100);
+ return (RawType(major) << 16) | (RawType(minor) << 8) | RawType(patch);
+ }
+
+ static RiffSemanticVersion makeFromRaw(RawType raw)
+ {
+ ThisType version;
+ version.m_raw = raw;
+ return version;
+ }
+
+ static RiffSemanticVersion make(int major, int minor, int patch) { return makeFromRaw(makeRaw(major, minor, patch)); }
+
+ /// True if the read version is compatible with the current version, based on semantic rules.
+ static bool areCompatible(const ThisType& currentVersion, const ThisType& readVersion)
+ {
+ const RawType currentRaw = currentVersion.m_raw;
+ const RawType readRaw = readVersion.m_raw;
+
+ // Must have same major version.
+ // For minor version, the read version must be less than or equal.
+ return ((currentRaw & 0xffff0000) == (readRaw & 0xffff0000)) && ((currentRaw & 0xff00) >= (readRaw & 0xff00));
+ }
+
+ RawType m_raw;
+};
+
struct RiffChunk
{
uint32_t m_type; ///< The FourCC code that identifies this chunk
@@ -31,9 +84,8 @@ struct RiffUtil
static SlangResult readChunk(Stream* stream, RiffChunk& outChunk);
-
- static SlangResult writeData(uint32_t riffType, const void* data, size_t size, Stream* out);
- static SlangResult readData(Stream* stream, RiffChunk& outChunk, List<uint8_t>& data);
+ static SlangResult writeData(const RiffChunk* header, size_t headerSize, const void* payload, size_t payloadSize, Stream* out);
+ static SlangResult readData(Stream* stream, RiffChunk* outHeader, size_t headerSize, List<uint8_t>& data);
};
}