File: SoapyRPCUnpacker.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 (122 lines) | stat: -rw-r--r-- 2,868 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
119
120
121
122
// 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>

class SoapyRPCSocket;

/*!
 * The unpacker object receives a complete RPC message,
 * and unpacks the message into primitive Soapy SDR types.
 */
class SOAPY_REMOTE_API SoapyRPCUnpacker
{
public:
    SoapyRPCUnpacker(SoapyRPCSocket &sock, const bool autoRecv = true, const long timeoutUs = 30000000);

    ~SoapyRPCUnpacker(void);

    //! Receive a complete RPC message
    void recv(void);

    //! Unpack a binary blob of known size
    void unpack(void *buff, const size_t length);

    //! Copy-less version of unpack
    void *unpack(const size_t length);

    //! Unpack a single byte
    char unpack(void)
    {
        char byte = _message[_offset];
        _offset++;
        return byte;
    }

    //! Done when no data is left to unpack
    bool done(void) const;

    //! View the next type without consuming
    SoapyRemoteTypes peekType(void) const
    {
        return SoapyRemoteTypes(_message[_offset]);
    }

    //! Unpack the call
    void operator&(SoapyRemoteCalls &value);

    //! Unpack the type
    void operator&(SoapyRemoteTypes &value)
    {
        value = SoapyRemoteTypes(this->unpack());
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    //! Get the received RPC version number
    unsigned int remoteRPCVersion(void) const
    {
        return _remoteRPCVersion;
    }

private:

    void ensureSpace(const size_t length);

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