OutBuffer

OutBuffer is a write-only output stream of untyped data. It is backed up by a contiguous array or a memory-mapped file.

Constructors

this
this(size_t initialSize)

Construct given size.

this
this(const(char)* filename)

Construct from filename. Will map the file into memory (or create it anew if necessary) and start writing at the beginning of it.

Destructor

~this
~this()

Frees resources associated automatically.

Members

Functions

allocate
char[] allocate(size_t nbytes)

Allocate space, but leave it uninitialized.

bracket
size_t bracket(size_t i, const(char)* left, size_t j, const(char)* right)

Insert left at i, and right at j. Return index just past right.

buf
ubyte* buf()

For porting with ease from dmd.backend.outbuf.Outbuffer

bufptr
ubyte** bufptr()

For porting with ease from dmd.backend.outbuf.Outbuffer

destroy
void destroy()

Releases all resources associated with this and resets it as an empty memory buffer. The config variables notlinehead, doindent etc. are not changed.

dtor
void dtor()

Frees resources associated.

extractData
char* extractData()

Transfer ownership of the allocated data to the caller.

extractSlice
char[] extractSlice(bool nullTerminate)

Extract the data as a slice and take ownership of it.

insert
size_t insert(size_t offset, const(void)* p, size_t nbytes)
moveToFile
bool moveToFile(char* filename)

Destructively saves the contents of this to filename. As an optimization, if the file already has identical contents with the buffer, no copying is done. This is because on SSD drives reading is often much faster than writing and because there's a high likelihood an identical file is written during the build process.

opSlice
const(char)[] opSlice()
print
void print(ulong u)

Convert u to a string and append it to the buffer.

reserve
void reserve(size_t nbytes)

Reserves nbytes bytes of additional memory (or file space) in advance. The resulting capacity is at least the previous length plus nbytes.

setsize
void setsize(size_t size)

Shrink the size of the data to size.

write16
void write16(int v)

Writes a 16 bit value.

write16n
void write16n(int v)

Writes a 16 bit value, no reserve check.

write32
void write32(int v)

Writes a 32 bit int.

write64
void write64(long v)

Writes a 64 bit int.

writeByten
void writeByten(int b)

Writes an 8 bit byte, no reserve check.

writeStringz
void writeStringz(const(char)* s)
void writeStringz(const(char)[] s)
void writeStringz(string s)

Write string to buffer, ensure it is zero terminated

writenl
void writenl()

strip trailing tabs or spaces, write newline

writestring
void writestring(const(char)* s)
void writestring(const(char)[] s)
void writestring(string s)

NOT zero-terminated

writestringln
void writestringln(const(char)[] s)

NOT zero-terminated, followed by newline

Variables

doindent
bool doindent;

Whether to indent

level
int level;

Current indent level

spaces
bool spaces;

Whether to indent by 4 spaces or by tabs;

Meta