PVData C++  8.0.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
serialize.h
1 /* serialize.h */
2 /*
3  * Copyright information and license terms for this software can be
4  * found in the file LICENSE that is included with the distribution
5  */
9 #ifndef SERIALIZE_H
10 #define SERIALIZE_H
11 
12 #include <epicsTypes.h>
13 
14 #include <pv/byteBuffer.h>
15 #include <pv/sharedPtr.h>
16 
17 #include <shareLib.h>
18 
19 #if defined(PVD_INTERNAL)
20 # define PVD_DEPRECATED(msg)
21 #elif __GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 5
22 # define PVD_DEPRECATED(msg) __attribute__((deprecated(msg)))
23 #else
24 # define PVD_DEPRECATED(msg) EPICS_DEPRECATED
25 #endif
26 
27 namespace epics { namespace pvData {
28 
29  class SerializableControl;
30  class DeserializableControl;
31  class Serializable;
32  class BitSetSerializable;
33  class SerializableArray;
34  class BitSet;
35  class Field;
36 
42  class epicsShareClass SerializableControl {
43  public:
51  virtual void flushSerializeBuffer() =0;
57  virtual void ensureBuffer(std::size_t size) =0;
58  virtual void alignBuffer(std::size_t alignment) PVD_DEPRECATED("Deprecated for lack of use") {}
73  virtual bool directSerialize(
74  ByteBuffer *existingBuffer,
75  const char* toSerialize,
76  std::size_t elementCount,
77  std::size_t elementSize) = 0;
83  virtual void cachedSerialize(
84  std::tr1::shared_ptr<const Field> const & field,
85  ByteBuffer* buffer) = 0;
86  };
87 
93  class epicsShareClass DeserializableControl {
94  public:
104  virtual void ensureData(std::size_t size) =0;
105  // Deprecated for lack of use
106  virtual void alignData(std::size_t alignment) PVD_DEPRECATED("Deprecated for lack of use") {};
121  virtual bool directDeserialize(
122  ByteBuffer *existingBuffer,
123  char* deserializeTo,
124  std::size_t elementCount,
125  std::size_t elementSize) = 0;
130  virtual std::tr1::shared_ptr<const Field> cachedDeserialize(
131  ByteBuffer* buffer) = 0;
132  };
133 
138  class epicsShareClass Serializable {
139  public:
143  virtual ~Serializable(){}
149  virtual void serialize(ByteBuffer *buffer,
150  SerializableControl *flusher) const = 0;
156  virtual void deserialize(ByteBuffer *buffer,
157  DeserializableControl *flusher) = 0;
158  };
159 
168  void epicsShareFunc serializeToVector(const Serializable *S,
169  int byteOrder,
171 
178  void epicsShareFunc deserializeFromBuffer(Serializable *S,
179  ByteBuffer& in);
180 
189  int byteOrder,
190  const std::vector<epicsUInt8>& in)
191  {
192  ByteBuffer B((char*)&in[0], in.size(), byteOrder); // we promise not the modify 'in'
193  deserializeFromBuffer(S, B);
194  }
195 
200  class epicsShareClass BitSetSerializable {
201  public:
212  virtual void serialize(ByteBuffer *buffer,
213  SerializableControl *flusher,BitSet *bitSet) const = 0;
220  virtual void deserialize(ByteBuffer *buffer,
221  DeserializableControl *flusher,BitSet *bitSet) = 0;
222  };
223 
224 
229  class epicsShareClass SerializableArray : public virtual Serializable {
230  public:
234  virtual ~SerializableArray(){}
243  virtual void serialize(
244  ByteBuffer *buffer,
245  SerializableControl *flusher,
246  std::size_t offset,
247  std::size_t count) const = 0;
248  };
249 
250 }}
251 #endif /* SERIALIZE_H */
valarray< size_t > size() const
void serializeToVector(const Serializable *S, int byteOrder, std::vector< epicsUInt8 > &out)
Push serialize and append to the provided byte vector. No caching is done. Only complete serializatio...
Callback class for serialization.
Definition: serialize.h:42
void deserializeFromVector(Serializable *S, int byteOrder, const std::vector< epicsUInt8 > &in)
deserializeFromBuffer Deserialize into S from provided vector
Definition: serialize.h:188
This class implements a Bytebuffer that is like the java.nio.ByteBuffer.
Definition: byteBuffer.h:236
constexpr iterator_traits< _InputIterator >::difference_type count(_InputIterator __first, _InputIterator __last, const _Tp &__value)
constexpr size_type size() const noexcept
virtual void serialize(ByteBuffer *buffer, SerializableControl *flusher) const =0
Callback class for deserialization.
Definition: serialize.h:93
void deserializeFromBuffer(Serializable *S, ByteBuffer &in)
deserializeFromBuffer Deserialize into S from provided vector
Class for serializing arrays.
Definition: serialize.h:229
Class for serializing bitSets.
Definition: serialize.h:200
Base class for serialization.
Definition: serialize.h:138
A vector of bits.
Definition: bitSet.h:56