-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Diffing_Engine: Implement hashing #1100
Comments
We do serialise to BHoM_Engine/Serialiser_Engine/Convert/Json.cs Lines 41 to 48 in 4c83c15
BHoM_Engine/Serialiser_Engine/Convert/Bson.cs Lines 47 to 60 in 4c83c15
Probably obj.ToBson().AsByteArray can help?
|
As discussed during our chat, that's definitely an excellent suggestion, thanks! |
I've now incorporated Eduardo's suggestion in the diffing engine -- hashing happens through MongoDB's BSON, that generates a SHA-64 hash |
After some thoughts and discussions, we concluded that the diffing (at least its first step, which is the "collection-level" diffing) should rather work with hashes than with custom comparers.
This is for several reasons:
Downside:
I don't think the downside should be seen as a problem. I can't find any good reason why we should support duplicates. If a case like that exists, I think we should rather rethink why/how that case is allowed to exist.
1. Hashing requirements
BH.oM.Base.BHoMObject GUID
BH.oM.Base.BHoMObject CustomData
?)2. Algorithm to generate the hash
The standard .NET GetHash() returns different results based on the environment. In other words, for example, for the same identical string two different users could get two different hashes.
So we can't just implement the standard .NET GetHash().
Since we need a platform-independent algorithm to generate hashes, we could use:
3. Serialization to generate hashing
Hashing algorithms require the object to be Serialised in Byte[].
The serialisation requires all classes to be marked as
[Serializable]
. Which we don't want.We can not add the Serializable attribute at runtime, either.
So we need another serializer.
3.1
Protobuf-net(deprecated proposal)A workaround could be to use Protocol Buffers to serialise to byte[], selecting the properties we want to serialise. This would also allow to solve point (2): it seems easy to exclude properties we don't want to be part of the serialization (therefore not in the fingerprint).
3.2 Use of MongoDB
As Eduardo suggested, we already have a good serializer in Mongo_Toolkit and we can leverage it.
We just need to find a way to avoid serializing some types. These exceptions will work as custom comparer for objects.
The text was updated successfully, but these errors were encountered: