diff --git a/examples/decode/decode.ino b/examples/decode/decode.ino index 275f043..5513849 100644 --- a/examples/decode/decode.ino +++ b/examples/decode/decode.ino @@ -4,12 +4,11 @@ void setup(){ Serial.begin(115200); while(!Serial); - const char data[] = "F3c7EYKkxMgnvO0nB8FWVw=="; - uint8_t result[base64::decodeLength(data)]; + const char input[] = "F3c7EYKkxMgnvO0nB8FWVw=="; + uint8_t output[base64::decodeLength(input)]; + base64::decode(input, output); - base64::decode(data, result); - - Serial.println((const char*)result); + Serial.println((const char*)output); } void loop(){} \ No newline at end of file diff --git a/examples/encode/encode.ino b/examples/encode/encode.ino index 217e0ab..2e6ec72 100644 --- a/examples/encode/encode.ino +++ b/examples/encode/encode.ino @@ -4,13 +4,12 @@ void setup(){ Serial.begin(115200); while(!Serial); - const uint8_t data[] = {0x17, 0x77, 0x3B, 0x11, 0x82, 0xA4, 0xC4, 0xC8, 0x27, 0xBC, 0xED, 0x27, 0x07, 0xC1, 0x56, 0x57}; - auto dataLength = sizeof(data); - char result[base64::encodeLength(dataLength)]; + const uint8_t input[] = {0x17, 0x77, 0x3B, 0x11, 0x82, 0xA4, 0xC4, 0xC8}; + auto inputLength = sizeof(input); + char output[base64::encodeLength(inputLength)]; + base64::encode(input, inputLength, output); - base64::encode(data, dataLength, result); - - Serial.println(result); + Serial.println(output); } void loop(){} \ No newline at end of file diff --git a/src/arduino_base64.hpp b/src/arduino_base64.hpp index 5913ee6..4eb78dc 100644 --- a/src/arduino_base64.hpp +++ b/src/arduino_base64.hpp @@ -13,6 +13,10 @@ namespace base64{ * If input is string, cast to `uint8_t*`. * @example * ```c++ + * const uint8_t input[] = {0x17, 0x77, 0x3B, 0x11, 0x82, 0xA4, 0xC4, 0xC8}; + * auto inputLength = sizeof(input); + * char output[base64::encodeLength(inputLength)]; + * base64::encode(input, inputLength, output); * ``` */ void encode(const uint8_t* input, size_t inputLength, char* output); @@ -21,6 +25,10 @@ namespace base64{ * Calculate number of output characters. * @example * ```c++ + * const uint8_t input[] = {0x17, 0x77, 0x3B, 0x11, 0x82, 0xA4, 0xC4, 0xC8}; + * auto inputLength = sizeof(input); + * char output[base64::encodeLength(inputLength)]; + * base64::encode(input, inputLength, output); * ``` */ size_t encodeLength(size_t inputLength); @@ -30,6 +38,9 @@ namespace base64{ * If output is string, cast to `char*`. * @example * ```c++ + * const char input[] = "F3c7EYKkxMgnvO0nB8FWVw=="; + * uint8_t output[base64::decodeLength(input)]; + * base64::decode(input, output); * ``` */ void decode(const char* input, uint8_t* output); @@ -38,6 +49,9 @@ namespace base64{ * Calculate number of output bytes. * @example * ```c++ + * const char input[] = "F3c7EYKkxMgnvO0nB8FWVw=="; + * uint8_t output[base64::decodeLength(input)]; + * base64::decode(input, output); * ``` */ size_t decodeLength(const char* input);