Envelope

@safe
struct Envelope {
EnvelopeHeader header;
immutable(ubyte)[] data;
immutable(ubyte)[] tail;
bool errorstate;
string[] errors;
}

Members

Structs

EnvelopeHeader
struct EnvelopeHeader

Examples

pragma(msg, "Envelope: TODO: make test for endian change case ");

uint x1 = 12345;
uint x2 = x1;
uint x3 = 0;
uint x4 = x1;

static if (endian == Endian.littleEndian) {
    makeFromBigEndian!uint(x2);
    x3 = x2;
    makeBigEndian!uint(x3);
    makeFromLittleEndian!uint(x4);
    makeLittleEndian!uint(x4);
} else {        
    makeFromLittleEndian!uint(x2);
    x3 = x2;
    makeLittleEndian!uint(x3);
    makeFromBigEndian!uint(x4);
    makeBigEndian!uint(x4);
}    
assert(x1 != x2);
assert(x1 == x3);
assert(x4 == x1);

immutable rawdata = cast(immutable(ubyte)[])(
    "the quick brown fox jumps over the lazy dog\r
     the quick brown fox jumps over the lazy dog\r");

Envelope e1 = Envelope(1,0,rawdata);
immutable b1 = e1.toBuffer();
Envelope e2 = Envelope(b1);
assert(!e2.errorstate, e2.errors[0]);
assert(e2.header.isValid);
assert(e2.header.datsize == rawdata.length);
assert(e2.header.schema == 1);
const b2 = e2.toData();
assert(b2 == rawdata);

Envelope e3 = Envelope(1,9,rawdata);
immutable b3 = e3.toBuffer();
Envelope e4 = Envelope(b3);
assert(e4.header.isValid());
const b4 = e4.toData();
assert(b4 == rawdata);