File: SoapyRPCPacker.hpp

package info (click to toggle)
soapyremote 0.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 504 kB
  • sloc: cpp: 6,740; makefile: 13
file content (118 lines) | stat: -rw-r--r-- 2,728 bytes parent folder | download
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Copyright (c) 2015-2017 Josh Blum
// SPDX-License-Identifier: BSL-1.0

#pragma once
#include "SoapyRemoteConfig.hpp"
#include <SoapySDR/Types.hpp>
#include <vector>
#include <complex>
#include <string>
#include <stdexcept>

class SoapyRPCSocket;

/*!
 * The packer object accepts primitive Soapy SDR types
 * and encodes them into a portable network RPC format.
 */
class SOAPY_REMOTE_API SoapyRPCPacker
{
public:
    SoapyRPCPacker(SoapyRPCSocket &sock, unsigned int remoteRPCVersion = SoapyRPCVersion);

    ~SoapyRPCPacker(void);

    //! Shortcut operator for send
    void operator()(void)
    {
        this->send();
    }

    //! Send the message when packing is complete
    void send(void);

    //! Pack a binary blob
    void pack(const void *buff, const size_t length);

    //! Pack a single byte
    void pack(const char byte)
    {
        this->ensureSpace(1);
        _message[_size] = byte;
        _size++;
    }

    //! Pack the call
    void operator&(const SoapyRemoteCalls value)
    {
        *this & SOAPY_REMOTE_CALL;
        *this & int(value);
    }

    //! Pack the type
    void operator&(const SoapyRemoteTypes value)
    {
        this->pack(char(value));
    }

    //! Pack a character
    void operator&(const char value);

    //! Pack a boolean
    void operator&(const bool value);

    //! Pack a 32-bit integer
    void operator&(const int value);

    //! Pack a 64-bit integer
    void operator&(const long long value);

    //! Pack a double float
    void operator&(const double value);

    //! Pack a complex double float
    void operator&(const std::complex<double> &value);

    //! Pack a string
    void operator&(const std::string &value);

    //! Pack a range
    void operator&(const SoapySDR::Range &value);

    //! Pack a list of ranges
    void operator&(const SoapySDR::RangeList &value);

    //! Pack a list of strings
    void operator&(const std::vector<std::string> &value);

    //! Pack a list of double floats
    void operator&(const std::vector<double> &value);

    //! Pack a kwargs dictionary
    void operator&(const SoapySDR::Kwargs &value);

    //! Pack a list of kwargs
    void operator&(const SoapySDR::KwargsList &value);

    //! Pack a list of sizes
    void operator&(const std::vector<size_t> &value);

    //! Pack an arg info structure
    void operator&(const SoapySDR::ArgInfo &value);

    //! Pack a list of arg infos
    void operator&(const SoapySDR::ArgInfoList &value);

    //! Pack an exception
    void operator&(const std::exception &value);

private:

    void ensureSpace(const size_t length);

    SoapyRPCSocket &_sock;
    char *_message;
    size_t _size;
    size_t _capacity;
    unsigned int _remoteRPCVersion;
};