marshaling.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: LGPL-3.0-or-later OR BSD-3-Clause
2 /***************************************************************************
3  * Copyright (C) 2020 by Robert Middleton *
4  * robert.middleton@rm5248.com *
5  * *
6  * This file is part of the dbus-cxx library. *
7  ***************************************************************************/
8 #ifndef DBUSCXX_MARSHALING_H
9 #define DBUSCXX_MARSHALING_H
10 
11 #include <stdint.h>
12 #include <vector>
13 #include <dbus-cxx/path.h>
14 #include <dbus-cxx/signature.h>
15 #include <dbus-cxx/enums.h>
17 
18 namespace DBus {
19 
20 class Variant;
21 
27 class Marshaling {
28 public:
29  Marshaling();
30 
35  Marshaling( std::vector<uint8_t>* data, Endianess endian );
36 
37  ~Marshaling();
38 
44  void set_data( std::vector<uint8_t>* data );
45 
46  void set_endianess( Endianess endian );
47 
48  void marshal( bool v );
49  void marshal( uint8_t v );
50  void marshal( int16_t v );
51  void marshal( uint16_t v );
52  void marshal( int32_t v );
53  void marshal( uint32_t v );
54  void marshal( int64_t v );
55  void marshal( uint64_t v );
56  void marshal( double v );
57  void marshal( std::string v );
58  void marshal( Path v );
59  void marshal( Signature v );
60  void marshal( const Variant& v );
61 
62  void align( int alignment );
63 
71  void marshal_at_offset( uint32_t offset, uint32_t value );
72 
73  uint32_t currentOffset() const;
74 
75 private:
76  void marshalShortBig( uint16_t toMarshal );
77  void marshalIntBig( uint32_t toMarshal );
78  void marshalLongBig( uint64_t toMarshal );
79  void marshalShortLittle( uint16_t toMarshal );
80  void marshalIntLittle( uint32_t toMarshal );
81  void marshalLongLittle( uint64_t toMarshal );
82 
83 private:
84  class priv_data;
85 
86  std::shared_ptr<priv_data> m_priv;
87 };
88 
89 }
90 
91 #endif
Implements the marshaling algorithms on a given vector of data.
Definition: marshaling.h:27
void align(int alignment)
Definition: marshaling.cpp:142
void marshalIntLittle(uint32_t toMarshal)
Definition: marshaling.cpp:187
std::shared_ptr< priv_data > m_priv
Definition: marshaling.h:84
void set_data(std::vector< uint8_t > *data)
Set the data vector to marshal/demarshal.
Definition: marshaling.cpp:207
void marshal_at_offset(uint32_t offset, uint32_t value)
Marshal a uint32_t value at the given offset.
Definition: marshaling.cpp:232
void marshalLongBig(uint64_t toMarshal)
Definition: marshaling.cpp:169
void marshalIntBig(uint32_t toMarshal)
Definition: marshaling.cpp:161
void set_endianess(Endianess endian)
Definition: marshaling.cpp:211
~Marshaling()
Definition: marshaling.cpp:41
void marshalShortBig(uint16_t toMarshal)
Definition: marshaling.cpp:155
void marshalLongLittle(uint64_t toMarshal)
Definition: marshaling.cpp:195
uint32_t currentOffset() const
Definition: marshaling.cpp:246
void marshalShortLittle(uint16_t toMarshal)
Definition: marshaling.cpp:181
void marshal(bool v)
Definition: marshaling.cpp:44
Marshaling()
Definition: marshaling.cpp:31
Represents a DBus Path.
Definition: path.h:21
Represents a DBus signature.
Definition: signature.h:74
A Variant is a type-safe union for DBus operations.
Definition: variant.h:42
Global DBus namespace, where everything happens.
Definition: callmessage.cpp:18
Endianess
Definition: enums.h:114