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

feat(scripting/v8): expose msgpack codec globally for custom type sup… #2931

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

JustGodWork
Copy link

Goal of this PR

Expose the msgpack codec globally to enable developers to easily add custom serializers and deserializers, enhancing flexibility for handling custom types in FiveM scripts.

How is this PR achieving the goal

This PR adds a new global variable, global.msgpack_codec, which provides direct access to the existing msgpack codec. Developers can use this to register custom types via addExtPacker and addExtUnpacker while maintaining backward compatibility with the current global.msgpack_pack and global.msgpack_unpack functions.

This PR applies to the following area(s)

  • Core scripting framework
  • Data serialization/deserialization using msgpack

Successfully tested on

Game builds:: 3258

Platforms: Windows

Checklist

  • Code compiles and has been tested successfully.
  • Code explains itself well and/or is documented.
  • My commit message explains what the changes do and what they are for.
  • No extra compilation warnings are added by these changes.

Fixes issues

No specific issues reported for this feature addition.

…port

- Added `global.msgpack_codec` to provide access to the msgpack codec.
- Enables developers to easily add custom serializers/deserializers.
- Maintains backward compatibility with existing msgpack_pack/unpack functions.
@github-actions github-actions bot added the triage Needs a preliminary assessment to determine the urgency and required action label Nov 15, 2024
@JustGodWork
Copy link
Author

Here is a link to my documentation pull request: citizenfx/fivem-docs#503

@thelindat
Copy link
Contributor

Personally I'd like to see a modern and more efficient msgpack implemented before we get access to the codec.

The current one hasn't been touched for 8 years and is lacking a lot of JS features. https://github.com/kawanet/msgpack-lite

@AvarianKnight might also have some thoughts on this.

@AvarianKnight
Copy link
Contributor

Personally I'd like to see a modern and more efficient msgpack implemented before we get access to the codec.

The current one hasn't been touched for 8 years and is lacking a lot of JS features. https://github.com/kawanet/msgpack-lite

@AvarianKnight might also have some thoughts on this.

There's a lot better encoders/decoders for msgpack now and it would make a lot of sense to swap to them (see msgpackr for one that's really fast, and blows out all current implementations)

@JustGodWork
Copy link
Author

Personally I'd like to see a modern and more efficient msgpack implemented before we get access to the codec.
The current one hasn't been touched for 8 years and is lacking a lot of JS features. https://github.com/kawanet/msgpack-lite
@AvarianKnight might also have some thoughts on this.

There's a lot better encoders/decoders for msgpack now and it would make a lot of sense to swap to them (see msgpackr for one that's really fast, and blows out all current implementations)

Thank you for the suggestion! (I don't know if this message is directed to the right place.)
I’ve been researching and testing msgpackr, and I agree it’s an impressive library with great performance. However, implementing it poses some significant challenges.

Here’s what I’ve managed so far and the issues I’ve encountered:

  • Progress Achieved:
    • I’ve successfully implemented msgpackr for standard arguments serialization/deserilization.
    • Function References work as excepted when triggering from LUA to JS with a LUA function as argument.
  • Challenges Remaining:
    • Function References: I haven’t been able to make function references work correctly when triggering from JS to LUA.

Note: I have not made any test with C#.

These challenges would require additional development to resolve and could impact other parts of the project. I’d love to hear your thoughts or suggestions on addressing these issues.

Additionally, if you'd like, I can share the code I’ve worked on so far to help provide more context. Please let me know where and how I should share it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage Needs a preliminary assessment to determine the urgency and required action
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants