2
* synergy -- mouse and keyboard sharing utility
3
* Copyright (C) 2002 Chris Schoeneman
5
* This package is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* found in the file COPYING that should have accompanied this file.
9
* This package is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
15
#ifndef CPROTOCOLUTIL_H
16
#define CPROTOCOLUTIL_H
18
#include "BasicTypes.h"
25
//! Synergy protocol utilities
27
This class provides various functions for implementing the synergy
32
//! Write formatted data
34
Write formatted binary data to a stream. \c fmt consists of
35
regular characters and format specifiers. Format specifiers
36
begin with \%. All characters not part of a format specifier
37
are regular and are transmitted unchanged.
39
Format specifiers are:
40
- \%\% -- literal `\%'
41
- \%1i -- converts integer argument to 1 byte integer
42
- \%2i -- converts integer argument to 2 byte integer in NBO
43
- \%4i -- converts integer argument to 4 byte integer in NBO
44
- \%1I -- converts std::vector<UInt8>* to 1 byte integers
45
- \%2I -- converts std::vector<UInt16>* to 2 byte integers in NBO
46
- \%4I -- converts std::vector<UInt32>* to 4 byte integers in NBO
47
- \%s -- converts CString* to stream of bytes
48
- \%S -- converts integer N and const UInt8* to stream of N bytes
50
static void writef(IOutputStream*,
51
const char* fmt, ...);
53
//! Read formatted data
55
Read formatted binary data from a buffer. This performs the
56
reverse operation of writef().
58
Format specifiers are:
59
- \%\% -- read (and discard) a literal `\%'
60
- \%1i -- reads a 1 byte integer; argument is a SInt32* or UInt32*
61
- \%2i -- reads an NBO 2 byte integer; arg is SInt32* or UInt32*
62
- \%4i -- reads an NBO 4 byte integer; arg is SInt32* or UInt32*
63
- \%1I -- reads 1 byte integers; arg is std::vector<UInt8>*
64
- \%2I -- reads NBO 2 byte integers; arg is std::vector<UInt16>*
65
- \%4I -- reads NBO 4 byte integers; arg is std::vector<UInt32>*
66
- \%s -- reads bytes; argument must be a CString*, \b not a char*
68
static void readf(IInputStream*,
69
const char* fmt, ...);
72
static UInt32 getLength(const char* fmt, va_list);
73
static void writef(void*, const char* fmt, va_list);
74
static UInt32 eatLength(const char** fmt);
75
static void read(IInputStream*, void*, UInt32);
78
//! Mismatched read exception
80
Thrown by CProtocolUtil::readf() when the data being read does not
83
class XIOReadMismatch : public XIO {
86
virtual CString getWhat() const throw();