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

Sending binary data #159

Open
ggallea opened this issue Aug 23, 2022 · 8 comments
Open

Sending binary data #159

ggallea opened this issue Aug 23, 2022 · 8 comments
Labels
❓ Question Further information is requested

Comments

@ggallea
Copy link

ggallea commented Aug 23, 2022

I am Reading data from binary file and trying to send the data I read to kafka.
I get the following error:
cannot unmarshal object into Go struct field Message.messages.value of type []uint8

What am I doing wrong?

Thanks

@mostafa
Copy link
Owner

mostafa commented Aug 23, 2022

Hey @ggallea,

Have a look at this example.

@ggallea
Copy link
Author

ggallea commented Aug 24, 2022

The example is serializing a string. I have numbers (float and int32) to send
I also tried with Uint8Array and it gave me the same error

@mostafa
Copy link
Owner

mostafa commented Aug 24, 2022

@ggallea
Can you send your script and some sample data, so I can use it to debug the issue?

@ggallea
Copy link
Author

ggallea commented Aug 28, 2022

How can I serialize (types other then string) to bytes (using the serialize function in SchemaRegistry)?

@c-meier
Copy link

c-meier commented Aug 29, 2022

Hello @mostafa,

Would it be possible to directly send an ArrayBuffer?

For the moment I do the following:

const body = encoding.b64decode(".............")  // returns an ArrayBuffer
writer.produce({ messages: [{
    value: schemaRegistry.serialize({
        data: Array.from(new Uint8Array(body)),
        schemaType: SCHEMA_TYPE_BYTES,
    }),
    key: ...
}]})

It works but it means a lot of transformations.

@mostafa
Copy link
Owner

mostafa commented Aug 29, 2022

Hey @c-meier,

you can read the reasoning behind making the serdes explicit in the following PR and its linked issues:

@c-meier
Copy link

c-meier commented Aug 29, 2022

Hello @mostafa,

My point wasn't about exporting the serdes functionality to JS (I think it works quite well). But that I think it would make more sense for SCHEMA_TYPE_BYTES to accept data as an ArrayBuffer (or maybe Uint8Array) instead of an Array[number]

EDIT: K6 seem to be using ArrayBuffer as the return type of most JS method which deal with binary data (see issue)

@mostafa
Copy link
Owner

mostafa commented Aug 29, 2022

@c-meier
Fair enough! Then I need to test it to see if and how it works. In the meantime, if you can help contribute some code, it'll be much appreciated.

@mostafa mostafa added the ❓ Question Further information is requested label Sep 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
❓ Question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants