porting @havocp's SerializedValue