Orange serializer/deserializer

InfiniteDimensional IntegratedDimensions at gmail.com
Tue Jun 5 17:47:01 UTC 2018


On Saturday, 2 June 2018 at 20:11:17 UTC, Jacob Carlborg wrote:
> On 2018-06-02 03:30, IntegratedDimensions wrote:
>> How can I modify the pre serialization and post serialization 
>> values? I need to transform some variables that are stored but 
>> I would like to do this easily "inline"(would be cool to be 
>> able to provide a delegate to do the transformations at the 
>> site of definition of the fields).
>
> Use the "onSerializing" and "onSerialized" UDAs on a method. 
> "onSerializing" will be called before serializing and 
> "onSerialized" after serializing. Have a look at the unit tests 
> [1].
>
>> Also, how does orange handle properties? Seems it just deals 
>> with fields and ignores all functions(does not use getter and 
>> setter of properties). This is valid, of course, just want to 
>> make sure. I still need to be able to transform values pre and 
>> post though.
>
> That is correct, it only (de)serializes fields. If you want to 
> (de)serialize proprieties, implement the "toData" and 
> "fromData". See the example in the wiki [2]. Note, by 
> implementing these methods none of the standard serialization 
> will occur. If you want to serialize the fields as well, you 
> need to do that as well when implementing "toData" and 
> "fromData".
>
> It's also possible to implement these "methods" in a 
> non-intrusive way, i.e. for customizing serialization of third 
> party type [3].
>
> [1] 
> https://github.com/jacob-carlborg/orange/blob/master/tests/Events.d#L39-L54
>
> [2] 
> https://github.com/jacob-carlborg/orange/wiki/Custom-Serialization
>
> [3] 
> https://github.com/jacob-carlborg/orange/blob/master/tests/NonIntrusive.d


Thanks.

I'm having problems preventing void* pointers from not being 
serialized

..\..\..\orange\serialization\Serializer.d(975): Error: 
expression `*value` is `void` and has no value

..\..\..\orange\serialization\Serializer.d(1491): Error: new can 
only create structs, dynamic arrays or class objects, not `void`'s


and all I've added to my class is

@nonSerialized void* ptr;

It seems that the (de)serializer should just ignore all void's no 
matter what. They can't be serialized to any meaningful thing. 
Maybe spit a warning out if the uda is not added. Usually pointer 
values are not meant to be serialized anyways.




More information about the Digitalmars-d-learn mailing list