/* * Copyright (c) 2023, kleines Filmröllchen * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include namespace RIFF { static constexpr size_t const chunk_id_size = 4; // Also referred to as "FourCC" (four character code) in the context of some formats. struct ChunkID { constexpr ChunkID(char const name[4]) { id_data[0] = static_cast(name[0]); id_data[1] = static_cast(name[1]); id_data[2] = static_cast(name[2]); id_data[3] = static_cast(name[3]); } constexpr ChunkID(Array data) : id_data(data) { } constexpr ChunkID(ChunkID const&) = default; constexpr ChunkID(ChunkID&&) = default; constexpr ChunkID& operator=(ChunkID const&) = default; static constexpr ChunkID from_number(u32 number) { return Array { { static_cast((number >> 24) & 0xff), static_cast((number >> 16) & 0xff), static_cast((number >> 8) & 0xff), static_cast(number & 0xff), } }; } static ErrorOr read_from_stream(Stream& stream); StringView as_ascii_string() const; constexpr u32 as_number() const { return (id_data[0] << 24) | (id_data[1] << 16) | (id_data[2] << 8) | id_data[3]; } bool operator==(ChunkID const&) const = default; bool operator==(StringView) const; Array id_data; }; static_assert(AssertSize()); } template<> struct AK::Formatter : StandardFormatter { ErrorOr format(FormatBuilder& builder, RIFF::ChunkID const& chunk_id) { TRY(builder.put_padding('\'', 1)); TRY(builder.put_literal(chunk_id.as_ascii_string())); TRY(builder.put_padding('\'', 1)); return {}; } };