2010-06-17 03:18:40 +02:00
|
|
|
/*
|
|
|
|
* The contents of this file are subject to the Interbase Public
|
|
|
|
* License Version 1.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy
|
|
|
|
* of the License at http://www.Inprise.com/IPL.html
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an
|
|
|
|
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
|
|
|
|
* or implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code was created by Inprise Corporation
|
|
|
|
* and its predecessors. Portions created by Inprise Corporation are
|
|
|
|
* Copyright (C) Inprise Corporation.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
* Contributor(s): ______________________________________.
|
|
|
|
* Adriano dos Santos Fernandes - refactored from others modules.
|
|
|
|
*/
|
|
|
|
|
2013-02-17 13:08:53 +01:00
|
|
|
#ifndef COMMON_CLASSES_BLR_WRITER_H
|
|
|
|
#define COMMON_CLASSES_BLR_WRITER_H
|
2010-06-17 03:18:40 +02:00
|
|
|
|
|
|
|
#include "../common/classes/alloc.h"
|
|
|
|
#include "../common/classes/array.h"
|
|
|
|
#include "../common/classes/fb_string.h"
|
|
|
|
#include "../common/classes/MetaName.h"
|
2013-02-17 13:08:53 +01:00
|
|
|
#include "../common/StatusArg.h"
|
2010-06-17 03:18:40 +02:00
|
|
|
|
2013-02-17 13:08:53 +01:00
|
|
|
namespace Firebird {
|
2010-06-17 03:18:40 +02:00
|
|
|
|
|
|
|
// BLR/DYN writer.
|
|
|
|
class BlrWriter : public Firebird::PermanentStorage
|
|
|
|
{
|
|
|
|
public:
|
2010-07-26 04:37:57 +02:00
|
|
|
typedef Firebird::HalfStaticArray<UCHAR, 1024> BlrData;
|
|
|
|
|
2010-06-17 03:18:40 +02:00
|
|
|
explicit BlrWriter(MemoryPool& p)
|
|
|
|
: PermanentStorage(p),
|
|
|
|
blrData(p),
|
|
|
|
baseOffset(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-07-26 04:37:57 +02:00
|
|
|
virtual ~BlrWriter()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-06-17 03:18:40 +02:00
|
|
|
void appendUChar(const UCHAR byte)
|
|
|
|
{
|
|
|
|
blrData.add(byte);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cram a word into the blr buffer.
|
|
|
|
void appendUShort(USHORT word)
|
|
|
|
{
|
|
|
|
appendUChar(word);
|
|
|
|
appendUChar(word >> 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
void appendULong(ULONG val)
|
|
|
|
{
|
|
|
|
appendUShort(val);
|
|
|
|
appendUShort(val >> 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
void appendUCharRepeated(UCHAR byte, int count)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < count; ++i)
|
|
|
|
appendUChar(byte);
|
|
|
|
}
|
|
|
|
|
2010-08-02 17:58:29 +02:00
|
|
|
void appendBytes(const UCHAR* string, size_t len)
|
2010-06-17 03:18:40 +02:00
|
|
|
{
|
|
|
|
blrData.add(string, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write out a string with one byte of length.
|
|
|
|
void appendNullString(const char* string)
|
|
|
|
{
|
|
|
|
size_t len = strlen(string);
|
|
|
|
|
|
|
|
// CVC: Maybe the Release version should truncate "len" to 255?
|
2010-07-13 13:03:55 +02:00
|
|
|
fb_assert(len <= MAX_UCHAR);
|
2010-06-17 03:18:40 +02:00
|
|
|
|
2010-07-13 13:03:55 +02:00
|
|
|
appendUChar(static_cast<USHORT>(len));
|
|
|
|
appendBytes(reinterpret_cast<const UCHAR*>(string), static_cast<USHORT>(len));
|
2010-06-17 03:18:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Write out a string valued attribute.
|
|
|
|
void appendNullString(UCHAR verb, const char* string)
|
|
|
|
{
|
2010-07-13 13:03:55 +02:00
|
|
|
const USHORT length = string ? static_cast<USHORT>(strlen(string)) : 0;
|
2010-06-17 03:18:40 +02:00
|
|
|
appendString(verb, string, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write out a string in metadata charset with one byte of length.
|
|
|
|
void appendMetaString(const char* string)
|
|
|
|
{
|
2010-07-13 13:03:55 +02:00
|
|
|
appendString(0, string, static_cast<USHORT>(strlen(string)));
|
2010-06-17 03:18:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void appendString(UCHAR verb, const char* string, USHORT len);
|
|
|
|
|
|
|
|
void appendString(UCHAR verb, const Firebird::MetaName& name)
|
|
|
|
{
|
2010-07-13 13:03:55 +02:00
|
|
|
appendString(verb, name.c_str(), static_cast<USHORT>(name.length()));
|
2010-06-17 03:18:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void appendString(UCHAR verb, const Firebird::string& name)
|
|
|
|
{
|
2010-07-13 13:03:55 +02:00
|
|
|
appendString(verb, name.c_str(), static_cast<USHORT>(name.length()));
|
2010-06-17 03:18:40 +02:00
|
|
|
}
|
|
|
|
|
2013-02-17 13:08:53 +01:00
|
|
|
void appendNumber(UCHAR verb, SSHORT number);
|
|
|
|
void appendUShortWithLength(USHORT val);
|
|
|
|
void appendULongWithLength(ULONG val);
|
|
|
|
void appendVersion();
|
|
|
|
|
|
|
|
void beginBlr(UCHAR verb);
|
|
|
|
void endBlr();
|
2010-06-17 03:18:40 +02:00
|
|
|
|
2010-07-26 04:37:57 +02:00
|
|
|
BlrData& getBlrData() { return blrData; }
|
2010-06-17 03:18:40 +02:00
|
|
|
|
|
|
|
ULONG getBaseOffset() const { return baseOffset; }
|
|
|
|
void setBaseOffset(ULONG value) { baseOffset = value; }
|
|
|
|
|
|
|
|
virtual bool isVersion4() = 0;
|
2013-02-17 13:08:53 +01:00
|
|
|
virtual void raiseError(const Arg::StatusVector& vector);
|
2010-07-06 02:49:33 +02:00
|
|
|
|
2010-06-17 03:18:40 +02:00
|
|
|
private:
|
2010-07-26 04:37:57 +02:00
|
|
|
BlrData blrData;
|
2010-06-17 03:18:40 +02:00
|
|
|
ULONG baseOffset; // place to go back and stuff in blr length
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2013-02-17 13:08:53 +01:00
|
|
|
#endif // COMMON_CLASSES_BLR_WRITER_H
|