tango.io.protocol.Writer

License:

BSD style: see license.txt

Version:

Oct 2004: Initial release Dec 2006: Outback release

Author:

Kris
class Writer : IWriter #
Writer base-class. Writers provide the means to append formatted data to an IBuffer, and expose a convenient method of handling a variety of data types. In addition to writing native types such as integer and char[], writers also process any class which has implemented the IWritable interface (one method).
All writers support the full set of native data types, plus their fundamental array variants. Operations may be chained back-to-back.

Writers support a Java-esque put() notation. However, the Tango style is to place IO elements within their own parenthesis, like so:

1
write (count) (" green bottles");

Note that each written element is distict; this style is affectionately known as "whisper". The code below illustrates basic operation upon a memory buffer:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
auto buf = new Buffer (256);

// map same buffer into both reader and writer
auto read = new Reader (buf);
auto write = new Writer (buf);

int i = 10;
long j = 20;
double d = 3.14159;
char[] c = "fred";

// write data types out
write (c) (i) (j) (d);

// read them back again
read (c) (i) (j) (d);


// same thing again, but using put() syntax instead
write.put(c).put(i).put(j).put(d);
read.get(c).get(i).get(j).get(d);

Writers may also be used with any class implementing the IWritable interface, along with any struct implementing an equivalent function.

this(IProtocol protocol) #
Construct a Writer on the provided Protocol
this(OutputStream stream) #
Construct a Writer on the given OutputStream. We do our own protocol handling, equivalent to the NativeProtocol.
IBuffer buffer() [final] #
Return the associated buffer
IWriter newline() #
Emit a newline
IWriter newline(char[] eol) #
set the newline sequence
IWriter flush() [final] #
Flush the output of this writer and return a chaining ref
IWriter put() [final] #
Flush this writer. This is a convenience method used by the "whisper" syntax.
IWriter put(IWriter.Closure dg) [final] #
Write via a delegate to the current buffer-position
IWriter put(IWritable x) [final] #
Write a class to the current buffer-position
IWriter put(bool x) [final] #
Write a boolean value to the current buffer-position
IWriter put(ubyte x) [final] #
Write an unsigned byte value to the current buffer-position
IWriter put(byte x) [final] #
Write a byte value to the current buffer-position
IWriter put(ushort x) [final] #
Write an unsigned short value to the current buffer-position
IWriter put(short x) [final] #
Write a short value to the current buffer-position
IWriter put(uint x) [final] #
Write a unsigned int value to the current buffer-position
IWriter put(int x) [final] #
Write an int value to the current buffer-position
IWriter put(ulong x) [final] #
Write an unsigned long value to the current buffer-position
IWriter put(long x) [final] #
Write a long value to the current buffer-position
IWriter put(float x) [final] #
Write a float value to the current buffer-position
IWriter put(double x) [final] #
Write a double value to the current buffer-position
IWriter put(real x) [final] #
Write a real value to the current buffer-position
IWriter put(char x) [final] #
Write a char value to the current buffer-position
IWriter put(wchar x) [final] #
Write a wchar value to the current buffer-position
IWriter put(dchar x) [final] #
Write a dchar value to the current buffer-position
IWriter put(bool[] x) [final] #
Write a boolean array to the current buffer-position
IWriter put(byte[] x) [final] #
Write a byte array to the current buffer-position
IWriter put(ubyte[] x) [final] #
Write an unsigned byte array to the current buffer-position
IWriter put(short[] x) [final] #
Write a short array to the current buffer-position
IWriter put(ushort[] x) [final] #
Write an unsigned short array to the current buffer-position
IWriter put(int[] x) [final] #
Write an int array to the current buffer-position
IWriter put(uint[] x) [final] #
Write an unsigned int array to the current buffer-position
IWriter put(long[] x) [final] #
Write a long array to the current buffer-position
IWriter put(ulong[] x) [final] #
Write an unsigned long array to the current buffer-position
IWriter put(float[] x) [final] #
Write a float array to the current buffer-position
IWriter put(double[] x) [final] #
Write a double array to the current buffer-position
IWriter put(real[] x) [final] #
Write a real array to the current buffer-position
IWriter put(char[] x) [final] #
Write a char array to the current buffer-position
IWriter put(wchar[] x) [final] #
Write a wchar array to the current buffer-position
IWriter put(dchar[] x) [final] #
Write a dchar array to the current buffer-position
void writeArray(void* src, uint bytes, IProtocol.Type type) [private] #
Dump array content into the buffer. Note that the default behaviour is to prefix with the array byte count
void writeElement(void* src, uint bytes, IProtocol.Type type) [private] #
Dump content into the buffer