summaryrefslogtreecommitdiff
path: root/lib/serialize_types.cpp
blob: fde7277dbcc819b3fb2a1f0dfd10ca48ca27a201 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright (C) by Josh Blum. See LICENSE.txt for licensing information.

#include <gras/sbuffer.hpp>
#include <gras/tags.hpp>
#include <gras/time_tag.hpp>
#include <PMC/Serialize.hpp>
#include <boost/serialization/split_free.hpp>
#include <boost/serialization/string.hpp>

/***********************************************************************
 * support for sbuffer
 **********************************************************************/
namespace boost { namespace serialization {
template<class Archive>
void save(Archive & ar, const gras::SBuffer & b, unsigned int version)
{
    //save null
    bool null = not b;
    ar & null;
    if (null) return;

    //save length
    size_t length = b.length;
    ar & length;

    //save bytes
    const char *ptr = reinterpret_cast<const char *>(b.get(0));
    for (size_t i = 0; i < length; i++) ar & (ptr[i]);
}
template<class Archive>
void load(Archive & ar, gras::SBuffer & b, unsigned int version)
{
    //load null
    bool null = false;
    ar & null;
    if (null) b.reset();
    if (null) return;

    //load length
    size_t length = 0;
    ar & length;

    //alloc sbuffer
    gras::SBufferConfig config;
    config.length = length;
    b = gras::SBuffer(config);

    //load bytes
    char *ptr = reinterpret_cast<char *>(b.get(0));
    for (size_t i = 0; i < length; i++) ar & (ptr[i]);
}
}}

BOOST_SERIALIZATION_SPLIT_FREE(gras::SBuffer)
PMC_SERIALIZE_EXPORT(gras::SBuffer, "PMC<gras::SBuffer>")


/***********************************************************************
 * support for special packet msg type
 **********************************************************************/
namespace boost { namespace serialization {
template <class Archive>
void serialize(Archive &ar, gras::PacketMsg &t, const unsigned int)
{
    ar & t.info;
    ar & t.buff;
}
}}

PMC_SERIALIZE_EXPORT(gras::PacketMsg, "PMC<gras::PacketMsg>")

/***********************************************************************
 * support for special stream tag type
 **********************************************************************/
namespace boost { namespace serialization {
template <class Archive>
void serialize(Archive &ar, gras::StreamTag &t, const unsigned int)
{
    ar & t.key;
    ar & t.val;
    ar & t.src;
}
}}

PMC_SERIALIZE_EXPORT(gras::StreamTag, "PMC<gras::StreamTag>")

/***********************************************************************
 * support for time tag type
 **********************************************************************/
namespace boost { namespace serialization {
template <class Archive>
void serialize(Archive &ar, gras::TimeTag &t, const unsigned int)
{
    ar & t._fsecs;
    ar & t._ticks;
}
}}

PMC_SERIALIZE_EXPORT(gras::TimeTag, "PMC<gras::TimeTag>")