base256
Install
$ go get -u ekyu.moe/base256
# or better
$ dep ensure -add ekyu.moe/base256
Example
package main
import (
"fmt"
"ekyu.moe/base256"
)
func main() {
fmt.Println(base256.EncodeToString([]byte("Hello, δΈη"))) //=> πΎπ§ππ¬ππ±πππ¦π₯π΄π€π
fmt.Println(string(base256.DecodeString("πΎπ§ππ¬ππ±πππ¦π₯π΄π€π"))) //=> Hello, δΈη
}
Check godoc for further documents.
A CLI utility is also available with go get ekyu.moe/base256/cmd/base256
.
Specification
base256 encoding uses two tables to transform a single byte into a single emoji. The tables can be found in table.go. In this implementation, these tables are utilized circularly when encoding, however such rule does not apply to decoding.
To achieve the best compatibility, all the emojis are picked from the classic version and each of them is guaranteed to be 4 bytes long in UTF-8.