A function to handle multiple datatypes

pekkaa:
After what pYro_65 just demonstrated, I am inclined to claim that for OP's case the sendAnything(const byte *value, unsigned int size) is more reasonable that all the extra hassle that the template alternative would require.

Well let's not get too carried away. In five pages of this thread I am the only one who has posted an actual working sketch, and that sketch showed that the templated solution was simple, and produced shorter code. The rest is hypothetical talk about needing to serialize "an object" or "lots of different types".

Sure, you can invent an example where pointers might be simpler or produce less code, but how about seeing an actual example of the types of data that need to be serialized? In other words, the real requirement, not some sort of hypothetical requirement.

It would have been helpful if the original post had actually quoted some code, or the actual data types, rather than just "a string of characters or an integer or an object". That's pretty vague. Does the string of characters contain every possible value (eg. including 0x00)? Is it a 2-byte integer? What sort of object is it?

Is the receiving end an Arduino? Does it have the same endian-ness? Does it have the same float representation? Is Unicode involved? How do you handle errors? Do you want sumchecks? How do you know if you are receiving the string of characters, or the integer, or the object?