CkByteData C++ Reference Documentation

CkByteData

Represents a chunk of byte data and provides methods for accessing it, adding to it, or saving and loading from files.

Properties

None

Methods

void append(CkByteData &db);

Appends byte data to the data already contained in the object.

void append2(const void *pByteData, unsigned long szByteData);

Appends bytes to the data already contained in the object.

void appendChar(char ch);

Appends a single byte.

void appendCharN(char ch, int numTimes);

Appends a single char N times. The equivalent of calling appendChar N times.

void appendEncoded(const char *str, const char *encoding);

Appends binary data from an encoded string. The encoding can be specified as "hex", "base64", "url", "quoted-printable", "modBase64", "base58", or "base32". The input string is decoded from the specified encoding and the binary data is appended to the calling object's content.

void appendEncodedW(const wchar_t *str, const wchar_t *encoding);

To be documented soon...

bool appendFile(const char *path);

Opens a file for binary read, appends the file contents, and closes the file.

bool appendFileW(const wchar_t *path);

To be documented soon...

void appendInt(int intValue, bool littleEndian);

Appends a 32-bit signed integer (4 bytes) to the data already contained in the object. littleEndian determines whether the big endian or little endian byte ordering is used.

void appendRandom(int numBytes);

Appends numBytes random bytes to the data already contained within the object.

void appendRange(CkByteData &byteData, unsigned long index, unsigned long numBytes);

Appends a range of bytes from byteData to the data contained withing the caller. The first byte is at index 0.

void appendShort(short shortValue, bool littleEndian);

Appends a 16-bit signed integer (2 bytes) to the data already contained in the object. littleEndian determines whether the big endian or little endian byte ordering is used.

void appendStr(const char *str);

Appends a null-terminated string to the data, without including the terminating null.

void appendStrW(const wchar_t *str, const wchar_t *charset);

To be documented soon...

bool beginsWith(CkByteData &byteDataObj);

Returns true if the caller's data begins with the exact bytes contained within byteDataObj.

bool beginsWith2(const void *pByteData, unsigned long szByteData);

Returns true if the caller's data begins with specified bytes.

void borrowData(void *pByteData, unsigned long szByteData);

Sets the CkByteData's data pointer and size to memory outside the object. This is useful in cases where a CkByteData object is needed, but copying data into the CkByteData is not desired.

Note: The borrowData method can only be used for data that is being passed into a Chilkat method call. It is not for use as a buffer for Chilkat to deposit data. This is not the intent of the method.

More detailed explanation of borrowData

void byteSwap4321(void);

4321 byte swaps the data contained within the object.

void clear(void);

Clears the CkByteData object of all data.

void encode(const char *encoding, CkString &str);

Encodes binary data according to the encoding requested. The encoding can be specified as "hex", "base64", "url", "quoted-printable", "modBase64", "base58", "base32", "qp-", "url_rfc1738", "url_rfc2396", or "url_rfc3986".

void encodeW(const wchar_t *encoding, CkString &str);

To be documented soon...

bool ensureBuffer(unsigned long expectedNumBytes);

This method can be called to help optimize internal memory re-allocation. If, for example, many calls will be made to append data, and the total size is approximately known, then this method can be called to pre-allocate the internal buffer to the expected total size.

Returns true for success, false for failure.

bool equals(CkByteData &compareBytes);

Returns true if compareBytes contains exactly the same content as the caller. Otherwise returns false.

bool equals2(const void *pCompareBytes, unsigned long numBytes);

Returns true if the bytes pointed to by pCompareBytes contains exactly the same content as the caller. Otherwise returns false.

int findBytes(CkByteData &byteDataObj);

Locates the first occurance of the bytes contained in byteDataObj and returns the index of where these bytes occur in the caller's data. Returns -1 if not found.

int findBytes2(const void *findBytes, unsigned long findBytesLen);

Locates the first occurance of the specified bytes and returns the index of where these bytes occur in the caller's data. Returns -1 if not found.

unsigned char getByte(unsigned long byteIndex);

Returns the Nth byte of the binary data. The 1st byte is at index 0.

const unsigned char *getBytes(void);

This method is deprecated. It will be removed in a future version.

