You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I want to use boost::serialize() to store class S2PointIndex as binary stream,
how do I do it?
Do I need to implement my own serialization function for S2PointIndex ?
Thanks.
Hi @smcallis , thanks for your reply.
Could you elaborate more on the way to do it?
I'm currently tracing class S2PointIndex and think I need to serialize S2Point, S2CellId, and s2internal::BTreeMultimap.
The last one BTreeMultimap is a little bit complicated, so I'm stuck at this point.
Could you provide more details on how to implement serialize() function for this class?
Thank you very much!
S2Point and S2CellId already have Encode/Init methods so they can serialize themselves for you. s2internal::BTreeMultimap is just absl::btree_multimap. I'd probably just iterate that container and store pairs of (S2CellId, [list of data]), then read that back into a new absl::btree_multimap when decoding. That might not be the absolute most efficient encoding space-wise but it is simple. I'd worry more about the fact that PointIndex takes a template parameter for the data, so you'll have to serialize the data type too.
S2Point and S2CellId already have Encode/Init methods so they can serialize themselves for you. s2internal::BTreeMultimap is just absl::btree_multimap. I'd probably just iterate that container and store pairs of (S2CellId, [list of data]), then read that back into a new absl::btree_multimap when decoding. That might not be the absolute most efficient encoding space-wise but it is simple. I'd worry more about the fact that PointIndex takes a template parameter for the data, so you'll have to serialize the data type too.
Thank you so much for your reply!
So your point is, for S2Point and S2CellId I don't need to write any codes to serialize them?
And for s2internal::BTreeMultimap, in addition to the container I need to handle the parameter.
I noticed the BTreeMultimap is instantiated like this: container_internal::btree<container_internal:: map_params<Key, Value, Compare, Alloc,/*TargetNodeSize=*/256,/*IsMulti=*/true>>
Did you mean I'll need to serialize map_params<> ?
I noticed map_params inherits common_params which inherits common_policy_traits.
I wonder how deep I should trace in order to successfully store all the necessary data.
Thank you!
You'll have to write code to hook S2Point and S2CellId into boost::serialize, but you can probably do that using their existing Encode/Init methods. I don't think you'll need to worry about storing the map params, that's a runtime detail different from storing the data in a serialized form.
Activity
smcallis commentedon Oct 31, 2023
GoroYeh-HRI commentedon Nov 1, 2023
Hi @smcallis , thanks for your reply.
Could you elaborate more on the way to do it?
I'm currently tracing class
S2PointIndexand think I need to serializeS2Point,S2CellId, ands2internal::BTreeMultimap.The last one
BTreeMultimapis a little bit complicated, so I'm stuck at this point.Could you provide more details on how to implement serialize() function for this class?
Thank you very much!
smcallis commentedon Nov 1, 2023
S2Point and S2CellId already have Encode/Init methods so they can serialize themselves for you. s2internal::BTreeMultimap is just absl::btree_multimap. I'd probably just iterate that container and store pairs of (S2CellId, [list of data]), then read that back into a new absl::btree_multimap when decoding. That might not be the absolute most efficient encoding space-wise but it is simple. I'd worry more about the fact that PointIndex takes a template parameter for the data, so you'll have to serialize the data type too.
GoroYeh-HRI commentedon Nov 1, 2023
Thank you so much for your reply!
So your point is, for S2Point and S2CellId I don't need to write any codes to serialize them?
And for s2internal::BTreeMultimap, in addition to the container I need to handle the parameter.
I noticed the BTreeMultimap is instantiated like this:
container_internal::btree<container_internal:: map_params<Key, Value, Compare, Alloc,/*TargetNodeSize=*/256,/*IsMulti=*/true>>Did you mean I'll need to serialize
map_params<>?I noticed map_params inherits common_params which inherits common_policy_traits.
I wonder how deep I should trace in order to successfully store all the necessary data.
Thank you!
smcallis commentedon Nov 1, 2023
You'll have to write code to hook S2Point and S2CellId into boost::serialize, but you can probably do that using their existing Encode/Init methods. I don't think you'll need to worry about storing the map params, that's a runtime detail different from storing the data in a serialized form.