Module: Steam::Protocol::Message
- Included in:
- ClientMessage, GcMessage, ProtobufMessage
- Defined in:
- lib/steam/protocol/message.rb
Overview
The base Steam message. Each message contains a header, body and emsg attribute.
The #emsg corresponds to the constants EMsg in the SteamLanguage
Constant Summary collapse
- PROTO_MASK =
Valve's mask for determining if a packet is Protobuf backed
0x80000000
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Each packet has a body, this is the Message being held in the packet.
-
#emsg ⇒ Object
readonly
The Message type.
-
#header ⇒ Object
readonly
Each packet has a header.
-
#payload ⇒ Object
readonly
Each packet has an optional byte string payload.
Instance Method Summary collapse
-
#decode(io) ⇒ Object
Decode a Packet from an io object.
-
#encode ⇒ String
Encode a Packet from to a string.
-
#initialize(header, body, emsg) ⇒ Object
Instantiate a Message object.
-
#proto? ⇒ Boolean
By default a Message is not Protobuf backed.
-
#session_id=(_sid) ⇒ Object
The session id associated with the message.
-
#steam_id=(_sid) ⇒ Object
The steam id associated with the message.
Instance Attribute Details
#body ⇒ Object (readonly)
Each packet has a body, this is the Message being held in the packet.
24 25 26 |
# File 'lib/steam/protocol/message.rb', line 24 def body @body end |
#emsg ⇒ Object (readonly)
The Message type
32 33 34 |
# File 'lib/steam/protocol/message.rb', line 32 def emsg @emsg end |
#header ⇒ Object (readonly)
Each packet has a header. The header is defined by the Steam Language. A header can be a MsgHdr, or a MsgHdrProtoBuf
20 21 22 |
# File 'lib/steam/protocol/message.rb', line 20 def header @header end |
#payload ⇒ Object (readonly)
Each packet has an optional byte string payload
27 28 29 |
# File 'lib/steam/protocol/message.rb', line 27 def payload @payload end |
Instance Method Details
#decode(io) ⇒ Object
Decode a Packet from an io object
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/steam/protocol/message.rb', line 70 def decode(io) @header.decode_from(io) if @body.respond_to?(:decode_from) # Steam language @body.decode_from(io) else # Proto @body = @body.class.decode(io.read) end end |
#encode ⇒ String
Encode a Packet from to a string
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/steam/protocol/message.rb', line 86 def encode io = StringIO.new io.set_encoding('BINARY') @header.encode_to(io) body = @body.encode io.write(body) io.write(@payload.string) io.string end |
#initialize(header, body, emsg) ⇒ Object
Instantiate a Message object
39 40 41 42 43 44 45 46 |
# File 'lib/steam/protocol/message.rb', line 39 def initialize(header, body, emsg) @header = header @body = body @header.msg = emsg @payload = ByteWriter.new @emsg = emsg nil end |
#proto? ⇒ Boolean
By default a Message is not Protobuf backed
49 50 51 |
# File 'lib/steam/protocol/message.rb', line 49 def proto? false end |
#session_id=(_sid) ⇒ Object
The session id associated with the message
63 64 65 |
# File 'lib/steam/protocol/message.rb', line 63 def session_id=(_sid) raise NotImplementedError end |
#steam_id=(_sid) ⇒ Object
The steam id associated with the message
56 57 58 |
# File 'lib/steam/protocol/message.rb', line 56 def steam_id=(_sid) raise NotImplementedError end |