2001-10-06 14:13:28 +00:00
|
|
|
#ifndef CPROTOCOLUTIL_H
|
|
|
|
#define CPROTOCOLUTIL_H
|
|
|
|
|
|
|
|
#include "BasicTypes.h"
|
|
|
|
#include "XIO.h"
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
class IInputStream;
|
|
|
|
class IOutputStream;
|
|
|
|
|
|
|
|
class CProtocolUtil {
|
|
|
|
public:
|
|
|
|
// write formatted binary data to a stream. fmt consists of
|
|
|
|
// regular characters and format specifiers. format specifiers
|
|
|
|
// begin with %. all characters not part of a format specifier
|
|
|
|
// are regular and are transmitted unchanged.
|
|
|
|
//
|
|
|
|
// format specifiers are:
|
|
|
|
// %% -- writes %
|
|
|
|
// %1i -- converts integer argument to 1 byte integer
|
|
|
|
// %2i -- converts integer argument to 2 byte integer in NBO
|
|
|
|
// %4i -- converts integer argument to 4 byte integer in NBO
|
2001-11-25 18:32:41 +00:00
|
|
|
// %s -- converts CString* to stream of bytes
|
|
|
|
// %S -- converts integer N and const UInt8* to stream of N bytes
|
2001-10-06 14:13:28 +00:00
|
|
|
static void writef(IOutputStream*,
|
2001-10-14 16:58:01 +00:00
|
|
|
const char* fmt, ...);
|
2001-10-06 14:13:28 +00:00
|
|
|
|
|
|
|
// read formatted binary data from a buffer. this performs the
|
|
|
|
// reverse operation of writef().
|
|
|
|
//
|
|
|
|
// format specifiers are:
|
|
|
|
// %% -- read (and discard) a %
|
|
|
|
// %1i -- reads a 1 byte integer; argument is a SInt32* or UInt32*
|
|
|
|
// %2i -- reads an NBO 2 byte integer; arg is SInt32* or UInt32*
|
|
|
|
// %4i -- reads an NBO 4 byte integer; arg is SInt32* or UInt32*
|
|
|
|
// %s -- reads bytes; argument must be a CString*, *not* a char*
|
|
|
|
static void readf(IInputStream*,
|
2001-10-14 16:58:01 +00:00
|
|
|
const char* fmt, ...);
|
2001-10-06 14:13:28 +00:00
|
|
|
|
|
|
|
private:
|
2001-10-14 16:58:01 +00:00
|
|
|
static UInt32 getLength(const char* fmt, va_list);
|
|
|
|
static void writef(void*, const char* fmt, va_list);
|
|
|
|
static UInt32 eatLength(const char** fmt);
|
|
|
|
static void read(IInputStream*, void*, UInt32);
|
2001-10-06 14:13:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class XIOReadMismatch : public XIO {
|
|
|
|
public:
|
|
|
|
// XBase overrides
|
|
|
|
virtual CString getWhat() const throw();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|