src
copy_serializable.cpp
Go to the documentation of this file.
1
26
#include "
odva_ethernetip/serialization/copy_serializable.h
"
27
#include "
odva_ethernetip/serialization/serializable_buffer.h
"
28
#include "
odva_ethernetip/serialization/buffer_reader.h
"
29
#include "
odva_ethernetip/serialization/buffer_writer.h
"
30
31
namespace
eip
{
32
namespace
serialization {
33
34
void
copy_serializable
(
Serializable
& dst,
const
Serializable
& src)
35
{
36
// check if this is SerializableBuffer to avoid unnecessary copy
37
const
SerializableBuffer
* src_sb =
dynamic_cast<
const
SerializableBuffer
*
>
(&src);
38
SerializableBuffer
* dst_sb =
dynamic_cast<
SerializableBuffer
*
>
(&dst);
39
if
(src_sb)
40
{
41
if
(dst_sb)
42
{
43
(*dst_sb) = (*src_sb);
44
}
45
else
46
{
47
BufferReader
reader(src_sb->
getData
());
48
dst.
deserialize
(reader, src_sb->
getLength
());
49
}
50
return
;
51
}
52
else
if
(dst_sb)
53
{
54
// cannot serialize to a SerializableBuffer, since it will attempt not to
55
// copy the buffer but just return to it.
56
// This should never be required in practice. Not implementing yet
57
// TODO: fix if actually ever needed
58
throw
std::logic_error(
"Cannot get payload from Serializable to SerializableBuffer"
);
59
}
60
else
61
{
62
// must serialize and then deserialize again
63
size_t
length = src.
getLength
();
64
std::vector<char> buf(length);
65
BufferWriter
writer(buffer(buf));
66
src.
serialize
(writer);
67
BufferReader
reader(buffer(buf));
68
dst.
deserialize
(reader, length);
69
}
70
}
71
72
}
// namespace serialization
73
}
// namespace eip
eip::serialization::SerializableBuffer::getLength
virtual size_t getLength() const
Definition:
serializable_buffer.h:71
eip
Definition:
connection.h:41
eip::serialization::BufferWriter
Definition:
buffer_writer.h:44
eip::serialization::Serializable::getLength
virtual size_t getLength() const =0
eip::serialization::Serializable::deserialize
virtual Reader & deserialize(Reader &reader, size_t length)=0
buffer_writer.h
eip::serialization::SerializableBuffer::getData
virtual mutable_buffer getData() const
Definition:
serializable_buffer.h:80
eip::serialization::Serializable
Definition:
serializable.h:38
eip::serialization::copy_serializable
void copy_serializable(Serializable &dst, const Serializable &src)
Definition:
copy_serializable.cpp:34
buffer_reader.h
eip::serialization::SerializableBuffer
Definition:
serializable_buffer.h:45
serializable_buffer.h
eip::serialization::BufferReader
Definition:
buffer_reader.h:45
copy_serializable.h
eip::serialization::Serializable::serialize
virtual Writer & serialize(Writer &writer) const =0
odva_ethernetip
Author(s): Kareem Shehata
autogenerated on Wed Mar 2 2022 00:38:55