fast_osc 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c9a41c6181bc5aacee5d21c72ed458afa8e8ab83
4
- data.tar.gz: 4826ac56d60fb8361a2b993b770353bd8cea2263
3
+ metadata.gz: b61fec8aa9b7da4919beb24194add024e7fc96ed
4
+ data.tar.gz: f3b8f4387da0d02161f4d173b60de999c9851948
5
5
  SHA512:
6
- metadata.gz: 89e221df978a9ddd6e4652e47e54223cf3080ee398f55768a0d3bf91ef98fb62b4807788e720c2df37d80e872a366a0b5dfe18c2c999a2f8107757d128366add
7
- data.tar.gz: f1cbc5bd780f52a26d3c78648ccdf7fe7c4dc8c6c053f9703ec62c6ab6dfa73cbc81f51f5e8df27e2e80dc46a283830fd82eab3dc81ab81b6692b5ccfccac1b6
6
+ metadata.gz: d6f8997f138ca1d6a78c3d686cbd24fcd9b29638dae90d817becd9f2a97ced738eb2f33025c5f6a86a0ece2abad5794ffa640bb690a8d92a0850108f8c1fb7cf
7
+ data.tar.gz: 58723176381c238b7591c82e1ff43f24ae4cb829311b862f03639236d16e47c65bbf914b26e1986ef494d45b799e88f688d680385dd761fb049ecf321ab61094
data/README.md CHANGED
@@ -65,19 +65,19 @@ I'll include a better test in the repo in time.
65
65
  ## Usage
66
66
 
67
67
  ```
68
- >> FastOsc.serialize("/foo", ["baz", 1, 2.0])
68
+ >> FastOsc.encode_single_message("/foo", ["baz", 1, 2.0])
69
69
  => "/foo\x00\x00\x00\x00,sif\x00\x00\x00\x00baz\x00\x00\x00\x00\x01@\x00\x00\x00"
70
70
  >> res = _
71
- >> FastOsc.deserialize(res)
72
- => ["baz", 1, 2.0]
71
+ >> FastOsc.decode_single_message(res)
72
+ => ["/foo", ["baz", 1, 2.0]]
73
+ >> FastOsc.encode_single_bundle(Time.now.to_i, "/foo", ["baz", 1, 2.0])
74
+ => "#bundle\x00\x00\x00\x00\x00W*1\x7F\x00\x00\x00\x1C/foo\x00\x00\x00\x00,sif\x00\x00\x00\x00baz\x00\x00\x00\x00\x01@\x00\x00\x00"
73
75
  ```
74
76
 
75
77
  ## Still todo
76
78
 
77
79
  * Implement more types
78
- * return address with `deserialize` (doh!)
79
80
  * add tests at the Ruby level (rtosc C code is already tested)
80
- * figure out build process
81
81
 
82
82
  ## Development notes
83
83
 
@@ -10,8 +10,9 @@ VALUE FastOsc = Qnil;
10
10
  // when this file is loaded, and the second is the actual business logic we're
11
11
  // implementing.
12
12
  void Init_fast_osc();
13
- VALUE method_fast_osc_deserialize(VALUE self, VALUE msg);
14
- VALUE method_fast_osc_serialize(VALUE self, VALUE address, VALUE args);
13
+ VALUE method_fast_osc_decode_single_message(VALUE self, VALUE msg);
14
+ VALUE method_fast_osc_encode_single_message(VALUE self, VALUE address, VALUE args);
15
+ VALUE method_fast_osc_encode_single_bundle(VALUE self, VALUE timestamp, VALUE address, VALUE args);
15
16
 
16
17
  // Initial setup function, takes no arguments and returns nothing. Some API
17
18
  // notes:
@@ -27,15 +28,24 @@ VALUE method_fast_osc_serialize(VALUE self, VALUE address, VALUE args);
27
28
  //
28
29
  void Init_fast_osc() {
29
30
  FastOsc = rb_define_module("FastOsc");
30
- rb_define_singleton_method(FastOsc, "deserialize", method_fast_osc_deserialize, 1);
31
- rb_define_singleton_method(FastOsc, "serialize", method_fast_osc_serialize, 2);
31
+ rb_define_singleton_method(FastOsc, "decode_single_message", method_fast_osc_decode_single_message, 1);
32
+ rb_define_singleton_method(FastOsc, "encode_single_message", method_fast_osc_encode_single_message, 2);
33
+ rb_define_singleton_method(FastOsc, "encode_single_bundle", method_fast_osc_encode_single_bundle, 3);
32
34
  }
33
35
 