Returns a pointer to the bytes contained within the object. Be very careful with the pointer that is returned. If more data is appended to the object, an internal reallocation may occur such that the previously returned pointer is no longer valid.

This method is identical to the getData method. Use getData instead.

char getChar(unsigned long byteIndex);

Returns the Nth byte of the binary content as a "char". The 1st byte is at index 0.

const unsigned char *getData(void);

Returns a pointer to the internal buffer. Be careful with this method because if additional data is appended, the data within the object may be relocated and the pointer may cease to be valid.

const unsigned char *getDataAt(unsigned long byteIndex);

Same as getData, except it gets a pointer to the data at a byte offset. (0 = the start of buffer)

bool getEncoded(const char *encoding, CkString &outStr);
const char *getEncoded(const char *encoding);

Introduced in version 9.5.0.47

Returns the binary data as an encoded string. The encoding may be "base64", "hex", "quoted-printable" (or "qp"), "url", "asc", "url_rfc1738", "url_rfc2396", "url_rfc3986", or "url_oauth".

Returns true for success, false for failure.

const wchar_t *getEncodedW(const wchar_t *encoding);

The utf-16 version of getEncoded.

int getInt(unsigned long byteIndex);

Returns the 4-byte integer located at a specific byte index.

const unsigned char *getRange(unsigned long byteIndex, unsigned long numBytes);

Copies a range of bytes to a separate internal memory buffer and returns the pointer to the bytes. The returned pointer is only valid while the object exists. Also, any subsequent calls to getRange, getRangeStr, or to_s will invalidate the buffer.

short getShort(unsigned long byteIndex);

Returns the 2-byte integer located at a specific byte index.

Note: The application is responsible for deleting (via the C++ delete operator) the object returned by this method.

unsigned long getSize(void);

Returns the number of bytes in the data buffer.

unsigned int getUInt(unsigned long byteIndex);

Returns the 4-byte unsigned integer located at a specific byte index.

Note: The application is responsible for deleting (via the C++ delete operator) the object returned by this method.

unsigned short getUShort(unsigned long byteIndex);

Returns the 2-byte unsigned integer located at a specific byte index.

Note: The application is responsible for deleting (via the C++ delete operator) the object returned by this method.

bool is7bit(void);

Returns true if all the bytes are in the range 0x00 to 0x7F.

bool loadFile(const char *path);

Equivalent to clear() followed by appendFile().

bool loadFileW(const wchar_t *path);

To be documented soon...

void pad(int blockSize, int paddingScheme);

Pads the data to a multiple of the blockSize using a cryptographic padding scheme specified by paddingScheme. The possible integer values for paddingScheme are the same as those listed for the PaddingScheme property of the CkCrypt2 class.

bool preAllocate(unsigned long expectedNumBytes);

This method is deprecated. It will be removed in a future version.

This method can be called to help optimize internal memory re-allocation. If, for example, many calls will be made to append data, and the total size is approximately known, then this method can be called to pre-allocate the internal buffer to the expected total size.

This method is identical to the ensureBuffer method. Use ensureBuffer instead.

void removeChunk(unsigned long startIndex, unsigned long numBytes);

Removes (discards) a range from the data.

unsigned char *removeData(void);

Removes the data from the CkByteData object. The caller will receivea pointer to the memory buffer, and is responsible for deleting it.
Example:
unsigned char *data = byteData.removeData();
... do something with the data....
delete [] data;

void replaceChar(unsigned char existingByteValue, unsigned char replacementByteValue);

Replaces all occurances of existingByteValue with replacementByteValue.

bool saveFile(const char *path);

Saves the byte data to a file. If the file already exists, it will be overwritten.

bool saveFileW(const wchar_t *path);

To be documented soon...

void shorten(unsigned long numBytes);

Discards N bytes from the end of the data.

const wchar_t *to_ws(const char *charset);

To be documented soon...

void unpad(int blockSize, int paddingScheme);

Unpads the data from a multiple of the blockSize to the original data size using a cryptographic padding scheme specified by paddingScheme. The possible integer values for paddingScheme are the same as those listed for the PaddingScheme property of the CkCrypt2 class.