Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
ISerializedData.h
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/* ISerializedData.h (C) 2000-2025 */
9/* */
10/* Interface of a serialized data. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_ISERIALIZEDDATA_H
13#define ARCANE_CORE_ISERIALIZEDDATA_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
18
19/*---------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
22namespace Arcane
23{
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28/*!
29 * \internal
30 * \brief Interface of a serialized data.
31 *
32 * A data (IData) is serialized into an instance of this class.
33 *
34 * Regardless of the data type, the serialized type must be
35 * a base type among the following: DT_Byte, DT_Int16, DT_Int32, DT_Int64, DT_Real.
36 *
37 * An instance of this class is only valid as long as the reference data
38 * is not modified.
39 *
40 * To serialize a data \a data for writing:
41 * \code
42 * IData* data = ...;
43 * ISerializedData* sdata = data->createSerializedData();
44 * // sdata->constBytes() contains the serialized data.
45 * Span<const Byte> buf(sdata->constBytes());
46 * std::cout.write(reinterpret_cast<const char*>(buf.data()),buf.size());
47 * \endcode
48 *
49 * To serialize a data \a data for reading:
50 * \code
51 * IData* data = ...
52 * // Create an instance of an ISerializedData.
53 * Ref<ISerializedData> sdata = arcaneCreateSerializedDataRef(...);
54 * data->allocateBufferForSerializedData(sdata);
55 * // Fills sdata->writableBytes() from your source
56 * Span<Byte> buf(sdata->writableBytes());
57 * std::cin.read(reinterpret_cast<char*>(buf.data()),buf.size());
58 * // Assigns the value to \a data
59 * data->assignSerializedData(sdata);
60 * \endcode
61 */
62class ARCANE_CORE_EXPORT ISerializedData
63{
65
66 public:
67
68 //! Frees resources
69 virtual ~ISerializedData() = default;
70
71 public:
72
73 //! Data type
74 virtual eDataType baseDataType() const = 0;
75
76 //! Dimension. 0 for a scalar, 1 for a 1D array, ...
77 virtual Integer nbDimension() const = 0;
78
79 //! Number of elements
80 virtual Int64 nbElement() const = 0;
81
82 //! Number of base elements
83 virtual Int64 nbBaseElement() const = 0;
84
85 //! Indicates if it is a multi-size array. (only relevant if nbDimension()>1)
86 virtual bool isMultiSize() const = 0;
87
88 //! Indicates the number of bytes that must be allocated to store or read the data
89 virtual Int64 memorySize() const = 0;
90
91 //! Array containing the number of elements for each dimension
92 virtual Int64ConstArrayView extents() const = 0;
93
94 //! Shape of the array associated with the data
95 virtual ArrayShape shape() const = 0;
96
97 //! Serialized values.
98 virtual Span<const Byte> constBytes() const = 0;
99
100 /*!
101 * \brief View of the serialized values
102 *
103 * \warning This method returns a non-empty view only if one
104 * has called allocateMemory() or setWritableBytes(Span<Byte>) beforehand.
105 */
107
108 /*!
109 * \brief Positions the serialized values.
110 *
111 * The view \a bytes must remain valid as long as this instance is used.
112 */
114
115 /*!
116 * \brief Positions the serialized values for reading
117 *
118 * The view \a bytes must remain valid as long as this instance is used.
119 */
121
122 /*!
123 * \brief Allocates an array to hold the serialized elements.
124 *
125 * After calling this method, it is possible to retrieve a
126 * view of the serialized values via writableBytes() or constBytes().
127 */
128 virtual void allocateMemory(Int64 size) = 0;
129
130 public:
131
132 /*!
133 * \brief Serialize the data for reading or writing
134 */
135 virtual void serialize(ISerializer* buffer) = 0;
136
137 /*!
138 * \brief Serialize the data for reading
139 */
140 virtual void serialize(ISerializer* buffer) const = 0;
141
142 public:
143
144 /*!
145 * \brief Compute a hash key on this data.
146 *
147 * The key is added to \a output. The length of the key depends
148 * on the algorithm used.
149 */
150 virtual void computeHash(IHashAlgorithm* algo, ByteArray& output) const = 0;
151
152 public:
153
154 /*!
155 * \brief Serialized values.
156 * \deprecated Use bytes() instead.
157 */
158 ARCANE_DEPRECATED_2018_R("Use method 'writableBytes()' or 'constBytes()' instead")
159 virtual ByteConstArrayView buffer() const = 0;
160
161 /*!
162 * \brief Serialized values.
163 * \deprecated Use bytes() instead.
164 */
165 ARCANE_DEPRECATED_2018_R("Use method 'writableBytes()' or 'constBytes()' instead")
166 virtual ByteArrayView buffer() = 0;
167
168 //! Serialized values.
169 ARCCORE_DEPRECATED_2021("Use method 'writableBytes()' or 'constBytes()' instead")
170 virtual Span<const Byte> bytes() const = 0;
171
172 /*!
173 * \brief Positions the serialized values.
174 *
175 * The array \a buffer must not be modified
176 * as long as this instance is used.
177 * \deprecated Use setBytes() instead.
178 */
179 ARCCORE_DEPRECATED_2021("Use method 'setWritableBytes()' instead")
180 virtual void setBuffer(ByteArrayView buffer) = 0;
181
182 /*!
183 * \brief Positions the serialized values.
184 *
185 * The array \a buffer must not be modified
186 * as long as this instance is used.
187 * \deprecated Use setBytes() instead.
188 */
189 ARCCORE_DEPRECATED_2021("Use method 'setConstBytes()' instead")
190 virtual void setBuffer(ByteConstArrayView buffer) = 0;
191
192 /*!
193 * \brief Positions the serialized values.
194 *
195 * The array \a bytes must not be modified
196 * as long as this instance is used.
197 */
198 ARCCORE_DEPRECATED_2021("Use method 'setWritableBytes()' instead")
199 virtual void setBytes(Span<Byte> bytes) = 0;
200
201 /*!
202 * \brief Positions the serialized values.
203 *
204 * The array \a bytes must not be modified
205 * as long as this instance is used.
206 */
207 ARCCORE_DEPRECATED_2021("Use method 'setConstBytes()' instead")
208 virtual void setBytes(Span<const Byte> bytes) = 0;
209
210 /*!
211 * \brief Serialized values
212 *
213 * \warning This method returns a non-empty view only if one
214 * has called setBytes(Span<Byte>) or allocateMemory().
215 */
216 ARCCORE_DEPRECATED_2021("Use method 'writableBytes()' or 'constBytes()' instead")
217 virtual Span<Byte> bytes() = 0;
218};
219
220/*---------------------------------------------------------------------------*/
221/*---------------------------------------------------------------------------*/
222
223/*!
224 * \brief Creates serialized data.
225 *
226 * The arrays \a dimensions and \a values are not duplicated and must not
227 * be modified as long as the serialized object is used.
228 *
229 * The type \a data_type must be a type among \a DT_Byte, \a DT_Int16, \a DT_Int32,
230 * \a DT_Int64 or DT_Real.
231 */
232extern "C++" ARCANE_CORE_EXPORT
234arcaneCreateSerializedDataRef(eDataType data_type, Int64 memory_size,
235 Integer nb_dim, Int64 nb_element, Int64 nb_base_element,
236 bool is_multi_size, Int64ConstArrayView dimensions);
237
238/*---------------------------------------------------------------------------*/
239/*---------------------------------------------------------------------------*/
240
241/*!
242 * \brief Creates serialized data.
243 *
244 * The arrays \a dimensions and \a values are not duplicated and must not
245 * be modified as long as the serialized object is used.
246 *
247 * The type \a data_type must be a type among \a DT_Byte, \a DT_Int16, \a DT_Int32,
248 * \a DT_Int64 or DT_Real.
249 */
250extern "C++" ARCANE_CORE_EXPORT
252arcaneCreateSerializedDataRef(eDataType data_type, Int64 memory_size,
253 Integer nb_dim, Int64 nb_element, Int64 nb_base_element,
254 bool is_multi_size, Int64ConstArrayView dimensions,
255 const ArrayShape& shape);
256
257/*---------------------------------------------------------------------------*/
258/*---------------------------------------------------------------------------*/
259
260/*!
261 * \brief Creates serialized data.
262 *
263 * The serialized data is empty. It can only be used after a
264 * call to ISerializedData::serialize() in ISerializer::ModePut mode.
265 */
266extern "C++" ARCANE_CORE_EXPORT
269
270/*---------------------------------------------------------------------------*/
271/*---------------------------------------------------------------------------*/
272
273} // End namespace Arcane
274
275/*---------------------------------------------------------------------------*/
276/*---------------------------------------------------------------------------*/
277
278#endif
Declarations of Arcane's general types.
#define ARCCORE_DECLARE_REFERENCE_COUNTED_INCLASS_METHODS()
Macro to declare the virtual methods managing reference counters.
Array shape.
Definition ArrayShape.h:42
Interface of a hashing algorithm.
virtual eDataType baseDataType() const =0
Data type.
virtual ArrayShape shape() const =0
Shape of the array associated with the data.
virtual Integer nbDimension() const =0
Dimension. 0 for a scalar, 1 for a 1D array, ...
virtual Int64 memorySize() const =0
Indicates the number of bytes that must be allocated to store or read the data.
virtual void allocateMemory(Int64 size)=0
Allocates an array to hold the serialized elements.
virtual void setWritableBytes(Span< Byte > bytes)=0
Positions the serialized values.
virtual void setConstBytes(Span< const Byte > bytes)=0
Positions the serialized values for reading.
virtual void serialize(ISerializer *buffer) const =0
Serialize the data for reading.
virtual void serialize(ISerializer *buffer)=0
Serialize the data for reading or writing.
ARCANE_DEPRECATED_2018_R("Use method 'writableBytes()' or 'constBytes()' instead") virtual ByteConstArrayView buffer() const =0
Serialized values.
virtual void computeHash(IHashAlgorithm *algo, ByteArray &output) const =0
Compute a hash key on this data.
virtual Span< Byte > writableBytes()=0
View of the serialized values.
virtual ~ISerializedData()=default
Frees resources.
virtual Span< const Byte > bytes() const =0
Serialized values.
virtual Int64 nbBaseElement() const =0
Number of base elements.
virtual Int64ConstArrayView extents() const =0
Array containing the number of elements for each dimension.
virtual Int64 nbElement() const =0
Number of elements.
virtual void setBytes(Span< Byte > bytes)=0
Positions the serialized values.
virtual void setBuffer(ByteArrayView buffer)=0
Positions the serialized values.
virtual Span< const Byte > constBytes() const =0
Serialized values.
virtual bool isMultiSize() const =0
Indicates if it is a multi-size array. (only relevant if nbDimension()>1).
Reference to an instance.
View of an array of elements of type T.
Definition Span.h:635
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Ref< ISerializedData > arcaneCreateSerializedDataRef(eDataType data_type, Int64 memory_size, Integer nb_dim, Int64 nb_element, Int64 nb_base_element, bool is_multi_size, Int64ConstArrayView dimensions)
Creates serialized data.
ArrayView< Byte > ByteArrayView
C equivalent of a 1D array of characters.
Definition UtilsTypes.h:447
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
Array< Byte > ByteArray
Dynamic one-dimensional array of characters.
Definition UtilsTypes.h:121
ConstArrayView< Int64 > Int64ConstArrayView
C equivalent of a 1D array of 64-bit integers.
Definition UtilsTypes.h:480
Ref< ISerializedData > arcaneCreateEmptySerializedDataRef()
Creates serialized data.
ConstArrayView< Byte > ByteConstArrayView
C equivalent of a 1D array of characters.
Definition UtilsTypes.h:476
unsigned char Byte
Type of a byte.
Definition BaseTypes.h:43
eDataType
Data type.
Definition DataTypes.h:41