Skip to content

Commit

Permalink
add example.
Browse files Browse the repository at this point in the history
  • Loading branch information
dojyorin committed Jul 21, 2020
1 parent fbc81b6 commit c0a8ead
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
37 changes: 32 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,32 @@
Binary based simple Base64 Codec for Arduino.


# Example
## Encode
```c++
const char* rawData = "foobar";
size_t rawSize = strlen(rawData);

char encoded[BASE64::encodeLength(rawSize)];
BASE64::encode((const uint8_t*)rawData, encoded, rawSize);

Serial.println(encoded);
```
## Decode
```c++
const char* encodedData = "Zm9vYmFy";
uint8_t raw[BASE64::decodeLength(encodedData)];
BASE64::decode(encodedData, raw);
Serial.println((char*)raw);
```


# API
## `void BASE64::encode(const uint8_t* input, char* output, size_t length)`
## void BASE64::encode(const uint8_t* input, char* output, size_t length)
**Arguments**
- `input`: Receives raw binary data as a byte array.
- `output`: Base64 encoded string.
Expand All @@ -13,27 +37,30 @@ Binary based simple Base64 Codec for Arduino.
- Nothing.

**Note**
- If the input data is a `char*`, cast it to `uint8_t*`.
- If the input data is `char*` string, cast it to `uint8_t*`.


## `size_t BASE64::encodeLength(size_t length)`
## size_t BASE64::encodeLength(size_t length)
**Arguments**
- `length`: Number of bytes of input data.

**Return**
- Number of characters after Base64 encoding.


## `void BASE64::decode(const char* input, uint8_t* output)`
## void BASE64::decode(const char* input, uint8_t* output)
**Arguments**
- `input`: Receives string data as a base64 encoded.
- `output`: Raw binary data.

**Return**
- Nothing.

**Note**
- If the output data is string, you can cast it to `char*`.


## `size_t BASE64::decodeLength(const char* input)`
## size_t BASE64::decodeLength(const char* input)
**Arguments**
- `input`: Receives string data as a base64 encoded.

Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Base64_Codec
version=1.0.0
version=1.0.2
author=dojyorin
maintainer=https://github.com/dojyorin
sentence=Base64 Codec
Expand Down

0 comments on commit c0a8ead

Please sign in to comment.