Should I serialize my custom JSON when sending to Speckle

Hi guys!

I’m facing a similar challenge as describe in Custom TypeScript Speckle Connector. I wrote my own ts code (copying here and there ;)) to send objects and commit to speckle and back from a client-side app.
I do not convert my json to speckle object model, I just wrap it in a Base speckle object. So the data has my own structure (a mixed of serialized 3js data and my own).
When pushing on speckle, of course I don’t see anything in the viewer, but that’s ok for now. When I pull back in my app is already in the format I need. A bit of a hack but still… for now it’s ok.

The problem is that I sometimes reach the limit of 10MB for single object (since it’s one…).

What do you suggest me to do?
Doing the same as @chrkong doing, so a proper conversion to speckle, or there is a fastest route I can take for now?

Thanks!
Gianluca

It sounds likely you’re hitting the 10MB limit due to the way you’re wrapping your data. Instead of converting everything into Speckle objects, there’s a middle ground you can consider: serialising your data following specific conventions.

Speckle’s serializer uses certain conventions, such as @ prefixed keys, to manage data efficiently. Adopting these conventions allows you to manage larger datasets and potentially avoid hitting the 10MB limit.

Here’s a brief outline of how you can proceed:

  1. Use Christian’s Serializer/Deserializer: If you can find the code or approach that Christian used, this would likely be the quickest way to get up and running. His solution might already handle chunking and serialization conventions suitable for Speckle.
  2. Custom Serializer/Deserializer: If you prefer or need a more tailored approach, you can customise your own serializer/deserializer. Here’s a brief guide on how to do this:
    • Chunking: Break your large object into smaller chunks. Each chunk should be under the 10MB limit.
    • Serialization Conventions: Use Speckle’s conventions such as @ prefixed keys for metadata and references. This helps in managing and reassembling chunks efficiently.
    • Detaching: Separate larger parts of your object into detached references. This means creating smaller Speckle objects for substantial data sections and linking them.

This approach allows you to keep your existing structure while complying with Speckle’s data handling requirements. For detailed guidance.

AS YOU HAVE DISCOVERED WE DONT DO A GOOD JOB OF EQUIPPING YOU HERE WITH TOOLS OR DOCUMENTATION. :smiling_with_tear_spockle:

1 Like

Hi Jonathan,

Thanks for the tips.
Just a clarification.

Speckle’s serializer uses certain conventions, such as @ prefixed keys, to manage data efficiently.

If I prepare my data using the “@” detaching property and I add speckle_type property to my nested objects, Is this sufficient? Can I just wrap it on 1 json object and push it on speckle (using GraphQL mutation)? Or do I need to actually subdivide in chunks my self and and push each object separately?

Example:

dataToSend = {

   "speckle_type": "Base",
   "id": "ashs6",
   "name": "hello",
   "@heavyMesh1": {
      "speckle_type": "Base",
      "id": "3332c",
      "geometry": "my own heavy geometry"
   },
   "@heavyMesh2": {
      "speckle_type": "Base",
      "id": "3fg2c",
      "geometry": "my own heavy geometry"
   }

}

my question is: can I just send the above?
Or I have to send @heavyMesh1 and @heavyMesh2 separately, get the idObject back and place it in dataToSend under the respective property as reference?

Thank you!

this is where the serializer comes in - it will discombobulate your json blob into bite-sized speckly pieces

Yes, just to quickly clarify, the serialization in my example includes chunking and detaching.

Ok i’ll give it a go with Christian code.
@chrkong can I look in the git repo you set up for dimitrie? Is it working? Thanks!

Yes, the code in the repo is working. I even merged his changes

1 Like

Hey @iltabe and @chrkong - there’s some better news:

this was my hackaton project! - thanks to @fabians we’re also now publishing it to npm for ease of use :slight_smile:

for usage examples.

4 Likes

Nice @dimitrie !
I’ll try it out :slight_smile:

:heart_eyes:

4 Likes

vabbe, what kind of editor you hacking there :eyes: :eyes: :eyes: :eyes: