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

How to produce array of float64 #109

Open
ahoora08 opened this issue Aug 7, 2018 · 1 comment
Open

How to produce array of float64 #109

ahoora08 opened this issue Aug 7, 2018 · 1 comment

Comments

@ahoora08
Copy link

ahoora08 commented Aug 7, 2018

I have an float64 array of size 129. I tried to produce it to Kafka:

       totalarray[0] = t0;
	for (i = 0; i < 40; i++) {
		totalarray[i + 1] = readanalog[i];
	}
	for (int j = 0; j < 88; j++) {
		totalarray[j+41] = data1[j];
	}
        builder.topic(TOPIC_NAME);
        builder.payload({totalarray, 129});
        producer.produce(builder);

But I got the errro:

In file included from /usr/local/include/cppkafka/producer.h:36:0,
                 from main.cpp:12:
/usr/local/include/cppkafka/buffer.h: In instantiation of ‘cppkafka::Buffer::Buffer(const T*, size_t) [with T = double; size_t = long unsigned int]’:
main.cpp:145:42:   required from here
/usr/local/include/cppkafka/buffer.h:78:9: error: static assertion failed: sizeof(T) != sizeof(DataType)
         static_assert(sizeof(T) == sizeof(DataType), "sizeof(T) != sizeof(DataType)");
         ^

How can I fix the error?

@mfontanini
Copy link
Owner

mfontanini commented Aug 7, 2018

Constructing Buffers from arbitrary pointers is not allowed unless the type the pointer points to is one byte long. So you can basically write chars, uint8_t, etc, but writing float is a bad idea given the representation of them can be different on one platform and another.

If you still want to do this, you can cast the pointer to something like a char*. e.g.

const char* ptr = reinterpret_cast<const char*>(totalArray);
builder.payload({ ptr, 129 * sizeof(float64) });

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