A function to handle multiple datatypes

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?

OK, as requested, more information.
The receiving end is not an arduino, but a machine running Ubuntu. I am fairly certain that is has the same endian-ness as everything I have sent so far I have managed to receive without having to switch the byte-order. Floats are tricky, due to different ways of representing them and their inherent inaccuracy, so I am not going to use any. Nope, no unicode. Error checking will be via a checksum byte at the end of the serial packet (note: I have not implemented this bit yet). Immediately prior to calling sendAnything the program outputs 0xFE, which signifies the start of the frame, followed by a one byte code signifying the type of data being sent and another byte containing the address or destination code. After all the data is sent the code 0xFE is sent again to signify the end of the frame.

With this in mind the sendAnything function can be re-written to look like this:

template <class T> void sendAnything(const T& value, byte type, byte address)
{
    const byte* p = (const byte*)&value;
    unsigned int i;
    Serial.write(0x7E);
    Serial.write(type);
    Serial.write(address);
    for (i = 0; i < sizeof(value); i++) {
      if (*p == 0x7E || *p == 0x7D) {
        Serial.write(0x7D);
        Serial.write(*p++ ^ 0x20);
      } else {
        Serial.write(*p++);
      }
    }
    Serial.write(0x7E);
}

The data types I will have to send are: 8, 16 and 32 bit integers, both signed and unsigned. Strings of up to 20 characters in length, null terminated as per normal strings.
At the moment I don't need to send objects or structures, but I may have to in the future.

So with that in mind, maybe sendAnything should be sendSomeThings :stuck_out_tongue: