Skip to content

Commit 952f457

Browse files
committed
Moved the base 64 alphabet into PROGMEM to save ram
1 parent 7955b0c commit 952f457

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Diff for: Base64.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "Base64.h"
2-
3-
const char b64_alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
2+
#include <avr/pgmspace.h>
3+
const char PROGMEM b64_alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
44
"abcdefghijklmnopqrstuvwxyz"
55
"0123456789+/";
66

@@ -21,7 +21,7 @@ int base64_encode(char *output, char *input, int inputLen) {
2121
a3_to_a4(a4, a3);
2222

2323
for(i = 0; i < 4; i++) {
24-
output[encLen++] = b64_alphabet[a4[i]];
24+
output[encLen++] = pgm_read_byte(&b64_alphabet[a4[i]]);
2525
}
2626

2727
i = 0;
@@ -36,7 +36,7 @@ int base64_encode(char *output, char *input, int inputLen) {
3636
a3_to_a4(a4, a3);
3737

3838
for(j = 0; j < i + 1; j++) {
39-
output[encLen++] = b64_alphabet[a4[j]];
39+
output[encLen++] = pgm_read_byte(&b64_alphabet[a4[j]]);
4040
}
4141

4242
while((i++ < 3)) {

0 commit comments

Comments
 (0)