tracklib 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cb89ce2fe3d5e3c37c9046a0b62fdfd1b36033afbf7b35e2eb5a4d509b9459cb
4
+ data.tar.gz: b33d3b2927225b97db87e7837c9c5a8a9362f2ef56dab71d16301878e8d38628
5
+ SHA512:
6
+ metadata.gz: 86d7a09fe589c38eb80f277a22ba7ce1c6ae2a746e5d3fa77d8f6d8114ed9f68ec410243366d12b5acc0c07138dccba7d0783b706adf8a5b32791f6c3c0f2c8f
7
+ data.tar.gz: 59a8ab8bcf9be2a6dd440bcca65aee92092d58dd0413daebdb348ad2a02adfc71533cd346118815f6b65f1ab7435fb77dacbd2dc9d2f92e7111063a56a327361
data/Cargo.lock ADDED
@@ -0,0 +1,254 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ [[package]]
4
+ name = "backtrace"
5
+ version = "0.3.33"
6
+ source = "registry+https://github.com/rust-lang/crates.io-index"
7
+ dependencies = [
8
+ "backtrace-sys 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)",
9
+ "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
10
+ "libc 0.2.60 (registry+https://github.com/rust-lang/crates.io-index)",
11
+ "rustc-demangle 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)",
12
+ ]
13
+
14
+ [[package]]
15
+ name = "backtrace-sys"
16
+ version = "0.1.31"
17
+ source = "registry+https://github.com/rust-lang/crates.io-index"
18
+ dependencies = [
19
+ "cc 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)",
20
+ "libc 0.2.60 (registry+https://github.com/rust-lang/crates.io-index)",
21
+ ]
22
+
23
+ [[package]]
24
+ name = "base64"
25
+ version = "0.10.1"
26
+ source = "registry+https://github.com/rust-lang/crates.io-index"
27
+ dependencies = [
28
+ "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
29
+ ]
30
+
31
+ [[package]]
32
+ name = "build_const"
33
+ version = "0.2.1"
34
+ source = "registry+https://github.com/rust-lang/crates.io-index"
35
+
36
+ [[package]]
37
+ name = "byteorder"
38
+ version = "1.3.2"
39
+ source = "registry+https://github.com/rust-lang/crates.io-index"
40
+
41
+ [[package]]
42
+ name = "cc"
43
+ version = "1.0.38"
44
+ source = "registry+https://github.com/rust-lang/crates.io-index"
45
+
46
+ [[package]]
47
+ name = "cfg-if"
48
+ version = "0.1.9"
49
+ source = "registry+https://github.com/rust-lang/crates.io-index"
50
+
51
+ [[package]]
52
+ name = "crc"
53
+ version = "1.8.1"
54
+ source = "registry+https://github.com/rust-lang/crates.io-index"
55
+ dependencies = [
56
+ "build_const 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
57
+ ]
58
+
59
+ [[package]]
60
+ name = "itoa"
61
+ version = "0.4.4"
62
+ source = "registry+https://github.com/rust-lang/crates.io-index"
63
+
64
+ [[package]]
65
+ name = "lazy_static"
66
+ version = "1.3.0"
67
+ source = "registry+https://github.com/rust-lang/crates.io-index"
68
+
69
+ [[package]]
70
+ name = "leb128"
71
+ version = "0.2.4"
72
+ source = "registry+https://github.com/rust-lang/crates.io-index"
73
+
74
+ [[package]]
75
+ name = "libc"
76
+ version = "0.2.60"
77
+ source = "registry+https://github.com/rust-lang/crates.io-index"
78
+
79
+ [[package]]
80
+ name = "log"
81
+ version = "0.4.8"
82
+ source = "registry+https://github.com/rust-lang/crates.io-index"
83
+ dependencies = [
84
+ "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
85
+ ]
86
+
87
+ [[package]]
88
+ name = "memchr"
89
+ version = "2.2.1"
90
+ source = "registry+https://github.com/rust-lang/crates.io-index"
91
+
92
+ [[package]]
93
+ name = "nom"
94
+ version = "4.2.3"
95
+ source = "registry+https://github.com/rust-lang/crates.io-index"
96
+ dependencies = [
97
+ "memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
98
+ "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
99
+ ]
100
+
101
+ [[package]]
102
+ name = "proc-macro2"
103
+ version = "0.4.30"
104
+ source = "registry+https://github.com/rust-lang/crates.io-index"
105
+ dependencies = [
106
+ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
107
+ ]
108
+
109
+ [[package]]
110
+ name = "quote"
111
+ version = "0.6.13"
112
+ source = "registry+https://github.com/rust-lang/crates.io-index"
113
+ dependencies = [
114
+ "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
115
+ ]
116
+
117
+ [[package]]
118
+ name = "ruby_tracklib"
119
+ version = "0.1.0"
120
+ dependencies = [
121
+ "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
122
+ "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
123
+ "rutie 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
124
+ "rutie-serde 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
125
+ "tracklib 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
126
+ ]
127
+
128
+ [[package]]
129
+ name = "rustc-demangle"
130
+ version = "0.1.15"
131
+ source = "registry+https://github.com/rust-lang/crates.io-index"
132
+
133
+ [[package]]
134
+ name = "rutie"
135
+ version = "0.5.6"
136
+ source = "registry+https://github.com/rust-lang/crates.io-index"
137
+ dependencies = [
138
+ "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
139
+ "libc 0.2.60 (registry+https://github.com/rust-lang/crates.io-index)",
140
+ ]
141
+
142
+ [[package]]
143
+ name = "rutie-serde"
144
+ version = "0.1.1"
145
+ source = "registry+https://github.com/rust-lang/crates.io-index"
146
+ dependencies = [
147
+ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
148
+ "rutie 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
149
+ "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)",
150
+ "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)",
151
+ ]
152
+
153
+ [[package]]
154
+ name = "ryu"
155
+ version = "1.0.0"
156
+ source = "registry+https://github.com/rust-lang/crates.io-index"
157
+
158
+ [[package]]
159
+ name = "serde"
160
+ version = "1.0.98"
161
+ source = "registry+https://github.com/rust-lang/crates.io-index"
162
+
163
+ [[package]]
164
+ name = "serde_json"
165
+ version = "1.0.40"
166
+ source = "registry+https://github.com/rust-lang/crates.io-index"
167
+ dependencies = [
168
+ "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
169
+ "ryu 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
170
+ "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)",
171
+ ]
172
+
173
+ [[package]]
174
+ name = "snafu"
175
+ version = "0.2.3"
176
+ source = "registry+https://github.com/rust-lang/crates.io-index"
177
+ dependencies = [
178
+ "backtrace 0.3.33 (registry+https://github.com/rust-lang/crates.io-index)",
179
+ "snafu-derive 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
180
+ ]
181
+
182
+ [[package]]
183
+ name = "snafu-derive"
184
+ version = "0.2.3"
185
+ source = "registry+https://github.com/rust-lang/crates.io-index"
186
+ dependencies = [
187
+ "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
188
+ "quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)",
189
+ "syn 0.15.42 (registry+https://github.com/rust-lang/crates.io-index)",
190
+ ]
191
+
192
+ [[package]]
193
+ name = "syn"
194
+ version = "0.15.42"
195
+ source = "registry+https://github.com/rust-lang/crates.io-index"
196
+ dependencies = [
197
+ "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
198
+ "quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)",
199
+ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
200
+ ]
201
+
202
+ [[package]]
203
+ name = "tracklib"
204
+ version = "0.1.0"
205
+ source = "registry+https://github.com/rust-lang/crates.io-index"
206
+ dependencies = [
207
+ "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
208
+ "crc 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
209
+ "leb128 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
210
+ "nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
211
+ "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)",
212
+ "snafu 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
213
+ ]
214
+
215
+ [[package]]
216
+ name = "unicode-xid"
217
+ version = "0.1.0"
218
+ source = "registry+https://github.com/rust-lang/crates.io-index"
219
+
220
+ [[package]]
221
+ name = "version_check"
222
+ version = "0.1.5"
223
+ source = "registry+https://github.com/rust-lang/crates.io-index"
224
+
225
+ [metadata]
226
+ "checksum backtrace 0.3.33 (registry+https://github.com/rust-lang/crates.io-index)" = "88fb679bc9af8fa639198790a77f52d345fe13656c08b43afa9424c206b731c6"
227
+ "checksum backtrace-sys 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)" = "82a830b4ef2d1124a711c71d263c5abdc710ef8e907bd508c88be475cebc422b"
228
+ "checksum base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e"
229
+ "checksum build_const 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "39092a32794787acd8525ee150305ff051b0aa6cc2abaf193924f5ab05425f39"
230
+ "checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5"
231
+ "checksum cc 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)" = "ce400c638d48ee0e9ab75aef7997609ec57367ccfe1463f21bf53c3eca67bf46"
232
+ "checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33"
233
+ "checksum crc 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d663548de7f5cca343f1e0a48d14dcfb0e9eb4e079ec58883b7251539fa10aeb"
234
+ "checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f"
235
+ "checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14"
236
+ "checksum leb128 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3576a87f2ba00f6f106fdfcd16db1d698d648a26ad8e0573cad8537c3c362d2a"
237
+ "checksum libc 0.2.60 (registry+https://github.com/rust-lang/crates.io-index)" = "d44e80633f007889c7eff624b709ab43c92d708caad982295768a7b13ca3b5eb"
238
+ "checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7"
239
+ "checksum memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e"
240
+ "checksum nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2ad2a91a8e869eeb30b9cb3119ae87773a8f4ae617f41b1eb9c154b2905f7bd6"
241
+ "checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759"
242
+ "checksum quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1"
243
+ "checksum rustc-demangle 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "a7f4dccf6f4891ebcc0c39f9b6eb1a83b9bf5d747cb439ec6fba4f3b977038af"
244
+ "checksum rutie 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "5386200cd74705d2f0f6f5076d833ed26070240dea32b778807af38159900284"
245
+ "checksum rutie-serde 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d43d8aea0107683e12860daed2e0fa7c36702927c181ecd270552c39dcc94b27"
246
+ "checksum ryu 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c92464b447c0ee8c4fb3824ecc8383b81717b9f1e74ba2e72540aef7b9f82997"
247
+ "checksum serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)" = "7fe5626ac617da2f2d9c48af5515a21d5a480dbd151e01bb1c355e26a3e68113"
248
+ "checksum serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)" = "051c49229f282f7c6f3813f8286cc1e3323e8051823fce42c7ea80fe13521704"
249
+ "checksum snafu 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "67a2e16c9b74a09d4bc84ea6e5eb68fef70b4cb14e8ccd26f2de76af2e9c2e8a"
250
+ "checksum snafu-derive 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bf96650c2b31fa949780f792025f4ca79fbe87bd723a8b3573dce37be7193b08"
251
+ "checksum syn 0.15.42 (registry+https://github.com/rust-lang/crates.io-index)" = "eadc09306ca51a40555dd6fc2b415538e9e18bc9f870e47b1a524a79fe2dcf5e"
252
+ "checksum tracklib 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "97f6f1e9e410c9b8d6b96f1eab38296f3c6aa8cd67d71a5163db6ba2bef9b6e5"
253
+ "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
254
+ "checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd"
data/Cargo.toml ADDED
@@ -0,0 +1,20 @@
1
+ [package]
2
+ name = "ruby_tracklib"
3
+ version = "0.1.0"
4
+ authors = ["Dan Larkin <dan@danlarkin.org>"]
5
+ license = "Apache-2.0 OR MIT"
6
+ edition = "2018"
7
+
8
+ [profile.release]
9
+ lto = false # LTO broke the ruby module in my testing
10
+
11
+ [lib]
12
+ name = "ruby_tracklib"
13
+ crate-type = ["cdylib"]
14
+
15
+ [dependencies]
16
+ tracklib = "*"
17
+ rutie = "0.5"
18
+ rutie-serde = "0.1"
19
+ lazy_static = "1.3"
20
+ base64 = "0.10"
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in ruby_tracklib.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ require "rbconfig"
2
+ require "bundler/gem_tasks"
3
+ require "rake/testtask"
4
+
5
+ desc 'Build Rust extension'
6
+ task :build_lib do
7
+ case RbConfig::CONFIG['host_os']
8
+ when /darwin|mac os/
9
+ sh 'NO_LINK_RUTIE=y cargo rustc --release -- -C link-args=-Wl,-undefined,dynamic_lookup'
10
+ else
11
+ sh 'NO_LINK_RUTIE=y cargo build --release'
12
+ end
13
+ end
14
+
15
+ desc 'bundle install'
16
+ task :bundle_install do
17
+ sh 'bundle install'
18
+ end
19
+
20
+ Rake::TestTask.new(test: [:bundle_install, :build_lib]) do |t|
21
+ t.libs << "test"
22
+ t.libs << "lib"
23
+ t.test_files = FileList["test/**/*_test.rb"]
24
+ end
25
+
26
+ task :default => :test
@@ -0,0 +1,3 @@
1
+ module Tracklib
2
+ VERSION = "0.1.1"
3
+ end
data/lib/tracklib.rb ADDED
@@ -0,0 +1,14 @@
1
+ require "tracklib/version"
2
+ require "rutie"
3
+
4
+ module Tracklib
5
+ class Error < StandardError; end
6
+ Rutie.new(:tracklib, {lib_path: "../../target/release"}).init 'Init_Tracklib', __dir__
7
+ end
8
+
9
+ class RWTFile
10
+ def hello_from_ruby()
11
+ puts "I am a ruby method"
12
+ return 5
13
+ end
14
+ end
data/src/lib.rs ADDED
@@ -0,0 +1,348 @@
1
+ use std::collections::{HashMap};
2
+ use std::convert::{TryFrom};
3
+ use std::io::{BufWriter};
4
+ use lazy_static::lazy_static;
5
+ use rutie::{
6
+ class, methods, wrappable_struct, AnyObject, Array, Boolean, Class, Encoding, Float, Hash, Integer,
7
+ Object, RString, VM,
8
+ };
9
+ use rutie_serde::{ruby_class, rutie_serde_methods};
10
+ use tracklib::{parse_rwtf, DataField, RWTFile, RWTFMetadata, TrackType};
11
+
12
+ fn any_to_float(o: AnyObject) -> f64 {
13
+ match o.try_convert_to::<Float>() {
14
+ Ok(f) => f.to_f64(),
15
+ Err(float_e) => o
16
+ .try_convert_to::<Integer>()
17
+ .map_err(|_| VM::raise_ex(float_e))
18
+ .unwrap()
19
+ .to_i64() as f64,
20
+ }
21
+ }
22
+
23
+ fn any_to_int(o: AnyObject) -> i64 {
24
+ match o.try_convert_to::<Integer>() {
25
+ Ok(f) => f.to_i64(),
26
+ Err(float_e) => o
27
+ .try_convert_to::<Float>()
28
+ .map_err(|_| VM::raise_ex(float_e))
29
+ .unwrap()
30
+ .to_f64() as i64,
31
+ }
32
+ }
33
+
34
+ fn any_to_str(o: AnyObject) -> String {
35
+ o.try_convert_to::<RString>()
36
+ .map_err(|e| VM::raise_ex(e))
37
+ .unwrap()
38
+ .to_string()
39
+ }
40
+
41
+ fn any_to_bool(o: AnyObject) -> bool {
42
+ o.try_convert_to::<Boolean>()
43
+ .map_err(|e| VM::raise_ex(e))
44
+ .unwrap()
45
+ .to_bool()
46
+ }
47
+
48
+ fn any_to_ids(o: AnyObject) -> Vec<u64> {
49
+ o.try_convert_to::<Array>()
50
+ .map_err(|e| VM::raise_ex(e))
51
+ .unwrap()
52
+ .into_iter()
53
+ .map(|ele| {
54
+ ele.try_convert_to::<Integer>()
55
+ .map_err(|e| VM::raise_ex(e))
56
+ .unwrap()
57
+ .to_u64()
58
+ })
59
+ .collect()
60
+ }
61
+
62
+ fn convert_config(config: Hash) -> HashMap<String, String> {
63
+ let mut hm = HashMap::new();
64
+
65
+ config.each(|rwtf_type_name, array_of_field_names| {
66
+ let type_name_obj = rwtf_type_name
67
+ .try_convert_to::<RString>()
68
+ .map_err(|e| VM::raise_ex(e))
69
+ .unwrap();
70
+ let array_obj = array_of_field_names
71
+ .try_convert_to::<Array>()
72
+ .map_err(|e| VM::raise_ex(e))
73
+ .unwrap();
74
+
75
+ for field_name in array_obj.into_iter() {
76
+ let field_name_obj = field_name
77
+ .try_convert_to::<RString>()
78
+ .map_err(|e| VM::raise_ex(e))
79
+ .unwrap();
80
+
81
+ hm.insert(field_name_obj.to_string(), type_name_obj.to_string());
82
+ }
83
+ });
84
+
85
+ hm
86
+ }
87
+
88
+ fn add_points(points: Array, mut callback: impl FnMut(usize, &str, AnyObject)) {
89
+ for (i, maybe_point) in points.into_iter().enumerate() {
90
+ let point = maybe_point
91
+ .try_convert_to::<Hash>()
92
+ .map_err(|e| VM::raise_ex(e))
93
+ .unwrap();
94
+
95
+ point.each(|k, v| {
96
+ let field_name_obj = k
97
+ .try_convert_to::<RString>()
98
+ .map_err(|e| VM::raise_ex(e))
99
+ .unwrap();
100
+ let name = field_name_obj.to_str();
101
+ let mut store_field = true;
102
+
103
+ if v.is_nil() {
104
+ store_field = false;
105
+ }
106
+
107
+ if name.is_empty() {
108
+ store_field = false;
109
+ }
110
+
111
+ match v.try_convert_to::<RString>() {
112
+ Ok(s) => if s.to_str().is_empty() {
113
+ store_field = false;
114
+ }
115
+ Err(_) => {}
116
+ }
117
+
118
+ match v.try_convert_to::<Array>() {
119
+ Ok(a) => if a.length() == 0 {
120
+ store_field = false;
121
+ }
122
+ Err(_) => {}
123
+ }
124
+
125
+ match v.try_convert_to::<Integer>() {
126
+ Ok(i) => if i.to_i64().abs() > 2i64.pow(48) {
127
+ store_field = false;
128
+ }
129
+ Err(_) => match v.try_convert_to::<Float>() {
130
+ Ok(f) => if f.to_f64().abs() > 2f64.powi(48) {
131
+ store_field = false;
132
+ }
133
+ Err(_) => {}
134
+ }
135
+ }
136
+
137
+ if store_field {
138
+ callback(i, name, v);
139
+ }
140
+ });
141
+ }
142
+ }
143
+
144
+ pub struct Inner {
145
+ inner: RWTFile,
146
+ }
147
+
148
+ wrappable_struct!(Inner, InnerWrapper, INNER_WRAPPER);
149
+
150
+ class!(RubyRWTFile);
151
+
152
+ methods!(
153
+ RubyRWTFile,
154
+ itself,
155
+
156
+ fn rwtf_from_bytes(bytes: RString) -> AnyObject {
157
+ let source = bytes.map_err(|e| VM::raise_ex(e)).unwrap();
158
+ let (_, rwtf) = parse_rwtf(source.to_bytes_unchecked())
159
+ .map_err(|e| VM::raise(Class::from_existing("Exception"), &format!("{}", e)))
160
+ .unwrap();
161
+ let inner = Inner { inner: rwtf };
162
+
163
+ Class::from_existing("RWTFile").wrap_data(inner, &*INNER_WRAPPER)
164
+ }
165
+
166
+ fn rwtf_to_bytes() -> RString {
167
+ let mut writer = BufWriter::new(Vec::new());
168
+ itself.get_data(&*INNER_WRAPPER).inner.write(&mut writer)
169
+ .map_err(|e| VM::raise(Class::from_existing("Exception"), &format!("{}", e)))
170
+ .unwrap();
171
+
172
+ let encoding = Encoding::find("ASCII-8BIT")
173
+ .map_err(|e| VM::raise_ex(e))
174
+ .unwrap();
175
+
176
+ let buf = writer.into_inner()
177
+ .map_err(|e| VM::raise(Class::from_existing("Exception"), &format!("{}", e)))
178
+ .unwrap();
179
+
180
+ RString::from_bytes(&buf, &encoding)
181
+ }
182
+
183
+ fn rwtf_from_hash(input: Hash, config_input: Hash, metadata: Hash) -> AnyObject {
184
+ let source = input.map_err(|e| VM::raise_ex(e)).unwrap();
185
+ let config = config_input.map_err(|e| VM::raise_ex(e)).unwrap();
186
+ let track_points_config = convert_config(config.at(&RString::new_utf8("track_points"))
187
+ .try_convert_to::<Hash>()
188
+ .map_err(|e| VM::raise_ex(e))
189
+ .unwrap());
190
+ let course_points_config = convert_config(config.at(&RString::new_utf8("course_points"))
191
+ .try_convert_to::<Hash>()
192
+ .map_err(|e| VM::raise_ex(e))
193
+ .unwrap());
194
+
195
+ let mut rwtf = if let Some(md) = metadata.ok() {
196
+ let tt_metadata = md.at(&RString::new_utf8("track_type"))
197
+ .try_convert_to::<Hash>()
198
+ .map_err(|e| VM::raise_ex(e))
199
+ .unwrap();
200
+
201
+ let track_type = tt_metadata.at(&RString::new_utf8("type"))
202
+ .try_convert_to::<RString>()
203
+ .map_err(|e| VM::raise_ex(e))
204
+ .unwrap();
205
+
206
+ let id = u32::try_from(tt_metadata.at(&RString::new_utf8("id"))
207
+ .try_convert_to::<Integer>()
208
+ .map_err(|e| VM::raise_ex(e))
209
+ .unwrap()
210
+ .to_u64())
211
+ .map_err(|e| VM::raise(Class::from_existing("Exception"), &format!("{}", e)))
212
+ .unwrap();
213
+
214
+ let tt = match track_type.to_str() {
215
+ "trip" => TrackType::Trip(id),
216
+ "route" => TrackType::Route(id),
217
+ "segment" => TrackType::Segment(id),
218
+ _ => {
219
+ VM::raise(
220
+ Class::from_existing("Exception"),
221
+ &format!("unknown track_type metadata: {}", track_type.to_str()),
222
+ );
223
+ unreachable!();
224
+ }
225
+ };
226
+
227
+ RWTFile::with_track_type(tt)
228
+ } else {
229
+ RWTFile::new()
230
+ };
231
+
232
+ let maybe_track_points = source
233
+ .at(&RString::new_utf8("track_points"))
234
+ .try_convert_to::<Array>();
235
+
236
+ if let Ok(track_points) = maybe_track_points {
237
+ add_points(track_points, |i, k, v| {
238
+ let data = if let Some(field_type) = track_points_config.get(k) {
239
+ match field_type.as_str() {
240
+ "LongFloat" => DataField::LongFloat(any_to_float(v)),
241
+ "ShortFloat" => DataField::ShortFloat(any_to_float(v)),
242
+ "Number" => DataField::Number(any_to_int(v)),
243
+ "Base64" => DataField::Base64(any_to_str(v).replace("\n", "")),
244
+ "String" => DataField::String(any_to_str(v)),
245
+ "Bool" => DataField::Bool(any_to_bool(v)),
246
+ "IDs" => DataField::IDs(any_to_ids(v)),
247
+ _ => {
248
+ VM::raise(
249
+ Class::from_existing("Exception"),
250
+ &format!("unknown track_points type: {}", field_type),
251
+ );
252
+ unreachable!();
253
+ }
254
+ }
255
+ } else {
256
+ VM::raise(
257
+ Class::from_existing("Exception"),
258
+ &format!("unknown track_points field: {}", k),
259
+ );
260
+ unreachable!();
261
+ };
262
+
263
+ rwtf.add_track_point(i, k, data)
264
+ .map_err(|e| {
265
+ VM::raise(Class::from_existing("Exception"), &format!("{}", e))
266
+ })
267
+ .unwrap();
268
+ });
269
+ }
270
+
271
+ let maybe_course_points = source
272
+ .at(&RString::new_utf8("course_points"))
273
+ .try_convert_to::<Array>();
274
+
275
+ if let Ok(course_points) = maybe_course_points {
276
+ add_points(course_points, |i, k, v| {
277
+ let data = if let Some(field_type) = course_points_config.get(k) {
278
+ match field_type.as_str() {
279
+ "LongFloat" => DataField::LongFloat(any_to_float(v)),
280
+ "ShortFloat" => DataField::ShortFloat(any_to_float(v)),
281
+ "Number" => DataField::Number(any_to_int(v)),
282
+ "Base64" => DataField::Base64(any_to_str(v).replace("\n", "")),
283
+ "String" => DataField::String(any_to_str(v)),
284
+ "Bool" => DataField::Bool(any_to_bool(v)),
285
+ "IDs" => DataField::IDs(any_to_ids(v)),
286
+ _ => {
287
+ VM::raise(
288
+ Class::from_existing("Exception"),
289
+ &format!("unknown course_points type: {}", field_type),
290
+ );
291
+ unreachable!();
292
+ }
293
+ }
294
+ } else {
295
+ VM::raise(
296
+ Class::from_existing("Exception"),
297
+ &format!("unknown course_points field: {}", k),
298
+ );
299
+ unreachable!();
300
+ };
301
+
302
+ rwtf.add_course_point(i, k, data)
303
+ .map_err(|e| {
304
+ VM::raise(Class::from_existing("Exception"), &format!("{}", e))
305
+ })
306
+ .unwrap();
307
+ });
308
+ }
309
+
310
+ let inner = Inner { inner: rwtf };
311
+ Class::from_existing("RWTFile").wrap_data(inner, &*INNER_WRAPPER)
312
+ }
313
+
314
+ fn rwtf_inspect() -> RString {
315
+ let rwtf = &itself.get_data(&*INNER_WRAPPER).inner;
316
+
317
+ RString::new_utf8(&format!("RWTFile<track_points: {}, course_points: {}>",
318
+ rwtf.track_points.len(),
319
+ rwtf.course_points.len()))
320
+ }
321
+ );
322
+
323
+ rutie_serde_methods!(
324
+ RubyRWTFile,
325
+ itself,
326
+ ruby_class!(Exception),
327
+
328
+ fn rwtf_to_hash() -> &RWTFile {
329
+ &itself.get_data(&*INNER_WRAPPER).inner
330
+ }
331
+
332
+ fn rwtf_metadata() -> &RWTFMetadata {
333
+ &itself.get_data(&*INNER_WRAPPER).inner.metadata()
334
+ }
335
+ );
336
+
337
+ #[allow(non_snake_case)]
338
+ #[no_mangle]
339
+ pub extern "C" fn Init_Tracklib() {
340
+ Class::new("RWTFile", Some(&Class::from_existing("Object"))).define(|itself| {
341
+ itself.def_self("from_bytes", rwtf_from_bytes);
342
+ itself.def_self("from_h", rwtf_from_hash);
343
+ itself.def("to_bytes", rwtf_to_bytes);
344
+ itself.def("to_h", rwtf_to_hash);
345
+ itself.def("metadata", rwtf_metadata);
346
+ itself.def("inspect", rwtf_inspect);
347
+ });
348
+ }
data/tracklib.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "tracklib/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "tracklib"
7
+ spec.version = Tracklib::VERSION
8
+ spec.authors = ["Dan Larkin"]
9
+ spec.email = ["dan@danlarkin.org"]
10
+
11
+ spec.summary = "tracklib"
12
+ spec.description = "RWGPS tracklib ruby gem"
13
+ spec.homepage = "https://ridewithgps.com"
14
+ spec.licenses = ["Apache-2.0", "MIT"]
15
+
16
+ spec.files = ["tracklib.gemspec",
17
+ "Rakefile",
18
+ "Gemfile",
19
+ "lib/tracklib.rb",
20
+ "lib/tracklib/version.rb",
21
+
22
+ "Cargo.toml",
23
+ "Cargo.lock",
24
+ "src/lib.rs"]
25
+
26
+ spec.require_paths = ["lib"]
27
+ spec.extensions = "Rakefile"
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.17"
30
+ spec.add_development_dependency "rake", "~> 12.3"
31
+
32
+ spec.add_development_dependency "minitest", "~> 5.11"
33
+ spec.add_dependency "rutie", "~> 0.0.4"
34
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tracklib
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Dan Larkin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-07-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '12.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '12.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rutie
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.0.4
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.0.4
69
+ description: RWGPS tracklib ruby gem
70
+ email:
71
+ - dan@danlarkin.org
72
+ executables: []
73
+ extensions:
74
+ - Rakefile
75
+ extra_rdoc_files: []
76
+ files:
77
+ - Cargo.lock
78
+ - Cargo.toml
79
+ - Gemfile
80
+ - Rakefile
81
+ - lib/tracklib.rb
82
+ - lib/tracklib/version.rb
83
+ - src/lib.rs
84
+ - tracklib.gemspec
85
+ homepage: https://ridewithgps.com
86
+ licenses:
87
+ - Apache-2.0
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubygems_version: 3.0.3
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: tracklib
109
+ test_files: []