summaryrefslogtreecommitdiff
path: root/include/object/xdr16stream.h
blob: 90a266240fafd96ddc0001d2ea75862a713e9244 (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
/*
 * Copyright 2020 Birte Kristina Friesel
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */
#ifndef XDRSTREAM_H
#define XDRSTREAM_H

#include <stdint.h>

class XDRStream {
 private:
	XDRStream(const XDRStream& copy);
	uint16_t next_array_len;
	bool is_fixed_length;

 public:
	XDRStream() : next_array_len(0) {}
	void setNextArrayLen(uint16_t len) {next_array_len = len;}
	void setFixedLength() { is_fixed_length = true; }
	void setVariableLength() { is_fixed_length = false; }

	virtual void put(char c) = 0;

	virtual void flush() {}

	XDRStream & operator<<(char c);
	XDRStream & operator<<(unsigned char c);
	XDRStream & operator<<(uint16_t number);
	XDRStream & operator<<(int16_t number);
	XDRStream & operator<<(uint32_t number);
	XDRStream & operator<<(int32_t number);
	XDRStream & operator<<(uint64_t number);
	XDRStream & operator<<(int64_t number);
	XDRStream & operator<<(float number);
	XDRStream & operator<<(double number);
	XDRStream & operator<<(char const *text);
	template<uint16_t TSize> XDRStream & operator<<(char const (&text)[TSize]);
	XDRStream & operator<<(XDRStream & (*fun) (XDRStream &));
};


XDRStream & flush(XDRStream & os);

XDRStream & term(XDRStream & os);

template<int TSize>
XDRStream & opaque(XDRStream & os);

XDRStream & fixed(XDRStream & os);
XDRStream & variable(XDRStream & os);

#endif