Ice 3.8
C++ API Reference
Loading...
Searching...
No Matches
SlicedData.h
1// Copyright (c) ZeroC, Inc.
2
3#ifndef ICE_SLICED_DATA_H
4#define ICE_SLICED_DATA_H
5
6#include "Config.h"
7#include "SlicedDataF.h"
8#include "Value.h"
9
10#include <cassert>
11#include <string>
12
13#if defined(__clang__)
14# pragma clang diagnostic push
15# pragma clang diagnostic ignored "-Wshadow-field-in-constructor"
16#elif defined(__GNUC__)
17# pragma GCC diagnostic push
18# pragma GCC diagnostic ignored "-Wshadow"
19#endif
20
21namespace Ice
22{
23 /// Encapsulates the details of a class slice with an unknown type.
24 /// @headerfile Ice/Ice.h
25 struct SliceInfo
26 {
27 /// The Slice type ID for this slice. It's empty when the compact ID is set (not `-1`).
28 const std::string typeId;
29
30 /// The Slice compact type ID for this slice. No compact ID is encoded as `-1`.
31 const int compactId;
32
33 /// The encoded bytes for this slice, including the leading size integer.
34 const std::vector<std::byte> bytes;
35
36 /// The class instances referenced by this slice.
37 std::vector<ValuePtr> instances;
38
39 /// Whether or not the slice contains optional members.
41
42 /// Whether or not this is the last slice.
43 const bool isLastSlice;
44
45 /// Constructs a new SliceInfo instance.
46 /// @param typeId The Slice type ID for this slice.
47 /// @param compactId The Slice compact type ID for this slice.
48 /// @param bytes The encoded bytes for this slice.
49 /// @param hasOptionalMembers Whether or not the slice contains optional members.
50 /// @param isLastSlice Whether or not this is the last slice.
52 std::string typeId,
53 int compactId,
54 std::vector<std::byte> bytes,
56 bool isLastSlice) noexcept
57 : typeId(std::move(typeId)),
59 bytes(std::move(bytes)),
62 {
63 if (compactId == -1)
64 {
65 assert(!this->typeId.empty());
66 }
67 else
68 {
69 assert(this->typeId.empty());
70 }
71 }
72 };
73
74 /// Holds class slices that cannot be unmarshaled because their types are not known locally.
75 /// @headerfile Ice/Ice.h
76 class ICE_API SlicedData final
77 {
78 public:
79 /// Constructs a SlicedData instance with the given slices.
80 /// @param slices The slices of the unknown class.
82
83 /// The slices of the unknown class.
85
86 /// Clears the slices to break potential cyclic references.
87 void clear();
88 };
89
90 /// Represents an instance of an unknown class.
91 /// @headerfile Ice/Ice.h
92 class ICE_API UnknownSlicedValue final : public Value
93 {
94 public:
95 /// Constructs the placeholder instance.
96 /// @param unknownTypeId The Slice type ID of the unknown value.
97 UnknownSlicedValue(std::string unknownTypeId) noexcept;
98
99 /// Returns the Slice type ID associated with this instance.
100 /// @return The type ID supplied to the constructor.
101 [[nodiscard]] const char* ice_id() const noexcept final;
102
103 /// Clones this object.
104 /// @return A new instance.
105 [[nodiscard]] UnknownSlicedValuePtr ice_clone() const
106 {
107 return std::static_pointer_cast<UnknownSlicedValue>(_iceCloneImpl());
108 }
109
110 void ice_printFields(std::ostream& os) const final;
111
112 private:
113 [[nodiscard]] ValuePtr _iceCloneImpl() const final;
114
115 std::string _unknownTypeId;
116 };
117}
118
119#if defined(__clang__)
120# pragma clang diagnostic pop
121#elif defined(__GNUC__)
122# pragma GCC diagnostic pop
123#endif
124
125#endif
void clear()
Clears the slices to break potential cyclic references.
const SliceInfoSeq slices
The slices of the unknown class.
Definition SlicedData.h:84
SlicedData(SliceInfoSeq slices) noexcept
Constructs a SlicedData instance with the given slices.
void ice_printFields(std::ostream &os) const final
Outputs the name and value of each field of this instance, including inherited fields,...
const char * ice_id() const noexcept final
Returns the Slice type ID associated with this instance.
UnknownSlicedValuePtr ice_clone() const
Clones this object.
Definition SlicedData.h:105
UnknownSlicedValue(std::string unknownTypeId) noexcept
Constructs the placeholder instance.
Value() noexcept=default
Default constructor.
std::vector< SliceInfoPtr > SliceInfoSeq
The slices of unknown types.
Definition SlicedDataF.h:17
std::shared_ptr< Value > ValuePtr
A shared pointer to a Value.
Definition ValueF.h:13
std::shared_ptr< UnknownSlicedValue > UnknownSlicedValuePtr
A shared pointer to an UnknownSlicedValue.
Definition SlicedDataF.h:27
The Ice RPC framework.
Definition SampleEvent.h:59
std::vector< ValuePtr > instances
The class instances referenced by this slice.
Definition SlicedData.h:37
SliceInfo(std::string typeId, int compactId, std::vector< std::byte > bytes, bool hasOptionalMembers, bool isLastSlice) noexcept
Constructs a new SliceInfo instance.
Definition SlicedData.h:51
const std::vector< std::byte > bytes
The encoded bytes for this slice, including the leading size integer.
Definition SlicedData.h:34
const bool hasOptionalMembers
Whether or not the slice contains optional members.
Definition SlicedData.h:40
const std::string typeId
The Slice type ID for this slice. It's empty when the compact ID is set (not -1).
Definition SlicedData.h:28
const bool isLastSlice
Whether or not this is the last slice.
Definition SlicedData.h:43
const int compactId
The Slice compact type ID for this slice. No compact ID is encoded as -1.
Definition SlicedData.h:31