Make Span const correclty
diff --git a/dev/core_generator/lib/src/field_types/bytes_field_type.dart b/dev/core_generator/lib/src/field_types/bytes_field_type.dart index 23a5d2e..22220c8 100644 --- a/dev/core_generator/lib/src/field_types/bytes_field_type.dart +++ b/dev/core_generator/lib/src/field_types/bytes_field_type.dart
@@ -5,15 +5,15 @@ : super( 'Bytes', 'CoreBytesType', - cppName: 'const Span<uint8_t>&', + cppName: 'Span<const uint8_t>', include: 'rive/span.hpp', ); @override - String get defaultValue => 'Span<uint8_t>(nullptr, 0)'; + String get defaultValue => 'Span<const uint8_t>(nullptr, 0)'; @override - String get cppGetterName => 'const Span<uint8_t>&'; + String get cppGetterName => 'Span<const uint8_t>'; @override String convertCpp(String value) {
diff --git a/include/rive/assets/file_asset_contents.hpp b/include/rive/assets/file_asset_contents.hpp index 2304bb6..10546d2 100644 --- a/include/rive/assets/file_asset_contents.hpp +++ b/include/rive/assets/file_asset_contents.hpp
@@ -9,9 +9,9 @@ std::vector<uint8_t> m_Bytes; public: - const std::vector<uint8_t>& bytes() const; + const Span<const uint8_t> bytes() const; StatusCode import(ImportStack& importStack) override; - void decodeBytes(const Span<uint8_t>& value) override; + void decodeBytes(Span<const uint8_t> value) override; void copyBytes(const FileAssetContentsBase& object) override; }; } // namespace rive
diff --git a/include/rive/core/binary_reader.hpp b/include/rive/core/binary_reader.hpp index 9cc6c2b..69e37c1 100644 --- a/include/rive/core/binary_reader.hpp +++ b/include/rive/core/binary_reader.hpp
@@ -24,7 +24,7 @@ size_t lengthInBytes() const; std::string readString(); - Span<uint8_t> readBytes(); + Span<const uint8_t> readBytes(); double readFloat64(); float readFloat32(); uint8_t readByte();
diff --git a/include/rive/core/field_types/core_bytes_type.hpp b/include/rive/core/field_types/core_bytes_type.hpp index 834acb8..5f257b6 100644 --- a/include/rive/core/field_types/core_bytes_type.hpp +++ b/include/rive/core/field_types/core_bytes_type.hpp
@@ -9,7 +9,7 @@ class CoreBytesType { public: static const int id = 1; - static Span<uint8_t> deserialize(BinaryReader& reader); + static Span<const uint8_t> deserialize(BinaryReader& reader); }; } // namespace rive #endif \ No newline at end of file
diff --git a/include/rive/generated/assets/file_asset_contents_base.hpp b/include/rive/generated/assets/file_asset_contents_base.hpp index 268976d..e5db01b 100644 --- a/include/rive/generated/assets/file_asset_contents_base.hpp +++ b/include/rive/generated/assets/file_asset_contents_base.hpp
@@ -27,7 +27,7 @@ static const uint16_t bytesPropertyKey = 212; public: - virtual void decodeBytes(const Span<uint8_t>& value) = 0; + virtual void decodeBytes(Span<const uint8_t> value) = 0; virtual void copyBytes(const FileAssetContentsBase& object) = 0; Core* clone() const override;
diff --git a/include/rive/generated/shapes/mesh_base.hpp b/include/rive/generated/shapes/mesh_base.hpp index d9c8276..f565213 100644 --- a/include/rive/generated/shapes/mesh_base.hpp +++ b/include/rive/generated/shapes/mesh_base.hpp
@@ -29,7 +29,7 @@ static const uint16_t triangleIndexBytesPropertyKey = 223; public: - virtual void decodeTriangleIndexBytes(const Span<uint8_t>& value) = 0; + virtual void decodeTriangleIndexBytes(Span<const uint8_t> value) = 0; virtual void copyTriangleIndexBytes(const MeshBase& object) = 0; Core* clone() const override;
diff --git a/include/rive/shapes/mesh.hpp b/include/rive/shapes/mesh.hpp index de6828c..7816827 100644 --- a/include/rive/shapes/mesh.hpp +++ b/include/rive/shapes/mesh.hpp
@@ -13,7 +13,7 @@ StatusCode onAddedDirty(CoreContext* context) override; void markDrawableDirty(); void addVertex(MeshVertex* vertex); - void decodeTriangleIndexBytes(const Span<uint8_t>& value) override; + void decodeTriangleIndexBytes(Span<const uint8_t> value) override; void copyTriangleIndexBytes(const MeshBase& object) override; #ifdef TESTING std::vector<MeshVertex*>& vertices() { return m_Vertices; }
diff --git a/src/assets/file_asset_contents.cpp b/src/assets/file_asset_contents.cpp index 857f8f1..e12c804 100644 --- a/src/assets/file_asset_contents.cpp +++ b/src/assets/file_asset_contents.cpp
@@ -15,7 +15,7 @@ return Super::import(importStack); } -void FileAssetContents::decodeBytes(const Span<uint8_t>& value) { +void FileAssetContents::decodeBytes(Span<const uint8_t> value) { m_Bytes = std::vector(value.begin(), value.end()); } @@ -24,4 +24,6 @@ assert(false); } -const std::vector<uint8_t>& FileAssetContents::bytes() const { return m_Bytes; } \ No newline at end of file +const Span<const uint8_t> FileAssetContents::bytes() const { + return Span<const uint8_t>(&m_Bytes[0], m_Bytes.size()); +} \ No newline at end of file
diff --git a/src/core/binary_reader.cpp b/src/core/binary_reader.cpp index 59004ec..d16ee13 100644 --- a/src/core/binary_reader.cpp +++ b/src/core/binary_reader.cpp
@@ -51,15 +51,15 @@ return std::string(rawValue.data(), length); } -Span<uint8_t> BinaryReader::readBytes() { +Span<const uint8_t> BinaryReader::readBytes() { uint64_t length = readVarUint64(); if (didOverflow()) { - return Span<uint8_t>(m_Position, 0); + return Span<const uint8_t>(m_Position, 0); } uint8_t* start = m_Position; m_Position += length; - return Span<uint8_t>(start, length); + return Span<const uint8_t>(start, length); } double BinaryReader::readFloat64() {
diff --git a/src/core/field_types/core_bytes_type.cpp b/src/core/field_types/core_bytes_type.cpp index 9a78bd2..8ec41bc 100644 --- a/src/core/field_types/core_bytes_type.cpp +++ b/src/core/field_types/core_bytes_type.cpp
@@ -3,6 +3,6 @@ using namespace rive; -Span<uint8_t> CoreBytesType::deserialize(BinaryReader& reader) { +Span<const uint8_t> CoreBytesType::deserialize(BinaryReader& reader) { return reader.readBytes(); } \ No newline at end of file
diff --git a/src/importers/file_asset_importer.cpp b/src/importers/file_asset_importer.cpp index a60dd29..d8488fe 100644 --- a/src/importers/file_asset_importer.cpp +++ b/src/importers/file_asset_importer.cpp
@@ -2,6 +2,8 @@ #include "rive/assets/file_asset_contents.hpp" #include "rive/assets/file_asset.hpp" #include "rive/file_asset_resolver.hpp" +#include "rive/span.hpp" +#include <cstdint> using namespace rive; @@ -10,8 +12,8 @@ m_FileAsset(fileAsset), m_FileAssetResolver(assetResolver) {} void FileAssetImporter::loadContents(const FileAssetContents& contents) { - const std::vector<uint8_t>& data = contents.bytes(); - if (m_FileAsset->decode(&data[0], data.size())) { + Span<const uint8_t> data = contents.bytes(); + if (m_FileAsset->decode(data.begin(), data.size())) { m_LoadedContents = true; } }
diff --git a/src/shapes/mesh.cpp b/src/shapes/mesh.cpp index 686f60b..b72a515 100644 --- a/src/shapes/mesh.cpp +++ b/src/shapes/mesh.cpp
@@ -23,7 +23,7 @@ return StatusCode::Ok; } -void Mesh::decodeTriangleIndexBytes(const Span<uint8_t>& value) { +void Mesh::decodeTriangleIndexBytes(Span<const uint8_t> value) { // decode the triangle index bytes }