class Message

Public Class Methods

new(content) click to toggle source

向斗鱼发送的消息 1.通信协议长度,后四个部分的长度,四个字节 2.第二部分与第一部分一样 3.请求代码,发送给斗鱼的话,内容为0xb1,0x02, 斗鱼返回的代码为0xb2,0x02 4.发送内容 5.末尾字节

# File lib/danmu/models/message.rb, line 8
def initialize(content)
  @length = [content.size + 9, 0x00, 0x00, 0x00].pack('c*')
  @code = @length.dup
  @magic = [0xb1, 0x02, 0x00, 0x00].pack('c*')
  @content = content
  @end = [0x00].pack('c*')
end
parse_content(message_all) click to toggle source
# File lib/danmu/models/message.rb, line 21
def self.parse_content(message_all)
  message_all[10, -2].unpack('c*')
end

Public Instance Methods

to_s() click to toggle source
# File lib/danmu/models/message.rb, line 16
def to_s
  @length + @code + @magic + @content + @end
end