Skip to content

Base64::encode : const correctness / String by reference passing #6581

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

Merged
merged 2 commits into from
Oct 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions cores/esp8266/base64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ extern "C" {

/**
* convert input data to base64
* @param data uint8_t *
* @param data const uint8_t *
* @param length size_t
* @return String
*/
String base64::encode(uint8_t * data, size_t length, bool doNewLines) {
String base64::encode(const uint8_t * data, size_t length, bool doNewLines) {
// base64 needs more size then the source data, use cencode.h macros
size_t size = ((doNewLines ? base64_encode_expected_len(length)
: base64_encode_expected_len_nonewlines(length)) + 1);
Expand All @@ -62,10 +62,10 @@ String base64::encode(uint8_t * data, size_t length, bool doNewLines) {

/**
* convert input data to base64
* @param text String
* @param text const String&
* @return String
*/
String base64::encode(String text, bool doNewLines) {
return base64::encode((uint8_t *) text.c_str(), text.length(), doNewLines);
String base64::encode(const String& text, bool doNewLines) {
return base64::encode((const uint8_t *) text.c_str(), text.length(), doNewLines);
}

4 changes: 2 additions & 2 deletions cores/esp8266/base64.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class base64 {
// NOTE: The default behaviour of backend (lib64)
// is to add a newline every 72 (encoded) characters output.
// This may 'break' longer uris and json variables
static String encode(uint8_t * data, size_t length, bool doNewLines = true);
static String encode(String text, bool doNewLines = true);
static String encode(const uint8_t * data, size_t length, bool doNewLines = true);
static String encode(const String& text, bool doNewLines = true);
private:
};

Expand Down