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

serializeMsgPack for unsigned char (uint8_t) #1142

Closed
Piruthivi opened this issue Dec 12, 2019 · 3 comments
Closed

serializeMsgPack for unsigned char (uint8_t) #1142

Piruthivi opened this issue Dec 12, 2019 · 3 comments
Labels
bug v6 ArduinoJson 6

Comments

@Piruthivi
Copy link

Hi, Am new to json format data and c++ too. I found it amusing, it is very easy to build a json when started to json generator example. And it is simple to use. Now lets see what my doubt is.

By using ArduinoJson library i can serializeJson to a character array and to a uart port like Serial1 or SerialUSB.
Similarly same can be done with serializeMsgPack. Now the tricky part is i need to use unsigned char for serialize message pack.
I did saw a "Custom Writer" could be a solution, but didnt have a clue to use it. Does it need to be added in the library files or in the program(.ino) files i have been using.

If i call serializeMsgPack(doc,(uint8_t) data) getting following error

_In member function 'size_t CustomWriter::write(uint8_t)':

abputilitypacket:22:9: error: request for member 'append' in '((CustomWriter*)this)->CustomWriter::str', which is of non-class type 'uint8_t {aka unsigned char}'

 str.append(1, static_cast<char>(c));

     ^_

If i could solve this i can move forward in my project. And thanks in advance.

@bblanchon
Copy link
Owner

Hi @Piruthivi,

serializeMsgPack() should support uint8_t, it's an omission from my part.
I'll fix this as soon as possible.

Meanwhile, you can cast the pointer to char*:

serializeMsgPack(doc, reinterpret_cast<char*>(data), sizeof(data));

Best Regards,
Benoit

@bblanchon bblanchon added the bug label Dec 12, 2019
@Piruthivi
Copy link
Author

Thanks for the reply.
So i tried by type casting it.

unsigned char hex_data[100];
serializeMsgPack(doc,(char *) hex_data);

compilation shows

_error: macro "min" passed 3 arguments, but takes just 2

 min(const _Tp& __a, const _Tp& __b, _Compare __comp)_

Don't know am doing it right but just sharing the info.
So it didn't worked for me.

@bblanchon
Copy link
Owner

Hi @Piruthivi,

I just pushed a fix for this issue. Please try with the "6.x" branch; you should be able to write serializeJson(doc, hex_data) without casting.

Best Regards,
Benoit

Repository owner locked and limited conversation to collaborators Jan 13, 2020
stawiski pushed a commit to stawiski/ArduinoJson that referenced this issue Jul 28, 2020
@bblanchon bblanchon added the v6 ArduinoJson 6 label Feb 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug v6 ArduinoJson 6
Projects
None yet
Development

No branches or pull requests

2 participants