ValueTree to XML and back value types question


#1

Hello,

I'm writing a thing that serialized a ValueTree to xml and back for storing the plugin state. However, the xmlalized ValueTree seems to discard var type information so that when I recreate the ValueTree from xml it thinks everything is a string. What's the best solution for this? I could parse all the strings into the correct type but that seems messy.

Thanks,

Rob


#2

Yeah, that is a drawback of using XML - the way the ValueTree gets converted to XML favours readability over type data.

The reason it's done like that is that if you don't need the output to be human-readable, then you'd be better off using the binary conversion, as it's both faster, smaller, and type-correct.


#3

Ah right, ok. So regarding plugin state saving, I could create a MemoryOutputStream to the state MemoryBlock and write the ValueTree to that? Would I need a "magic number" like in copyXmlToBinary()?


#4

That would certainly be more robust. Magic numbers are always good :)


#5

Thanks. Nothing else will be written into the state apart from the ValueTree, so I'm not gonna bother with magic.