wvdbusserver: implement NameHasOwner request.
[wvstreams.git] / include / wvhex.h
blob4720589675ffafbd3cb37d255b81364aac1d9435
1 /* -*- Mode: C++ -*-
2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
5 * Hex encoder and hex decoder.
6 */
7 #ifndef __WVHEX_H
8 #define __WVHEX_H
10 #include "wvencoder.h"
12 /**
13 * A hex encoder.
15 * The input data is transformed into a sequence of hexadecimal
16 * characters.
18 * Supports reset().
21 class WvHexEncoder : public WvEncoder
23 char alphabase;
25 public:
26 /**
27 * Creates a hex encoder.
29 * "use_uppercase" is if true, outputs hex codes A through Z
30 * in upper case, otherwise output them in lower case
31 * (the default)
33 WvHexEncoder(bool use_uppercase = false);
34 virtual ~WvHexEncoder() { }
36 protected:
37 virtual bool _encode(WvBuf &in, WvBuf &out, bool flush);
38 virtual bool _reset(); // supported
42 /**
43 * A hex decoder.
45 * The input hex characters are paired and decoded into the
46 * corresponding byte stream. Whitespace is skipped as is the
47 * case of the hex codes A through Z. Other characters cause the
48 * encoder to flag an error.
50 * Supports reset().
53 class WvHexDecoder : public WvEncoder
55 bool issecond;
56 int first;
58 public:
59 /** Creates a hex decoder. */
60 WvHexDecoder();
61 virtual ~WvHexDecoder() { }
63 protected:
64 virtual bool _encode(WvBuf &in, WvBuf &out, bool flush);
65 virtual bool _reset(); // supported
68 /** \file
69 * Hex functions for compatibility with older code
72 /**
73 * Write the contents of the binary string of length 'len' pointed to by 'ibuf'
74 * into the output buffer 'obuf' in hexadecimal format.
76 * For example, if len==4, ibuf=="ABCDEF", then obuf will contain "41424344"
77 * with a terminating NULL character.
79 * This is useful to turn arbitrary binary into a simple printable format, so
80 * that it can (for example) be written to a WvConf configuration file.
82 * obuf must be a buffer with at least (len * 2) + 1 bytes available. (two
83 * digits for each byte of ibuf, plus a terminating NULL).
85 void hexify(char *obuf, const void *ibuf, size_t len);
87 /**
88 * Reverse the operation performed by hexify(). obuf must be a buffer large
89 * enough to contain the entire binary output string; you can calculate this
90 * size with (strlen(ibuf) / 2). obuf will NOT be automatically NULL-terminated.
92 void unhexify(void *obuf, const char *ibuf);
94 #endif // __WVHEX_H