Added general buffer serialisation code.