Module: SteamSerializable
- Included in:
- Accept, ChallengeData, ConnectData, Datagram, Disconnect, ExtendedClientMsgHdr, MsgChannelEncryptRequest, MsgChannelEncryptResponse, MsgChannelEncryptResult, MsgClientAppUsageEvent, MsgClientChatAction, MsgClientChatActionResult, MsgClientChatEnter, MsgClientChatMemberInfo, MsgClientChatMsg, MsgClientChatRoomInfo, MsgClientCreateChat, MsgClientCreateChatResponse, MsgClientEmailAddrInfo, MsgClientGenericResponse, MsgClientGetFriendsWhoPlayGame, MsgClientGetFriendsWhoPlayGameResponse, MsgClientJoinChat, MsgClientJustStrings, MsgClientLogOnResponse, MsgClientLoggedOff, MsgClientLogon, MsgClientMarketingMessageUpdate2, MsgClientNewLoginKey, MsgClientNewLoginKeyAccepted, MsgClientOGSBeginSession, MsgClientOGSBeginSessionResponse, MsgClientOGSEndSession, MsgClientOGSEndSessionResponse, MsgClientOGSWriteRow, MsgClientP2PIntroducerMessage, MsgClientRequestedClientStats, MsgClientSendGuestPass, MsgClientSendGuestPassResponse, MsgClientServerUnavailable, MsgClientSetIgnoreFriend, MsgClientSetIgnoreFriendResponse, MsgClientUpdateGuestPassesList, MsgClientVACBanStatus, MsgGCHdr, MsgGCHdrProtoBuf, MsgGSApprove, MsgGSDeny, MsgGSGetPlayStatsResponse, MsgGSGetReputationResponse, MsgGSGetUserGroupStatus, MsgGSGetUserGroupStatusResponse, MsgGSKick, MsgGSPerformHardwareSurvey, MsgHdr, MsgHdrProtoBuf, UdpHeader
- Defined in:
- lib/steamd/generator/ruby/steam_serializable.rb
Overview
Included in each Generated Ruby class. Provides access to methods on the class as well as serialization options.
Instance Attribute Summary collapse
-
#constants ⇒ Object
readonly
Variables in this class.
-
#variables ⇒ Object
readonly
Variables in this class.
Instance Method Summary collapse
-
#consts ⇒ Array<SerizableConstant>
Returns a list of SerizableConstant objects.
-
#deserialize(io) ⇒ Object
(also: #decode, #decode_from)
Deserialize the object using an IO stream.
-
#encode_to(io) ⇒ Object
Encode to a given IO stream.
-
#flag(vars, var) ⇒ Object
Looks up the variable flag.
-
#initialize(vars, consts = []) ⇒ Object
Sets the variables and constants of this Steam object.
-
#serialize ⇒ String
(also: #encode)
Serialize the constants and variables into a stream.
-
#vars ⇒ Array<SerializedVariable>
Returns a list of SerializedVariable objects.
Instance Attribute Details
#constants ⇒ Object (readonly)
Variables in this class
13 14 15 |
# File 'lib/steamd/generator/ruby/steam_serializable.rb', line 13 def constants @constants end |
#variables ⇒ Object (readonly)
Variables in this class
10 11 12 |
# File 'lib/steamd/generator/ruby/steam_serializable.rb', line 10 def variables @variables end |
Instance Method Details
#consts ⇒ Array<SerizableConstant>
Returns a list of SerizableConstant objects. Allowing you to serialize each constant
53 54 55 |
# File 'lib/steamd/generator/ruby/steam_serializable.rb', line 53 def consts constants.values.map { |const| SerizableConstant.new(const) } end |
#deserialize(io) ⇒ Object Also known as: decode, decode_from
Deserialize the object using an IO stream
42 43 44 45 |
# File 'lib/steamd/generator/ruby/steam_serializable.rb', line 42 def deserialize(io) (consts + vars).each { |v| send("#{v.name}=", v.deserialize(io)) } self end |
#encode_to(io) ⇒ Object
Encode to a given IO stream
24 25 26 |
# File 'lib/steamd/generator/ruby/steam_serializable.rb', line 24 def encode_to(io) io.write(serialize) end |
#flag(vars, var) ⇒ Object
Looks up the variable flag. This is used for when variables are of a defined length
ie:
int header_len;
proto<header_len> ProtoBuf name;
The flag in the case of serialization would be the “name” variable as it would need to write that before it can write header len.
The flag in the case of deserialization would be the “header_len” variable because it defines how many bytes to read so we can read the “name” variable
85 86 87 88 |
# File 'lib/steamd/generator/ruby/steam_serializable.rb', line 85 def flag(vars, var) (vars.select { |v| v.modifier_size == var.name } + vars.select { |v| v.name == var.modifier_size }).first end |
#initialize(vars, consts = []) ⇒ Object
Sets the variables and constants of this Steam object
16 17 18 19 |
# File 'lib/steamd/generator/ruby/steam_serializable.rb', line 16 def initialize(vars, consts = []) @variables = vars.each_with_object({}) { |v, m| m[v[:name]] = v } @constants = consts.each_with_object({}) { |v, m| m[v[:name]] = v } end |
#serialize ⇒ String Also known as: encode
Serialize the constants and variables into a stream
31 32 33 34 35 36 |
# File 'lib/steamd/generator/ruby/steam_serializable.rb', line 31 def serialize stream = StringIO.new stream.set_encoding('BINARY') stream.write((consts + vars).map(&:serialize).join) stream.string end |
#vars ⇒ Array<SerializedVariable>
Returns a list of SerializedVariable objects. Allowing you to serialize each constant
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/steamd/generator/ruby/steam_serializable.rb', line 61 def vars vars = variables.values.map do |v| SerizableVariable.new(v) end vars.map do |var| var.flag = flag(vars, var) var end end |