Arcane  4.2.3.0
Developer documentation
Loading...
Searching...
No Matches
SerializerExtension.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* SerializerExtension.cc (C) 2000-2026 */
9/* */
10/* Extension of the serializer with support of multidimensional arrays. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arccore/serialize/SerializerExtension.h"
15
16#include "arccore/base/Float128.h"
17#include "arccore/base/Float16.h"
18#include "arccore/base/Int128.h"
19#include "arccore/base/BFloat16.h"
20#include "arccore/base/MDSpan.h"
21#include "arccore/common/NumArray.h"
22#include "arccore/collections/Array2.h"
23
24/*---------------------------------------------------------------------------*/
25/*---------------------------------------------------------------------------*/
26
27namespace Arcane
28{
29
30/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
32
35{
36 // size of each String + size of array.
37 m_serializer->reserveInt64(values.size() + 1);
38 for (const String& elem : values) {
39 m_serializer->reserveSpan(elem.bytes());
40 }
41}
42
43/*---------------------------------------------------------------------------*/
44/*---------------------------------------------------------------------------*/
45
47putArray(Span<const String> values) const
48{
49 m_serializer->putInt64(values.size());
50 for (const String& elem : values) {
51 m_serializer->putInt64(elem.length());
52 m_serializer->putSpan(elem.bytes());
53 }
54}
55
56/*---------------------------------------------------------------------------*/
57/*---------------------------------------------------------------------------*/
58
60getArray(Array<String>& values) const
61{
62 const Int64 size_array = m_serializer->getInt64();
63 values.resize(size_array);
64 for (Int64 i = 0; i < size_array; ++i) {
65 const Int64 len = m_serializer->getInt64();
66 UniqueArray<Byte> bytes(len);
67 m_serializer->getSpan(bytes);
68 values[i] = String(bytes.span());
69 }
70}
71
72/*---------------------------------------------------------------------------*/
73/*---------------------------------------------------------------------------*/
74
75/*---------------------------------------------------------------------------*/
76/*---------------------------------------------------------------------------*/
77
78// Explicit instantiation to check compilation
85
92
93/*---------------------------------------------------------------------------*/
94/*---------------------------------------------------------------------------*/
95
96} // namespace Arcane
97
98/*---------------------------------------------------------------------------*/
99/*---------------------------------------------------------------------------*/
Types and functions associated with the MDSpan class.
Class representing a classic 2D array.
Base class for 1D data vectors.
void resize(Int64 s)
Changes the number of elements in the array to s.
Base class for multidimensional views.
Multi-dimensional arrays for numerical types accessible on accelerators.
void getSpan(Span2< Type > values) const
Retrieve the array values.
void reserveArray(Span2< const Type > values) const
Reserve to save the number of elements and the values elements.
void putArray(Span2< const Type > values) const
Save the number of elements and the values elements.
void reserveSpan(Span2< const Type > values) const
Reserve for a view of values elements.
void getArray(Array2< Type > &values) const
Resize and fill values.
void putSpan(Span2< const Type > values) const
Add the array values.
View for a 2D array whose size is an 'Int64'.
Definition Span2.h:320
constexpr __host__ __device__ SizeType size() const noexcept
Returns the size of the array.
Definition Span.h:325
View of an array of elements of type T.
Definition Span.h:633
1D data vector with value semantics (STL style).
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int64_t Int64
Signed integer type of 64 bits.