Skip to content
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

DL duplicates data when using pointers to structs #152

Open
Tisten opened this issue Oct 10, 2022 · 6 comments
Open

DL duplicates data when using pointers to structs #152

Tisten opened this issue Oct 10, 2022 · 6 comments

Comments

@Tisten
Copy link
Contributor

Tisten commented Oct 10, 2022

I've created a test for this in #151

I could try to solve it myself, but I'm not sure how to best put a tag on some data in JSON so a pointer can refer to it. Any opinions?

@lundmark
Copy link
Collaborator

From my PoV I'd appreciate it if they were separate json-objects serialized just like the actual data would look like in memory but as json instead. Then have the structs refer to them by index or something similar?

I guess there should be a storage passed in the serialization context that handles all existing references to serialized objects to handle this?

@Tisten
Copy link
Contributor Author

Tisten commented Oct 20, 2022

So all structs which someone points to will get a magic "__index" member which pointers can refer to?

@lundmark
Copy link
Collaborator

Something like that would make sense imo yes, I'm not sure what @wc-duck thinks tho?

@wc-duck
Copy link
Owner

wc-duck commented Oct 27, 2022

hmm... in that case we could just use any name, such as "__ref_id" or similar so that if you write it by hand you can just write something that makes sense.
It could always be generated as "my_type_1" or similar.

But also, this would only be needed if you reference an item that is also part of an array or struct right? Otherwise they are just put in
'__subdata' :
{
'__item_1' : {}
}

Right? Long time since I worked with the pointers? :)

@Tisten
Copy link
Contributor Author

Tisten commented Oct 27, 2022

Yes, that is right. I agree that writing something sensible when authoring it by hand is a great feature. And keeping pointer payloads which aren't used as arrays or members of structs is also fine, it is one correct way of doing it, and the closest to what is there today.

For improved json readability I could also imagine it working by putting each pointer payload in the place where it is first referred to, and then all other pointers to it will just refer to the "__ref_id". But that is a matter of taste, both would work and option 1 is probably least work.

@Tisten
Copy link
Contributor Author

Tisten commented Feb 9, 2025

F.Y.I:
I have continued developing datalibrary based on our internal needs ever since 2022, and this issue is now solved using the "__ref_id" idea.
It also solved the "writing pointer payloads 'inline' " part of #147
I wont be able to make a pull request of the solution since it builds on the already created pull requests, and around 100 commits after those PRs are done. In my own fork I've also ditched 32 bit support and strict C compatibility, so it is no longer possible to simply merge the code with your original repository.
That said, I would love to make our alternative version available as well, so if someone want to make the effort to merge something, then at least it could be done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants