API Reference — dna/Writer
class DNAAPI Writer : public RBFBehaviorWriter, public GeometryWriter, public MachineLearnedBehaviorExtWriter, public JointBehaviorMetadataWriter, public TwistSwingBehaviorWriter
Abstract unified write interface for all DNA data layers. Use this as the base type when you need to write a complete DNA asset — it combines geometry, behavior, machine-learned behavior, RBF, joint metadata, and twist/swing writing into a single entry point.
When to use this
Reach for Writer when you need to mutate or construct a DNA asset. Use setFrom to bulk-copy an entire existing asset from a Reader — optionally restricting which layers are transferred via DataLayer. Note that the layer hierarchy cannot be written selectively at the class level; the unified interface is intentional.
Example
// Obtain a Writer instance (e.g., from BinaryStreamWriter factory)
dna::Writer* writer = dna::BinaryStreamWriter::create(stream, memRes);
const dna::Reader* reader = dna::BinaryStreamReader::create(inputStream, memRes);
// Copy all layers, preserving any unknown data
writer->setFrom(reader, dna::DataLayer::All, dna::UnknownLayerPolicy::Preserve);
// Copy only geometry, discarding unrecognized layers
writer->setFrom(reader, dna::DataLayer::Geometry, dna::UnknownLayerPolicy::Discard);
Parameters
| Name | Type | Description |
|---|---|---|
source |
const Reader* |
required — the DNA Reader to copy data from |
layer |
DataLayer |
optional — limits which layers are transferred; defaults to DataLayer::All |
policy |
UnknownLayerPolicy |
optional — whether unrecognized layers are preserved or discarded; defaults to UnknownLayerPolicy::Preserve |
memRes |
MemoryResource* |
optional — memory resource for temporary allocations during the copy; defaults to nullptr |
Watch out for
- The
Writerclass intentionally cannot write only specific layers — the unified interface mirrors theReaderhierarchy by design. UseDataLayerinsetFromto control which layers are read from source, not which are written. setFromis implemented in the abstract base class itself and calls every getter onsourcethen every matching setter onthis. For large DNA assets, pass aMemoryResourceto avoid heap fragmentation during the copy.