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

im noob #53

Open
estantaya opened this issue Jul 31, 2016 · 6 comments
Open

im noob #53

estantaya opened this issue Jul 31, 2016 · 6 comments

Comments

@estantaya
Copy link

estantaya commented Jul 31, 2016

it is possible?

var typeSet = {

    jBinary.all:'msh',

    msh: {
        artworks: ['string0', 9],
        version: ['array', 'uint8', 8],
        indices: ['array', 'uint8', 8],

        versionName: ['string0', 'indices[4]']
    }
};

'indices[4]' as variable

@RReverser
Copy link
Member

I don't know what you're trying to achieve, so can't answer your question. Also, please format your code using Markdown for better readability (wrap between ````javascript` and ````` lines).

@estantaya
Copy link
Author

sry
'indices[4]' as variable????
i use this for the moment

var typeSet = {
    artworks: ['string0', 9],
    version: ['array', 'uint8', 8],
    indices: ['array', 'uint8', 8],
};
    jBinary.load(files[0], typeSet, function (err, binary) {
        //var tar = binary.readAll;
        //console.log(tar);
        document.getElementById("empresa").value=binary.read('artworks');
        document.getElementById("version").value=binary.read('version');
        var indices=binary.read('indices');
        document.getElementById("indices").value=indices;
        document.getElementById("titulo").value=binary.read(['string0',indices[4]]);
        binary.skip(4);
        var color=binary.read(['array', 'uint8', 4]);
        for (i=0;i<color.length;i++) {
            document.getElementById("color"+i).value=color[i];
        }
    });

@RReverser
Copy link
Member

Now I see. No, you can't use ['string0', 'indices[4]'] directly, but you can pass a function from context as a second argument, see https://github.com/jDataView/jBinary/wiki/Standard-types#references for an example.

In your case, it will be smth like:

    msh: {
        artworks: ['string0', 9],
        version: ['array', 'uint8', 8],
        indices: ['array', 'uint8', 8],

        versionName: ['string0', function (context) {
            return context.indices[4];
        });
    }

or, if using ES6, ['string0', context => context.indices[4]].

Does this answer your question?

@estantaya
Copy link
Author

TypeError: Size is not a number.
if("number"!=typeof b)throw new TypeError("Size is not a number.");

var typeSet = {
    company: ['string0', 9],
    version: ['array', 'uint8', 8],
    indices: ['array', 'uint8', 8],
    versionName: ['string0', function (context) {
            return context.indices[4];
    }],
    color: ['array', 'uint8', 4]
};

input[5]=htmlEscape(binary.read('versionName'));

it does not work that way but I have no trouble reading the binary and arrays :)
I will return when I have trouble writing the data muahahaha

@RReverser
Copy link
Member

That's strange, can you do console.log(context) inside of that function (context) { ... } and tell what you see?

@estantaya
Copy link
Author

trow the same thing

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

2 participants