34
- VALUE method_fast_osc_deserialize(VALUE self, VALUE msg) {
36
+ const char *rtosc_path(const char *msg)
37
+ {
38
+ return msg;
39
+ }
40
+
41
+ VALUE method_fast_osc_decode_single_message(VALUE self, VALUE msg) {
35
42
  rtosc_arg_itr_t itr;
36
43
  char* data = StringValuePtr(msg);
37
44
  itr = rtosc_itr_begin(data);
38
45
  VALUE output = rb_ary_new();
46
+ VALUE args_output = rb_ary_new();
47
+
48
+ VALUE path = rb_str_new2(rtosc_path(data));
39
49
 
40
50
  rtosc_arg_val_t next_val;
41
51
 
@@ -46,38 +56,40 @@ VALUE method_fast_osc_deserialize(VALUE self, VALUE msg) {
46
56
  switch(next_val.type) {
47
57
  case 'i' :
48
58
  // INT2FIX() for integers within 31bits.
49
- rb_ary_push(output, INT2FIX(next_val.val.i));
59
+ rb_ary_push(args_output, INT2FIX(next_val.val.i));
50
60
  break;
51
61
  case 'f' :
52
- rb_ary_push(output, rb_float_new(next_val.val.f));
62
+ rb_ary_push(args_output, rb_float_new(next_val.val.f));
53
63
  break;
54
64
  case 's' :
55
- rb_ary_push(output, rb_str_new2(next_val.val.s));
65
+ rb_ary_push(args_output, rb_str_new2(next_val.val.s));
56
66
  break;
57
67
  case 'b' :
58
- rb_ary_push(output, rb_str_new((const char*)next_val.val.b.data, next_val.val.b.len));
68
+ rb_ary_push(args_output, rb_str_new((const char*)next_val.val.b.data, next_val.val.b.len));
59
69
  break;
60
70
  case 'h' :
61
71
  // INT2NUM() for arbitrary sized integers
62
- rb_ary_push(output, INT2NUM(next_val.val.h));
72
+ rb_ary_push(args_output, INT2NUM(next_val.val.h));
63
73
  break;
64
74
  case 't' :
65
75
  // OSC time tag
66
76
  // not implemented
67
77
  break;
68
78
  case 'd' :
69
- rb_ary_push(output, rb_float_new(next_val.val.d));
79
+ rb_ary_push(args_output, rb_float_new(next_val.val.d));
70
80
  break;
71
81
  case 'S' :
72
- rb_ary_push(output, ID2SYM(rb_intern(next_val.val.s)));
82
+ rb_ary_push(args_output, ID2SYM(rb_intern(next_val.val.s)));
73
83
  break;
74
84
  case 'c' :
75
- rb_ary_push(output, rb_str_concat(rb_str_new2(""), INT2FIX(next_val.val.i)));
85
+ rb_ary_push(args_output, rb_str_concat(rb_str_new2(""), INT2FIX(next_val.val.i)));
76
86
  break;
77
87
  }
78
88
 
79
89
  }
80
90
 
91
+ rb_ary_push(output, path);
92
+ rb_ary_push(output, args_output);
81
93
  return output;
82
94
  }
83
95
 
@@ -86,7 +98,7 @@ int buffer_size_for_ruby_string(VALUE rstring) {
86
98
  return (int)((str_bytesize + sizeof(int) - 1) & ~(sizeof(int) - 1));
87
99
  }
88
100
 
89
- VALUE method_fast_osc_serialize(VALUE self, VALUE address, VALUE args) {
101
+ VALUE method_fast_osc_encode_single_message(VALUE self, VALUE address, VALUE args) {
90
102
  char* c_address = StringValueCStr(address);
91
103
 
92
104
  int no_of_args = NUM2INT(LONG2NUM(RARRAY_LEN(args)));
@@ -153,3 +165,17 @@ VALUE method_fast_osc_serialize(VALUE self, VALUE address, VALUE args) {
153
165
 
154
166
  return output;
155
167
  }
168
+
169
+ VALUE method_fast_osc_encode_single_bundle(VALUE self, VALUE timestamp, VALUE address, VALUE args) {
170
+ VALUE message = method_fast_osc_encode_single_message(self, address, args);
171
+ int bufsize = buffer_size_for_ruby_string(message) + 16;
172
+ int no_of_elems = 1;
173
+ uint64_t tt = FIX2LONG(timestamp);
174
+ char output_buffer[bufsize];
175
+
176
+ int len = rtosc_bundle(output_buffer, bufsize, tt, no_of_elems, StringValuePtr(message));
177
+
178
+ VALUE output = rb_str_new(output_buffer, len);
179
+
180
+ return output;
181
+ }
@@ -1,5 +1,3 @@
1
1
  module FastOsc
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
4
-
5
- require "fast_osc/fast_osc"
data/lib/fast_osc.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "fast_osc/version"
2
+ require "fast_osc/fast_osc"
2
3
 
3
4
  module FastOsc
4
5
  # Your code goes here...
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_osc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xavier Riley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-03 00:00:00.000000000 Z
11
+ date: 2016-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler