14#include "arcane/core/ISerializedData.h"
18#include "arcane/utils/Ref.h"
19#include "arcane/utils/NotImplementedException.h"
20#include "arcane/utils/NotSupportedException.h"
21#include "arcane/utils/FatalErrorException.h"
22#include "arcane/utils/IHashAlgorithm.h"
23#include "arcane/utils/CheckedConvert.h"
24#include "arcane/utils/Array.h"
25#include "arcane/utils/ArrayShape.h"
27#include "arcane/core/ISerializer.h"
37 const Int64 SERIALIZE_MAGIC_NUMBER = 0x6b90ac81;
99 Int64 m_nb_base_element;
100 bool m_is_multi_size;
106 Int64 m_element_size;
116 void _copyExtentsToDimensions();
128, m_nb_base_element(0)
129, m_is_multi_size(false)
141: m_base_data_type(base_data_type)
142, m_memory_size(memory_size)
143, m_nb_dimension(nb_dimension)
144, m_nb_element(nb_element)
145, m_nb_base_element(nb_base_element)
146, m_is_multi_size(is_multi_size)
151 _copyExtentsToDimensions();
152 if (!is_multi_size &&
shape.nbDimension() == 0) {
153 if (nb_dimension == 1) {
154 m_shape.setNbDimension(1);
155 m_shape.setDimension(0, 1);
157 else if (nb_dimension > 1) {
158 m_shape.setNbDimension(nb_dimension - 1);
159 for (
Int32 i = 1; i < nb_dimension; ++i)
160 m_shape.setDimension(i - 1, CheckedConvert::toInt32(
extents[i]));
169_copyExtentsToDimensions()
172 m_dimensions.resize(n);
178 for (
Integer i = 0; i < n; ++i)
179 m_dimensions[i] =
static_cast<Int32>(m_extents[i]);
207 m_const_buffer = buffer;
208 m_stored_buffer.clear();
209 m_memory_size = buffer.size();
218 m_const_buffer = buffer;
220 m_stored_buffer.clear();
221 m_memory_size = buffer.size();
231 m_buffer = m_stored_buffer;
232 m_const_buffer = m_stored_buffer.view();
233 m_memory_size = size;
244 const Byte* ptr =
reinterpret_cast<const Byte*
>(m_dimensions.data());
273 case ISerializer::ModeReserve:
282 _serializeRead(sbuf);
299 if (magic_number != SERIALIZE_MAGIC_NUMBER)
300 ARCANE_FATAL(
"Bad magic number for SerializedData '{0}", magic_number);
304 ARCANE_FATAL(
"Bad magic number for SerializedData '{0}", magic_number);
310 m_nb_base_element = sbuf->
getInt64();
316 m_extents.
resize(dimensions_size);
318 _copyExtentsToDimensions();
322 std::array<Int32, ArrayShape::MAX_NB_DIMENSION> shape_dims_buf;
323 Span<Int32> shape_dims(shape_dims_buf.data(), shape_nb_dim);
328 m_stored_buffer.
resize(buffer_size);
329 sbuf->
getSpan(m_stored_buffer);
330 m_buffer = m_stored_buffer;
331 m_const_buffer = m_buffer;
346 if (m_extents.size() != m_dimensions.size())
347 ARCANE_FATAL(
"Incoherence between extents ({0}) and dimensions ({1})",
348 m_extents.size(), m_dimensions.size());
351 case ISerializer::ModeReserve:
354 sbuf->reserveInteger(1);
356 sbuf->reserveInteger(1);
359 sbuf->reserveInteger(1);
372 sbuf->
putInt64(SERIALIZE_MAGIC_NUMBER);
385 sbuf->
putInt32(m_shape.nbDimension());
386 sbuf->
putSpan(m_shape.dimensions());
388 sbuf->
putInt64(m_const_buffer.size());
399extern "C++" ARCANE_CORE_EXPORT
406 nb_base_element, is_multi_size, dimensions, shape);
412extern "C++" ARCANE_CORE_EXPORT
419 nb_base_element, is_multi_size, dimensions,
ArrayShape());
425extern "C++" ARCANE_CORE_EXPORT
#define ARCANE_THROW(exception_class,...)
Macro for throwing an exception with formatting.
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
#define ARCCORE_DEFINE_REFERENCE_COUNTED_INCLASS_METHODS()
Macro to define methods managing counters of references.
void setDimensions(Span< const Int32 > dims)
Sets the number and values of the dimensions.
void resize(Int64 s)
Changes the number of elements in the array to s.
Interface of a hashing algorithm.
virtual void computeHash64(Span< const Byte > input, ByteArray &output)
Calculates the hash value for the array input.
Interface of a serialized data.
void reserveInt64(Int64 n)
Reserve for n Int64.
void reserveInt32(Int64 n)
Reserve for n Int32.
virtual Integer getInteger()=0
Retrieve a size.
eMode
Serializer operating mode.
@ ModePut
The serializer expects reserve().
@ ModeGet
The serializer expects get().
virtual Int64 getInt64()=0
Retrieve a size.
virtual void putInteger(Integer value)=0
Add the integer value.
virtual eReadMode readMode() const =0
Read mode.
virtual void putInt32(Int32 value)=0
Add the integer value.
virtual void putSpan(Span< const Real > values)
Add the array values.
virtual eMode mode() const =0
Current operating mode.
@ ReadReplace
Replace current elements with those read.
@ ReadAdd
Add those read to the current elements.
virtual void getSpan(Span< Real > values)
Retrieve the array values.
virtual Int32 getInt32()=0
Retrieve an integer.
virtual void reserveSpan(eBasicDataType dt, Int64 n)=0
Reserves memory for n values of dt.
virtual void putInt64(Int64 value)=0
Add the integer value.
Exception when a function is not implemented.
Exception when an operation is not supported.
Reference to an instance.
Thread-safe implementation of a reference counter.
void serialize(ISerializer *buffer) override
Serialize the data for reading or writing.
void computeHash(IHashAlgorithm *algo, ByteArray &output) const override
Compute a hash key on this data.
Int64ConstArrayView extents() const override
Array containing the number of elements for each dimension.
Span< Byte > writableBytes() override
View of the serialized values.
void setConstBytes(Span< const Byte > bytes) override
Positions the serialized values for reading.
void allocateMemory(Int64 size) override
Allocates an array to hold the serialized elements.
Integer nbDimension() const override
Dimension. 0 for a scalar, 1 for a 1D array, ...
Span< const Byte > constBytes() const override
Serialized values.
void _serialize(ISerializer *sbuf) const
Int64 nbBaseElement() const override
Number of base elements.
void setBytes(Span< Byte > bytes) override
Positions the serialized values.
Span< Byte > bytes() override
Serialized values.
eDataType baseDataType() const override
Data type.
bool isMultiSize() const override
Indicates if it is a multi-size array. (only relevant if nbDimension()>1).
void setWritableBytes(Span< Byte > bytes) override
Positions the serialized values.
Int64 memorySize() const override
Indicates the number of bytes that must be allocated to store or read the data.
void setBytes(Span< const Byte > bytes) override
Positions the serialized values.
void setBuffer(ByteArrayView buffer) override
Positions the serialized values.
Int64 nbElement() const override
Number of elements.
Span< const Byte > bytes() const override
Serialized values.
ArrayShape shape() const override
Shape of the array associated with the data.
View of an array of elements of type T.
1D data vector with value semantics (STL style).
constexpr view_type smallView()
Constant view of this view.
constexpr ConstArrayView< value_type > constSmallView() const
Constant view of this view.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
ARCANE_DATATYPE_EXPORT Integer dataTypeSize(eDataType type)
Size of data type type (which must be different from DT_String).
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.
Ref< TrueType > createRef(Args &&... args)
Creates an instance of type TrueType with arguments Args and returns a reference to it.
ArrayView< Byte > ByteArrayView
C equivalent of a 1D array of characters.
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.
@ Int32
32-bit integer data type
@ Int64
64-bit integer data type
ConstArrayView< Int64 > Int64ConstArrayView
C equivalent of a 1D array of 64-bit integers.
Ref< ISerializedData > arcaneCreateEmptySerializedDataRef()
Creates serialized data.
ConstArrayView< Byte > ByteConstArrayView
C equivalent of a 1D array of characters.
unsigned char Byte
Type of a byte.
@ DT_Unknown
Unknown or uninitialized data type.
std::int32_t Int32
Signed integer type of 32 bits.