CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
json_memory_marshal.h
1
5#pragma once
6
7#include <cstdint>
8
9#include <system/span.h>
10#include <cstring>
11
12namespace System {
13namespace Text {
14namespace Json {
15
18{
19public:
25 template <typename TFrom, typename TTo>
27 {
28 return ReadOnlySpan<TTo>((const TTo*)span.data_ptr(), span.get_Length() * sizeof(TFrom) / sizeof(TTo));
29 }
30
35 template <typename T>
36 static T Read(const ReadOnlySpan<uint8_t>& source)
37 {
38 T value = T();
39 std::memcpy(&value, source.data_ptr(), sizeof(T));
40 return value;
41 }
42
47 template <typename T>
48 static T Read(const Span<uint8_t>& source)
49 {
50 T value = T();
51 std::memcpy(&value, source.data_ptr(), sizeof(T));
52 return value;
53 }
54
59 template <typename T>
60 static void Write(const Span<uint8_t>& destination, T& value)
61 {
62 std::memcpy(destination.data_ptr(), &value, sizeof(T));
63 }
64};
65
66} // namespace Json
67} // namespace Text
68} // namespace System
Forward to use within Span class.
Definition: span.h:415
Represents a contiguous region of arbitrary memory similar to C++20's std::span.
Definition: span.h:375
Byte-span marshalling helpers used by the JSON reader/writer implementation.
Definition: json_memory_marshal.h:18
static void Write(const Span< uint8_t > &destination, T &value)
Writes a value of type T to the beginning of the specified byte span.
Definition: json_memory_marshal.h:60
static ReadOnlySpan< TTo > Cast(const ReadOnlySpan< TFrom > &span)
Casts a read-only span of one primitive type TFrom to another primitive type TTo.
Definition: json_memory_marshal.h:26
static T Read(const Span< uint8_t > &source)
Reads a value of type T from the beginning of the specified byte span.
Definition: json_memory_marshal.h:48
static T Read(const ReadOnlySpan< uint8_t > &source)
Reads a value of type T from the beginning of the specified byte span.
Definition: json_memory_marshal.h:36
@ Text
Defines color adjustment information for text.
Definition: db_command.h:9