Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use bytes for raw data #148

Merged
merged 2 commits into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cesium3DTiles/include/Cesium3DTiles/ExternalTilesetContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <gsl/span>
#include <memory>
#include <vector>
#include <cstddef>
#include <spdlog/fwd.h>

namespace Cesium3DTiles {
Expand Down Expand Up @@ -47,7 +48,7 @@ namespace Cesium3DTiles {
const glm::dmat4& tileTransform,
TileRefine tileRefine,
const std::string& url,
const gsl::span<const uint8_t>& data
const gsl::span<const std::byte>& data
);
};

Expand Down
3 changes: 2 additions & 1 deletion Cesium3DTiles/include/Cesium3DTiles/GltfContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <glm/mat4x4.hpp>
#include <gsl/span>
#include <spdlog/fwd.h>
#include <cstddef>

namespace Cesium3DTiles {

Expand Down Expand Up @@ -42,7 +43,7 @@ namespace Cesium3DTiles {
static std::unique_ptr<TileContentLoadResult> load(
std::shared_ptr<spdlog::logger> pLogger,
const std::string& url,
const gsl::span<const uint8_t>& data
const gsl::span<const std::byte>& data
);

public:
Expand Down
3 changes: 2 additions & 1 deletion Cesium3DTiles/include/Cesium3DTiles/TileContentFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <memory>
#include <optional>
#include <unordered_map>
#include <cstddef>

namespace Cesium3DTiles {
class TileContent;
Expand Down Expand Up @@ -91,7 +92,7 @@ namespace Cesium3DTiles {
const TileContentLoadInput& input);

private:
static std::optional<std::string> getMagic(const gsl::span<const uint8_t>& data);
static std::optional<std::string> getMagic(const gsl::span<const std::byte>& data);

static std::unordered_map<std::string, std::shared_ptr<TileContentLoader>> _loadersByMagic;
static std::unordered_map<std::string, std::shared_ptr<TileContentLoader>> _loadersByContentType;
Expand Down
7 changes: 4 additions & 3 deletions Cesium3DTiles/include/Cesium3DTiles/TileContentLoadInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <gsl/span>

#include <memory>
#include <cstddef>

namespace Cesium3DTiles
{
Expand Down Expand Up @@ -63,7 +64,7 @@ namespace Cesium3DTiles
*/
TileContentLoadInput(
const std::shared_ptr<spdlog::logger> pLogger_,
const gsl::span<const uint8_t>& data_,
const gsl::span<const std::byte>& data_,
const std::string& contentType_,
const std::string& url_,
const Tile& tile_
Expand Down Expand Up @@ -103,7 +104,7 @@ namespace Cesium3DTiles
*/
TileContentLoadInput(
const std::shared_ptr<spdlog::logger> pLogger_,
const gsl::span<const uint8_t>& data_,
const gsl::span<const std::byte>& data_,
const std::string& contentType_,
const std::string& url_,
const TileContext& context_,
Expand Down Expand Up @@ -141,7 +142,7 @@ namespace Cesium3DTiles
* does not succeed, it will try to determine the type based on the
* `contentType` field.
*/
gsl::span<const uint8_t> data;
gsl::span<const std::byte> data;

/**
* @brief The content type.
Expand Down
9 changes: 5 additions & 4 deletions Cesium3DTiles/src/Batched3DModelContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "Cesium3DTiles/spdlog-cesium.h"
#include <rapidjson/document.h>
#include <stdexcept>
#include <cstddef>

namespace Cesium3DTiles {

Expand Down Expand Up @@ -41,7 +42,7 @@ namespace Cesium3DTiles {
void parseFeatureTableJsonData(
const std::shared_ptr<spdlog::logger>& pLogger,
CesiumGltf::Model& gltf,
const gsl::span<const uint8_t>& featureTableJsonData)
const gsl::span<const std::byte>& featureTableJsonData)
{
rapidjson::Document document;
document.Parse(reinterpret_cast<const char*>(featureTableJsonData.data()), featureTableJsonData.size());
Expand Down Expand Up @@ -80,7 +81,7 @@ namespace Cesium3DTiles {
std::unique_ptr<TileContentLoadResult> Batched3DModelContent::load(
std::shared_ptr<spdlog::logger> pLogger,
const std::string& url,
const gsl::span<const uint8_t>& data
const gsl::span<const std::byte>& data
) {
// TODO: actually use the b3dm payload
if (data.size() < sizeof(B3dmHeader)) {
Expand Down Expand Up @@ -147,7 +148,7 @@ namespace Cesium3DTiles {
throw std::runtime_error("The B3DM is invalid because the start of the glTF model is after the end of the entire B3DM.");
}

gsl::span<const uint8_t> glbData = data.subspan(glbStart, glbEnd - glbStart);
gsl::span<const std::byte> glbData = data.subspan(glbStart, glbEnd - glbStart);
std::unique_ptr<TileContentLoadResult> pResult = GltfContent::load(
pLogger,
url,
Expand All @@ -156,7 +157,7 @@ namespace Cesium3DTiles {

if (pResult->model && header.featureTableJsonByteLength > 0) {
CesiumGltf::Model& gltf = pResult->model.value();
gsl::span<const uint8_t> featureTableJsonData = data.subspan(headerLength, header.featureTableJsonByteLength);
gsl::span<const std::byte> featureTableJsonData = data.subspan(headerLength, header.featureTableJsonByteLength);
parseFeatureTableJsonData(pLogger, gltf, featureTableJsonData);
}

Expand Down
3 changes: 2 additions & 1 deletion Cesium3DTiles/src/Batched3DModelContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "Cesium3DTiles/TileContentLoader.h"
#include <memory>
#include <string>
#include <cstddef>
#include <spdlog/fwd.h>

namespace Cesium3DTiles {
Expand Down Expand Up @@ -42,7 +43,7 @@ namespace Cesium3DTiles {
static std::unique_ptr<TileContentLoadResult> load(
std::shared_ptr<spdlog::logger> pLogger,
const std::string& url,
const gsl::span<const uint8_t>& data
const gsl::span<const std::byte>& data
);
};

Expand Down
7 changes: 4 additions & 3 deletions Cesium3DTiles/src/CompositeContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "Cesium3DTiles/TileContentFactory.h"
#include <rapidjson/document.h>
#include <stdexcept>
#include <cstddef>

namespace {
#pragma pack(push, 1)
Expand Down Expand Up @@ -41,7 +42,7 @@ namespace Cesium3DTiles {
* @param derivedData The data for the result.
* @return The result.
*/
TileContentLoadInput derive(const TileContentLoadInput& input, const gsl::span<const uint8_t>& derivedData) {
TileContentLoadInput derive(const TileContentLoadInput& input, const gsl::span<const std::byte>& derivedData) {
return TileContentLoadInput(
input.pLogger,
derivedData,
Expand All @@ -62,7 +63,7 @@ namespace Cesium3DTiles {
std::unique_ptr<TileContentLoadResult> CompositeContent::load(
const TileContentLoadInput& input) {
const std::shared_ptr<spdlog::logger>& pLogger = input.pLogger;
const gsl::span<const uint8_t>& data = input.data;
const gsl::span<const std::byte>& data = input.data;
const std::string& url = input.url;

if (data.size() < sizeof(CmptHeader)) {
Expand Down Expand Up @@ -102,7 +103,7 @@ namespace Cesium3DTiles {
break;
}

gsl::span<const uint8_t> innerData(data.data() + pos, pInner->byteLength);
gsl::span<const std::byte> innerData(data.data() + pos, pInner->byteLength);

std::unique_ptr<TileContentLoadResult> pInnerLoadResult = TileContentFactory::createContent(
derive(input, innerData)
Expand Down
3 changes: 2 additions & 1 deletion Cesium3DTiles/src/ExternalTilesetContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "Cesium3DTiles/Tileset.h"
#include "CesiumUtility/Uri.h"
#include <rapidjson/document.h>
#include <cstddef>

namespace Cesium3DTiles {

Expand All @@ -18,7 +19,7 @@ namespace Cesium3DTiles {
const glm::dmat4& tileTransform,
TileRefine tileRefine,
const std::string& url,
const gsl::span<const uint8_t>& data
const gsl::span<const std::byte>& data
) {
std::unique_ptr<TileContentLoadResult> pResult = std::make_unique<TileContentLoadResult>();

Expand Down
2 changes: 1 addition & 1 deletion Cesium3DTiles/src/GltfContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Cesium3DTiles {
/*static*/ std::unique_ptr<TileContentLoadResult> GltfContent::load(
std::shared_ptr<spdlog::logger> pLogger,
const std::string& url,
const gsl::span<const uint8_t>& data
const gsl::span<const std::byte>& data
) {
std::unique_ptr<TileContentLoadResult> pResult = std::make_unique<TileContentLoadResult>();

Expand Down
Loading