PackerImpl.pack

Serializes object and writes to stream.

Calling toMsgpack if $(D_KEYWORD class) and $(D_KEYWORD struct) implement toMsgpack method. toMsgpack signature is:

void toMsgpack(Packer)(ref Packer packer) const

This method serializes all members of T object if $(D_KEYWORD class) and $(D_KEYWORD struct) don't implement toMsgpack.

An object that doesn't implement toMsgpack is serialized to Array type.

packer.pack(tuple(true, 1, "Hi!"))  // -> '[true, 1, "Hi!"]', not 'ture, 1, "Hi!"'

struct Foo
{
    int num    = 10;
    string msg = "D!";
}
packer.pack(Foo());  // -> '[10, "D!"]'

class Base
{
    bool flag = true;
}
class Derived : Base
{
    double = 0.5f;
}
packer.pack(new Derived());  // -> '[true, 0.5f]'

Parameters

object T

the content to serialize.

Return Value

self, i.e. for method chaining.

Meta