mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-08-23 20:22:08 +00:00
Bug: dawn:1480 Change-Id: I858111f62be457c2e7cd5017bbf4c10e76395e83 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/95340 Reviewed-by: Loko Kung <lokokung@google.com> Commit-Queue: Austin Eng <enga@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com>
62 lines
1.7 KiB
C++
62 lines
1.7 KiB
C++
// Copyright 2022 The Dawn Authors
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
#include "dawn/native/stream/Stream.h"
|
|
|
|
#include <string>
|
|
|
|
namespace dawn::native::stream {
|
|
|
|
template <>
|
|
void Stream<std::string>::Write(Sink* s, const std::string& t) {
|
|
StreamIn(s, t.length());
|
|
size_t size = t.length() * sizeof(char);
|
|
if (size > 0) {
|
|
void* ptr = s->GetSpace(size);
|
|
memcpy(ptr, t.data(), size);
|
|
}
|
|
}
|
|
|
|
template <>
|
|
MaybeError Stream<std::string>::Read(Source* s, std::string* t) {
|
|
size_t length;
|
|
DAWN_TRY(StreamOut(s, &length));
|
|
const void* ptr;
|
|
DAWN_TRY(s->Read(&ptr, length));
|
|
*t = std::string(static_cast<const char*>(ptr), length);
|
|
return {};
|
|
}
|
|
|
|
template <>
|
|
void Stream<std::string_view>::Write(Sink* s, const std::string_view& t) {
|
|
StreamIn(s, t.length());
|
|
size_t size = t.length() * sizeof(char);
|
|
if (size > 0) {
|
|
void* ptr = s->GetSpace(size);
|
|
memcpy(ptr, t.data(), size);
|
|
}
|
|
}
|
|
|
|
template <>
|
|
void Stream<std::wstring_view>::Write(Sink* s, const std::wstring_view& t) {
|
|
StreamIn(s, t.length());
|
|
size_t size = t.length() * sizeof(wchar_t);
|
|
if (size > 0) {
|
|
void* ptr = s->GetSpace(size);
|
|
memcpy(ptr, t.data(), size);
|
|
}
|
|
}
|
|
|
|
} // namespace dawn::native::stream
|