-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from Q1-Energie-AG/rustler_0_22
- Loading branch information
Showing
8 changed files
with
69 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,5 @@ erl_crash.dump | |
tds_encoding-*.tar | ||
|
||
/priv/native/ | ||
|
||
/native/*/target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
%{ | ||
"earmark": {:hex, :earmark, "1.4.3", "364ca2e9710f6bff494117dbbd53880d84bebb692dafc3a78eb50aa3183f2bfd", [:mix], [], "hexpm"}, | ||
"ex_doc": {:hex, :ex_doc, "0.21.3", "857ec876b35a587c5d9148a2512e952e24c24345552259464b98bfbb883c7b42", [:mix], [{:earmark, "~> 1.4", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"}, | ||
"makeup": {:hex, :makeup, "1.0.0", "671df94cf5a594b739ce03b0d0316aa64312cee2574b6a44becb83cd90fb05dc", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"}, | ||
"makeup_elixir": {:hex, :makeup_elixir, "0.14.0", "cf8b7c66ad1cff4c14679698d532f0b5d45a3968ffbcbfd590339cb57742f1ae", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm"}, | ||
"nimble_parsec": {:hex, :nimble_parsec, "0.5.3", "def21c10a9ed70ce22754fdeea0810dafd53c2db3219a0cd54cf5526377af1c6", [:mix], [], "hexpm"}, | ||
"rustler": {:hex, :rustler, "0.21.0", "68cc4fc015d0b9541865ea78e78e9ef2dd91ee4be80bf543fd15791102a45aca", [:mix], [{:toml, "~> 0.5.2", [hex: :toml, repo: "hexpm", optional: false]}], "hexpm"}, | ||
"toml": {:hex, :toml, "0.5.2", "e471388a8726d1ce51a6b32f864b8228a1eb8edc907a0edf2bb50eab9321b526", [:mix], [], "hexpm"}, | ||
"earmark": {:hex, :earmark, "1.4.3", "364ca2e9710f6bff494117dbbd53880d84bebb692dafc3a78eb50aa3183f2bfd", [:mix], [], "hexpm", "8cf8a291ebf1c7b9539e3cddb19e9cef066c2441b1640f13c34c1d3cfc825fec"}, | ||
"earmark_parser": {:hex, :earmark_parser, "1.4.15", "b29e8e729f4aa4a00436580dcc2c9c5c51890613457c193cc8525c388ccb2f06", [:mix], [], "hexpm", "044523d6438ea19c1b8ec877ec221b008661d3c27e3b848f4c879f500421ca5c"}, | ||
"ex_doc": {:hex, :ex_doc, "0.25.3", "3edf6a0d70a39d2eafde030b8895501b1c93692effcbd21347296c18e47618ce", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "9ebebc2169ec732a38e9e779fd0418c9189b3ca93f4a676c961be6c1527913f5"}, | ||
"makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"}, | ||
"makeup_elixir": {:hex, :makeup_elixir, "0.15.1", "b5888c880d17d1cc3e598f05cdb5b5a91b7b17ac4eaf5f297cb697663a1094dd", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "db68c173234b07ab2a07f645a5acdc117b9f99d69ebf521821d89690ae6c6ec8"}, | ||
"makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"}, | ||
"nimble_parsec": {:hex, :nimble_parsec, "1.1.0", "3a6fca1550363552e54c216debb6a9e95bd8d32348938e13de5eda962c0d7f89", [:mix], [], "hexpm", "08eb32d66b706e913ff748f11694b17981c0b04a33ef470e33e11b3d3ac8f54b"}, | ||
"rustler": {:hex, :rustler, "0.22.0", "e2930f9d6933e910f87526bb0a7f904e32b62a7e838a3ca4a884ee7fdfb957ed", [:mix], [{:toml, "~> 0.5.2", [hex: :toml, repo: "hexpm", optional: false]}], "hexpm", "01f5989dd511ebec09be481e07d3c59773d5373c5061e09d3ebc3ef61811b49d"}, | ||
"toml": {:hex, :toml, "0.5.2", "e471388a8726d1ce51a6b32f864b8228a1eb8edc907a0edf2bb50eab9321b526", [:mix], [], "hexpm", "f1e3dabef71fb510d015fad18c0e05e7c57281001141504c6b69d94e99750a07"}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,53 @@ | ||
#[macro_use] | ||
extern crate rustler; | ||
// #[macro_use] | ||
extern crate rustler_codegen; | ||
// #[macro_use] | ||
extern crate lazy_static; | ||
extern crate encoding; | ||
extern crate lazy_static; | ||
|
||
|
||
use encoding::{DecoderTrap, EncoderTrap}; | ||
use encoding::label::encoding_from_whatwg_label; | ||
use encoding::{DecoderTrap, EncoderTrap}; | ||
|
||
use rustler::{Env, Term, NifResult, Encoder}; | ||
use rustler::types::binary::{ Binary, OwnedBinary }; | ||
use rustler::{Error}; | ||
use rustler::types::binary::{Binary, OwnedBinary}; | ||
use rustler::Error; | ||
use rustler::{Encoder, Env, NifResult, Term}; | ||
|
||
use std::io::Write; | ||
|
||
|
||
mod atoms { | ||
rustler_atoms! { | ||
atom ok; | ||
atom error; | ||
atom unknown_encoding; | ||
atoms! { | ||
ok, | ||
error, | ||
unknown_encoding, | ||
//atom __true__ = "true"; | ||
//atom __false__ = "false"; | ||
} | ||
} | ||
|
||
rustler_export_nifs! { | ||
"Elixir.Tds.Encoding", | ||
[ | ||
("encode", 2, encode), | ||
("decode", 2, decode) | ||
], | ||
None | ||
} | ||
|
||
fn decode<'a>(env: Env<'a>, args: &[Term<'a>]) -> NifResult<Term<'a>> { | ||
let enc : String = args[1].decode()?; | ||
rustler::init!("Elixir.Tds.Encoding", [encode, decode]); | ||
|
||
#[rustler::nif] | ||
fn decode<'a>(env: Env<'a>, in_binary: Binary, enc: String) -> NifResult<Term<'a>> { | ||
match encoding_from_whatwg_label(&enc) { | ||
Some(encoding) => { | ||
let in_binary : Binary = args[0].decode()?; | ||
let in_str = in_binary.to_owned().unwrap(); | ||
let res = encoding.decode(in_str.as_slice(), DecoderTrap::Replace).unwrap(); | ||
return Ok(res.encode(env)) | ||
}, | ||
None => return Err(Error::BadArg), | ||
let res = encoding | ||
.decode(in_str.as_slice(), DecoderTrap::Replace) | ||
.unwrap(); | ||
Ok(res.encode(env)) | ||
} | ||
None => Err(Error::BadArg) | ||
} | ||
} | ||
|
||
fn encode<'a>(env: Env<'a>, args: &[Term<'a>]) -> NifResult<Term<'a>> { | ||
let enc : String = args[1].decode()?; | ||
|
||
#[rustler::nif] | ||
fn encode<'a>(env: Env<'a>, in_str: &str, enc: String) -> NifResult<Term<'a>> { | ||
match encoding_from_whatwg_label(&enc) { | ||
Some(encoding) => { | ||
let in_str : &str = args[0].decode()?; | ||
let enc_bin = encoding.encode(in_str, EncoderTrap::Replace).unwrap(); | ||
let mut bin = OwnedBinary::new(enc_bin.len()).unwrap(); | ||
bin.as_mut_slice().write(&enc_bin).unwrap(); | ||
return Ok(bin.release(env).encode(env)) | ||
}, | ||
None => return Err(Error::BadArg), | ||
bin.as_mut_slice().write_all(&enc_bin).unwrap(); | ||
Ok(bin.release(env).encode(env)) | ||
} | ||
None => Err(Error::BadArg) | ||
} | ||
} |