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

Enable use of DIS 6 and DIS 7 in same library #25

Open
B1Dobbs opened this issue Sep 11, 2023 · 0 comments
Open

Enable use of DIS 6 and DIS 7 in same library #25

B1Dobbs opened this issue Sep 11, 2023 · 0 comments

Comments

@B1Dobbs
Copy link

B1Dobbs commented Sep 11, 2023

With the way functions are declared on a global variable 'dis', it makes it fairly difficult to use both DIS 6 and DIS 7 in the same module. We have a need to support both versions and potentially DIS 8 when it comes along. Instead of declaring everything to one variable 'dis', could each version assign it to 'disX' where 'X' is the version number?

Example of issue:

const dis6 = require('open-dis') // don't need relative import because module 'main' points to dis6.min.js
const dis7 = require("../../../../node_modules/open-dis/dist/dis7.min.js"); // overwrites all 'dis' functions to dis7 version

var entityStatePdu_dis6 = new dis6.EntityStatePdu();
entityStatePdu_dis6.entityID.entity = 1;
var entityStatePdu_dis7 = new dis7.EntityStatePdu();
entityStatePdu_dis6.entityID.entityID = 1;

var ab = new ArrayBuffer(1500);
var outputstream = new dis.OutputStream(ab)
entityStatePdu_dis6.encodeToBinary(outputStream) // would encode pdu.entityID.entityID instead of pdu.entityID.entity
entityStatePdu_dis7.encodeToBinary(outputStream) // encodes pdu.entityID.entityID as expected

A way I got around this was to reset the global dis.EntityID function before any pdu creation but this would get very unwieldy for a more complex pdu.

const dis6 = require('open-dis');
const dis7 = require("../../../../node_modules/open-dis/dist/dis7.min.js");

var pdu; // dummy variable for example, would be an dis.Pdu object
if(pdu.protocolVersion == 7) {
    global.dis.EntityID = dis7.EntityID;
    pdu = new dis7.EntityStatePdu();
} else {
    global.dis.EntityID = dis6.EntityID;
    pdu = new dis6.EntityStatePdu();
}

Would definitely appreciate any advice if there is a better way to get around this!

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

1 participant