Skip to content

Commit

Permalink
Merge branch 'add-double' of https://github.com/samaaron/osc-ruby int…
Browse files Browse the repository at this point in the history
…o samaaron-add-double
  • Loading branch information
aberant committed Aug 18, 2013
2 parents 4675169 + 13d6763 commit 9d43128
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
15 changes: 11 additions & 4 deletions lib/osc-ruby/osc_packet.rb
Expand Up @@ -47,10 +47,11 @@ def self.decode_simple_message( time, osc_packet )
def initialize( string )
@packet = NetworkPacket.new( string )

@types = { "i" => lambda{ OSCInt32.new( get_int32 ) },
"f" => lambda{ OSCFloat32.new( get_float32 ) },
"s" => lambda{ OSCString.new( get_string ) },
"b" => lambda{ OSCBlob.new( get_blob )}
@types = { "i" => lambda{ OSCInt32.new( get_int32 ) },
"f" => lambda{ OSCFloat32.new( get_float32 ) },
"d" => lambda{ OSCDouble64.new( get_double64 )},
"s" => lambda{ OSCString.new( get_string ) },
"b" => lambda{ OSCBlob.new( get_blob )}
}
end

Expand Down Expand Up @@ -116,6 +117,12 @@ def get_float32
f
end

def get_double64
f = @packet.getn(8).unpack('G')[0]
@packet.skip_padding
f
end

def get_blob
l = @packet.getn(4).unpack('N')[0]
b = @packet.getn(l)
Expand Down
9 changes: 7 additions & 2 deletions lib/osc-ruby/osc_types.rb
Expand Up @@ -8,7 +8,12 @@ def encode() [@val].pack('N').force_encoding("BINARY") end

class OSCFloat32 < OSCArgument
def tag() 'f' end
def encode() [@val].pack('g').force_encoding("BINARY") end
def encode() [@val].pack('g').force_encoding("BINARY") end
end

class OSCDouble64 < OSCArgument
def tag() 'd' end
def encode() [@val].pack('G').force_encoding("BINARY") end
end

class OSCString < OSCArgument
Expand All @@ -20,4 +25,4 @@ class OSCBlob < OSCArgument
def tag() 'b' end
def encode() padding([@val.size].pack('N') + @val).force_encoding("BINARY") end
end
end
end

0 comments on commit 9d43128

Please sign in to comment.