Class: Vizcore::Sync::OscMessage::Parser Private
- Inherits:
-
Object
- Object
- Vizcore::Sync::OscMessage::Parser
- Defined in:
- lib/vizcore/sync/osc_message.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Constant Summary collapse
- BUNDLE_SIGNATURE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
"#bundle"- NTP_TO_UNIX_OFFSET =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
2_208_988_800
Instance Method Summary collapse
-
#initialize(data) ⇒ Parser
constructor
private
A new instance of Parser.
- #parse_bundle ⇒ Object private
- #parse_message(address, timetag: nil) ⇒ Object private
- #parse_packet(default_timetag: nil) ⇒ Vizcore::Sync::OscMessage, ... private
- #read_arguments(tags) ⇒ Array private
- #read_string ⇒ String? private
Constructor Details
#initialize(data) ⇒ Parser
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Parser.
33 34 35 36 |
# File 'lib/vizcore/sync/osc_message.rb', line 33 def initialize(data) @data = data.to_s.b @offset = 0 end |
Instance Method Details
#parse_bundle ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/vizcore/sync/osc_message.rb', line 59 def parse_bundle = (read_uint64) = [] until @offset >= @data.bytesize break if @offset + 4 > @data.bytesize begin = read_int32 rescue StandardError break end break if <= 0 begin = read_bytes() rescue StandardError break end parsed = Parser.new().parse_packet(default_timetag: ) .concat(Array(parsed)) end end |
#parse_message(address, timetag: nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
87 88 89 90 91 92 93 |
# File 'lib/vizcore/sync/osc_message.rb', line 87 def (address, timetag: nil) return nil unless address&.start_with?("/") = read_string arguments = read_arguments() OscMessage.new(address: address, arguments: arguments, timetag: ) end |
#parse_packet(default_timetag: nil) ⇒ Vizcore::Sync::OscMessage, ...
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
39 40 41 42 43 44 45 |
# File 'lib/vizcore/sync/osc_message.rb', line 39 def parse_packet(default_timetag: nil) signature_or_address = read_string return nil unless signature_or_address return parse_bundle if signature_or_address == BUNDLE_SIGNATURE (signature_or_address, timetag: ) end |
#read_arguments(tags) ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
97 98 99 100 101 102 103 104 |
# File 'lib/vizcore/sync/osc_message.rb', line 97 def read_arguments() return [] if .to_s.empty? return [] unless .start_with?(",") [1..].to_s.each_char.map do |tag| read_argument(tag) end end |
#read_string ⇒ String?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/vizcore/sync/osc_message.rb', line 48 def read_string start = @offset @offset += 1 while @offset < @data.bytesize && @data.getbyte(@offset) != 0 return nil if @offset >= @data.bytesize value = @data.byteslice(start...@offset).to_s.force_encoding(Encoding::UTF_8) @offset += 1 align_offset value end |