Sha256: 55fbea4e39c0f50d158935001f1daaae4f75c85a239db115bb5d7f2b8f37a193

Contents?: true

Size: 858 Bytes

Versions: 3

Compression:

Stored size: 858 Bytes

Contents

module OSC
  module TCP
    class SendingSocket
      def initialize socket
        @socket = socket
      end

      def send msg
        @socket_buffer = []

        enc_msg = msg.encode

        send_char CHAR_END

        enc_msg.bytes.each do |b|
          case b
          when CHAR_END
            send_char CHAR_ESC
            send_char CHAR_ESC_END
          when CHAR_ESC
            send_char CHAR_ESC
            send_char CHAR_ESC_ESC
          else
            send_char b
          end
        end

        send_char CHAR_END

        flush

        # puts "[TCP::SendingSocket] sent message: #{ enc_msg.inspect }"
      end

      private

      def flush
        @socket.send @socket_buffer.join, 0
      end

      def send_char c
        @socket_buffer << [c].pack('C')
        # @socket.send [c].pack('C'), 0
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
qcmd-0.2.0 lib/qcmd/core_ext/osc/sending_socket.rb
qcmd-0.1.16 lib/qcmd/core_ext/osc/sending_socket.rb
qcmd-0.1.16.pre2 lib/qcmd/core_ext/osc/sending_socket.rb