Hi,
is this the way to go in order to generate the object id for the database (Deterministic 32 hex chars (128bit) guid based on MD5 of the object data) ???
UE5 code:
FString USpeckleMesh::CreateHash(FString Data)
{
FString hmd5 = FMD5::HashAnsiString(*Data);
UE_LOG(LogTemp, Log, TEXT("NEW HASH is ==== %s"), *hmd5 );
return hmd5;
}
@moihack
@Jedd
@Luca
References:
Which function is responsible in the C# core for generating the guid ?
https://github.com/specklesystems/speckle-sharp
1 Like
Jedd
(Jedd Morgan)
17 September 2022 08:31
4
Hi Dimitrios,
Here is the code in Speckle Sharp
public enum HashingFuctions
{
SHA256, MD5
}
/// <summary>
/// Wrapper method around hashing functions. Defaults to md5.
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public static string hashString(string input, HashingFuctions func = HashingFuctions.SHA256)
{
switch (func)
{
case HashingFuctions.SHA256:
return Utilities.sha256(input).Substring(0, HashLength);
case HashingFuctions.MD5:
default:
return Utilities.md5(input).Substring(0, HashLength);
And here in python
from specklepy.transports.abstract_transport import AbstractTransport
# import for serialization
import specklepy.objects.geometry
import specklepy.objects.other
PRIMITIVES = (int, float, str, bool)
def hash_obj(obj: Any) -> str:
return hashlib.sha256(ujson.dumps(obj).encode()).hexdigest()[:32]
def safe_json_loads(obj: str, obj_id=None) -> Any:
try:
return ujson.loads(obj)
except ValueError as err:
import json
warn(
f"Failed to deserialise object (id: {obj_id}). This is likely a ujson big int error - falling back to json. \nError: {err}",
1 Like