Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
209fe91b
Commit
209fe91b
authored
Oct 07, 2018
by
devsaurus
Browse files
add encoder doc
parent
9ab7e7fa
Changes
2
Hide whitespace changes
Inline
Side-by-side
docs/en/modules/encoder.md
0 → 100644
View file @
209fe91b
# encoder Module
| Since | Origin / Contributor | Maintainer | Source |
| :----- | :-------------------- | :---------- | :------ |
| 2016-02-26 |
[
Terry Ellison
](
https://github.com/TerryE
)
|
[
Terry Ellison
](
https://github.com/TerryE
)
|
[
encoder.c
](
../../../app/modules/encoder.c
)
|
The encoder modules provides various functions for encoding and decoding byte data.
## encoder.toBase64()
Provides a Base64 representation of a (binary) Lua string.
#### Syntax
`b64 = encoder.toBase64(binary)`
#### Parameters
`binary`
input string to Base64 encode
#### Return
A Base64 encoded string.
#### Example
```
lua
print
(
encoder
.
toBase64
(
crypto
.
hash
(
"sha1"
,
"abc"
)))
```
## encoder.fromBase64()
Decodes a Base64 representation of a (binary) Lua string back into the original string. An error is
thrown if the string is not a valid base64 encoding.
#### Syntax
`binary_string = encoder.toBase64(b64)`
#### Parameters
`b64`
Base64 encoded input string
#### Return
The decoded Lua (binary) string.
#### Example
```
lua
print
(
encoder
.
fromBase64
(
encoder
.
toBase64
(
"hello world"
)))
```
## encoder.toHex()
Provides an ASCII hex representation of a (binary) Lua string. Each byte in the input string is
represented as two hex characters in the output.
#### Syntax
`hexstr = encoder.toHex(binary)`
#### Parameters
`binary`
input string to get hex representation for
#### Returns
An ASCII hex string.
#### Example
```
lua
print
(
encoder
.
toHex
(
crypto
.
hash
(
"sha1"
,
"abc"
)))
```
## encoder.fromHex()
Returns the Lua binary string decode of a ASCII hex string. Each byte in the output string is
represented as two hex characters in the input. An error is thrown if the string is not a
valid base64 encoding.
#### Syntax
`binary = encoder.fromHex(hexstr)`
#### Parameters
`hexstr`
An ASCII hex string.
#### Returns
Decoded string of hex representation.
#### Example
```
lua
print
(
encoder
.
fromHex
(
"6a6a6a"
)))
```
mkdocs.yml
View file @
209fe91b
...
@@ -36,6 +36,7 @@ pages:
...
@@ -36,6 +36,7 @@ pages:
-
'
bthci'
:
'
en/modules/bthci.md'
-
'
bthci'
:
'
en/modules/bthci.md'
-
'
can'
:
'
en/modules/can.md'
-
'
can'
:
'
en/modules/can.md'
-
'
dht'
:
'
en/modules/dht.md'
-
'
dht'
:
'
en/modules/dht.md'
-
'
encoder'
:
'
en/modules/encoder.md'
-
'
file'
:
'
en/modules/file.md'
-
'
file'
:
'
en/modules/file.md'
-
'
gpio'
:
'
en/modules/gpio.md'
-
'
gpio'
:
'
en/modules/gpio.md'
-
'
i2c'
:
'
en/modules/i2c.md'
-
'
i2c'
:
'
en/modules/i2c.md'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment