Skip to content

Commit

Permalink
Use bytes for raw data
Browse files Browse the repository at this point in the history
  • Loading branch information
javagl committed Mar 4, 2021
1 parent e9cc884 commit 95ff93a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Source/Cesium/Private/CesiumGltfComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

#define STB_IMAGE_RESIZE_IMPLEMENTATION
#include <stb_image_resize.h>
#include <cstddef>

using namespace CesiumGltf;

Expand Down Expand Up @@ -1229,7 +1230,7 @@ void UCesiumGltfComponent::ModelRequestComplete(FHttpRequestPtr request, FHttpRe
// TODO: is it reasonable to use the global thread pool for this?
TFuture<void> future = Async(EAsyncExecution::ThreadPool, [this, content]
{
gsl::span<const uint8_t> data(static_cast<const uint8_t*>(content.GetData()), content.Num());
gsl::span<const std::byte> data(reinterpret_cast<const std::byte*>(content.GetData()), content.Num());
std::unique_ptr<CesiumGltf::ModelReaderResult> pLoadResult = std::make_unique<CesiumGltf::ModelReaderResult>(std::move(CesiumGltf::readModel(data)));

if (!pLoadResult->warnings.empty()) {
Expand Down
9 changes: 5 additions & 4 deletions Source/Cesium/Private/UnrealAssetAccessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "UnrealConversions.h"
#include <set>
#include <optional>
#include <cstddef>

static CesiumAsync::HttpHeaders parseHeaders(const TArray<FString>& unrealHeaders) {
CesiumAsync::HttpHeaders result;
Expand Down Expand Up @@ -48,9 +49,9 @@ class UnrealAssetResponse : public CesiumAsync::IAssetResponse {
return this->_headers;
}

virtual gsl::span<const uint8_t> data() const override {
virtual gsl::span<const std::byte> data() const override {
const TArray<uint8>& content = this->_pResponse->GetContent();
return gsl::span(static_cast<const uint8_t*>(content.GetData()), content.Num());
return gsl::span(reinterpret_cast<const std::byte*>(content.GetData()), content.Num());
}

private:
Expand Down Expand Up @@ -133,7 +134,7 @@ CesiumAsync::Future<std::shared_ptr<CesiumAsync::IAssetRequest>> UnrealAssetAcce
const CesiumAsync::AsyncSystem& asyncSystem,
const std::string& url,
const std::vector<CesiumAsync::IAssetAccessor::THeader>& headers,
const gsl::span<const uint8_t>& contentPayload
const gsl::span<const std::byte>& contentPayload
) {
return asyncSystem.createFuture<std::shared_ptr<CesiumAsync::IAssetRequest>>([
&url,
Expand All @@ -151,7 +152,7 @@ CesiumAsync::Future<std::shared_ptr<CesiumAsync::IAssetRequest>> UnrealAssetAcce

pRequest->AppendToHeader(TEXT("User-Agent"), TEXT("Cesium for Unreal"));

pRequest->SetContent(TArray<uint8>(contentPayload.data(), contentPayload.size()));
pRequest->SetContent(TArray<uint8>(reinterpret_cast<const uint8*>(contentPayload.data()), contentPayload.size()));

pRequest->OnProcessRequestComplete().BindLambda([promise](FHttpRequestPtr pRequest, FHttpResponsePtr pResponse, bool connectedSuccessfully) {
if (connectedSuccessfully) {
Expand Down
3 changes: 2 additions & 1 deletion Source/Cesium/Public/UnrealAssetAccessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "CesiumAsync/IAssetAccessor.h"
#include "CesiumAsync/AsyncSystem.h"
#include <cstddef>

class CESIUM_API UnrealAssetAccessor : public CesiumAsync::IAssetAccessor
{
Expand All @@ -18,7 +19,7 @@ class CESIUM_API UnrealAssetAccessor : public CesiumAsync::IAssetAccessor
const CesiumAsync::AsyncSystem& asyncSystem,
const std::string& url,
const std::vector<CesiumAsync::IAssetAccessor::THeader>& headers,
const gsl::span<const uint8_t>& contentPayload
const gsl::span<const std::byte>& contentPayload
) override;

virtual void tick() noexcept override;
Expand Down

0 comments on commit 95ff93a

Please sign in to comment.