Skip to content

Commit 9a18d64

Browse files
committed
Parsing string arguments
1 parent c3c4679 commit 9a18d64

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lib/osc/message.ex

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ defmodule OSC.Message do
3939
|> :binary.bin_to_list
4040
end
4141

42-
defp remove_extra_nulls(type_tag, arguments) do
43-
extra_null_count = extra_nulls type_tag
42+
defp remove_extra_nulls(string, arguments) do
43+
extra_null_count = extra_nulls string
4444
len = size(arguments) - extra_null_count
4545
:binary.part arguments, extra_null_count, len
4646
end
@@ -75,5 +75,11 @@ defmodule OSC.Message do
7575
{{:osc_float, value}, rest}
7676
end
7777

78+
defp get_next_value(?s, arguments) do
79+
[string, rest] = String.split arguments, <<0>>, global: false
80+
rest = remove_extra_nulls string, rest
81+
{{:osc_string, string}, rest}
82+
end
83+
7884
end
7985

test/osc/message_test.exs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,19 @@ defmodule OSC.MessageTest do
4343
assert_in_delta 440.0, float_value, 0.001
4444
end
4545

46+
test "parses a string message" do
47+
msg = <<"/ab", 0, ",s", 0, 0, "john", 0, 0, 0, 0>>
48+
assert {"/ab", [{:osc_string, "john"}]} = OSC.Message.parse(msg)
49+
50+
msg = <<"/ab", 0, ",s", 0, 0, "hello", 0, 0, 0>>
51+
assert {"/ab", [{:osc_string, "hello"}]} = OSC.Message.parse(msg)
52+
53+
msg = <<"/ab", 0, ",s", 0, 0, "ab", 0, 0>>
54+
assert {"/ab", [{:osc_string, "ab"}]} = OSC.Message.parse(msg)
55+
56+
msg = <<"/ab", 0, ",s", 0, 0, "bob", 0>>
57+
assert {"/ab", [{:osc_string, "bob"}]} = OSC.Message.parse(msg)
58+
end
59+
4660
end
4761

0 commit comments

Comments
 (0)