41 : m_Owner(
true), m_ReadOffset(0), m_WriteOffset(0)
49 : m_Owner(
copy), m_ReadOffset(0), m_WriteOffset(0)
97 for(
size_t i = *offsetp;
i <
all.size();
i++) {
102 rv = (rv << 7) | (ch & 0x7F);
105 rv = (rv << 6) | (ch & 0x3F);
106 *offsetp =
static_cast<int>(
i+1);
108 return (ch & 0x40) ? -rv : rv;
114 "CBlastDbBlob::ReadVarInt: eof while reading integer.");
117 #if ((!defined(NCBI_COMPILER_WORKSHOP) || (NCBI_COMPILER_VERSION > 550)) && \
118 (!defined(NCBI_COMPILER_MIPSPRO)) )
126 return x_ReadIntFixed<int, 1>(&
offset);
136 return x_ReadIntFixed<int, 2>(&
offset);
146 return x_ReadIntFixed<Int4, 4>(&
offset);
156 return x_ReadIntFixed<Int8, 8>(&
offset);
174 sz = x_ReadIntFixed<int,4>(offsetp);
179 const char * datap =
"";
185 for(
size_t i = *offsetp;
i < ts.
size();
i++) {
186 if (ts[
i] == (
char)0) {
187 zoffset =
static_cast<int>(
i);
195 "CBlastDbBlob::ReadString: Unterminated string.");
198 datap = ts.
data() + *offsetp;
199 sz = zoffset - *offsetp;
200 *offsetp = zoffset+1;
216 int begin = *offsetp;
217 int end = begin +
size;
219 if (begin > end || end > (
int)s.
size()) {
222 "CBlastDbBlob::x_ReadRaw: hit end of data");
226 return s.
data() + begin;
258 _ASSERT(((x >> 62) == -1) || ((x >> 62) == 0));
261 int end_ptr =
sizeof(
buf);
266 buf[--ptr] = (ux & 0x3F);
274 buf[--ptr] = (ux & 0x7F) | 0x80;
278 int bytes = end_ptr - ptr;
301 #if ((!defined(NCBI_COMPILER_WORKSHOP) || (NCBI_COMPILER_VERSION > 550)) && \
302 (!defined(NCBI_COMPILER_MIPSPRO)) )
305 x_WriteIntFixed<int,1>(x,
NULL);
310 x_WriteIntFixed<int,1>(x, &
offset);
315 x_WriteIntFixed<int,2>(x,
NULL);
320 x_WriteIntFixed<int,2>(x, &
offset);
325 x_WriteIntFixed<int,4>(x,
NULL);
330 x_WriteIntFixed<int,4>(x, &
offset);
335 x_WriteIntFixed<Int8, 8>(x,
NULL);
340 x_WriteIntFixed<Int8, 8>(x, &
offset);
345 x_WriteIntFixed_LE<int,1>(x,
NULL);
350 x_WriteIntFixed_LE<int,1>(x, &
offset);
355 x_WriteIntFixed_LE<int,2>(x,
NULL);
360 x_WriteIntFixed_LE<int,2>(x, &
offset);
365 x_WriteIntFixed_LE<int,4>(x,
NULL);
370 x_WriteIntFixed_LE<int,4>(x, &
offset);
375 x_WriteIntFixed_LE<Int8, 8>(x,
NULL);
380 x_WriteIntFixed_LE<Int8, 8>(x, &
offset);
398 x_WriteIntFixed<int,4>(
static_cast<int>(
str.size()), offsetp);
412 return end_off - start_off;
433 int orig_size =
size;
435 if (offsetp ==
NULL) {
475 *offsetp += orig_size;
502 int cur_cap =
static_cast<int>(
m_DataHere.capacity());
504 if (cur_cap < need) {
509 while(new_cap < need) {
570 pads = pads ? (align - pads) : 0;
576 for(
int i = 0;
i < pads;
i++) {
580 for(
int i = 1;
i < pads;
i++) {
593 #if ((!defined(NCBI_COMPILER_WORKSHOP) || (NCBI_COMPILER_VERSION > 550)) && \
594 (!defined(NCBI_COMPILER_MIPSPRO)) )
601 pads = pads ? (align-pads) : 0;
605 for(
int i = 0;
i < (
int)
tmp.size();
i++) {
void SkipPadBytes(int align, EPadding fmt)
Align the offset by skipping bytes.
int GetReadOffset() const
Get the current read pointer offset.
CTempString m_DataRef
Non-owned data (only used for `read' streams).
Int4 ReadInt4()
Read a 4 byte integer at the pointer (and move the pointer).
int ReadInt2()
Read a 2 byte integer at the pointer (and move the pointer).
int ReadInt1()
Read a 1 byte integer at the pointer (and move the pointer).
CBlastDbBlob(int size=0)
Create a new object, reserving 'size' bytes for writing.
void x_WriteRaw(const char *ptr, int size, int *offsetp)
Write raw bytes as ptr + size at a given offset.
@ eString
Pad using NUL terminated string of '#' bytes.
@ eSimple
Just write NUL bytes until aligned.
static int VarIntSize(Int8 x)
Compute bytes used for a variable length integer.
int Size() const
Get size of blob contents.
void ReferTo(CTempString data)
Refer to an existing memory area.
int GetWriteOffset() const
Get the current write pointer offset.
void WriteRaw(const char *begin, int size)
Write raw data to the blob (moving the write pointer).
void WritePadBytes(int align, EPadding fmt)
Align the offset by writing pad bytes.
EStringFormat
String termination style.
@ eSizeVar
Write string length as VarInt, then string data.
@ eNUL
Write a NUL terminated string.
@ eSize4
Write string length as Int4, then string data.
void WriteInt2(int x)
Write a 1 byte integer to the blob.
CTempString ReadString(EStringFormat fmt)
Read string data from the blob (moving the read pointer).
void x_Copy(int total)
Copy referenced data to owned data.
void Clear()
Clear all owned data and reference an empty string.
void WriteInt4(Int4 x)
Write a 4 byte integer to the blob.
int x_WriteVarInt(Int8 x, int *offsetp)
Write a variable length integer into the buffer.
void WriteInt8(Int8 x)
Write an 8 byte integer to the blob.
int m_WriteOffset
The `write pointer' for stream-like access.
Int8 x_ReadVarInt(int *offsetp) const
Read a variable length integer from the buffer.
void WriteInt8_LE(Int8 x)
vector< char > m_DataHere
Data owned by this object.
Int8 ReadInt8()
Read an 8 byte integer at the pointer (and move the pointer).
void SeekRead(int offset)
Move the read pointer to a specific location.
CRef< CObject > m_Lifetime
Lifetime maintenance object for referenced data.
int x_WriteString(CTempString str, EStringFormat fmt, int *offsetp)
Write string data to the blob.
void WriteInt1(int x)
Write a 1 byte integer to the blob.
void x_Reserve(int size)
Write raw bytes as a CTempString.
CTempString Str() const
Get blob contents as a CTempString.
void WriteInt4_LE(Int4 x)
int WriteString(CTempString str, EStringFormat fmt)
Write string data to the blob.
void SeekWrite(int offset)
Seek write pointer to a specific location.
const char * x_ReadRaw(int size, int *offsetp) const
Read raw bytes from a given offset.
const char * ReadRaw(int size)
Read raw data (moving the read pointer).
CTempString x_ReadString(EStringFormat fmt, int *offsetp) const
Read string data from the blob.
bool m_Owner
True if this object owns the target data.
int m_ReadOffset
The `read pointer' for stream-like access.
Int8 ReadVarInt()
Read a variable length integer from the blob.
int WriteVarInt(Int8 x)
Write a variable length integer to the blob.
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
void Reset(void)
Reset reference object.
int32_t Int4
4-byte (32-bit) signed integer
int64_t Int8
8-byte (64-bit) signed integer
uint64_t Uint8
8-byte (64-bit) unsigned integer
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
const char * data(void) const
Return a pointer to the array represented.
size_type size(void) const
Return the length of the represented array.
unsigned int
A callback function used to compare two keys in a database.
const struct ncbi::grid::netcache::search::fields::SIZE size
void copy(Njn::Matrix< S > *matrix_, const Njn::Matrix< T > &matrix0_)
Defines BlastDb `Blob' class for SeqDB and WriteDB.
Defines exception class and several constants for SeqDB.
This file defines several SeqDB utility functions related to byte order and file system portability.
#define SEQDB_FILE_ASSERT(YESNO)
static const char * str(char *buf, int n)