Class: Type

Inherits:
Object
  • Object
show all
Defined in:
lib/steamd/generator/ruby/serializable_type.rb

Overview

Serializable type

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ Type

Instantiate a Type

Examples:

Instantiate a Type

type = Type.new('int')


10
11
12
# File 'lib/steamd/generator/ruby/serializable_type.rb', line 10

def initialize(type)
  @type = type
end

Instance Attribute Details

#typeString (readonly)

The String representation of the Type. If it is a SteamKit Internal type, the type is transformed into namespaces from the ‘steam-proto` repo.

Returns:



18
19
20
# File 'lib/steamd/generator/ruby/serializable_type.rb', line 18

def type
  @type
end

Instance Method Details

#bytedirectiveString

The byte directive for this type

Returns:



48
49
50
51
52
53
54
55
56
57
# File 'lib/steamd/generator/ruby/serializable_type.rb', line 48

def bytedirective
  {
    'int' => 'l<',
    'ushort' => 'S<',
    'short' => 's<',
    'byte' => 'c',
    'uint' => 'L<',
    'ulong' => 'Q<'
  }[type]
end

#bytesizeInteger

The size in bytes of this type

Returns:

  • (Integer)


62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/steamd/generator/ruby/serializable_type.rb', line 62

def bytesize
  case type
  when 'uint', 'int'
    4
  when 'ushort', 'short'
    2
  when 'ulong', 'long'
    8
  when 'byte'
    1
  end
end

#encodable?Bool

Is this type an encodable type?

Returns:

  • (Bool)


34
35
36
# File 'lib/steamd/generator/ruby/serializable_type.rb', line 34

def encodable?
  encodables.include?(type)
end

#klassObject

The Class represented by this Type

Returns:

  • (Object)


78
79
80
# File 'lib/steamd/generator/ruby/serializable_type.rb', line 78

def klass
  type.constantize
end

#primitive?Bool

Is this type an primitive type?

Returns:

  • (Bool)


41
42
43
# File 'lib/steamd/generator/ruby/serializable_type.rb', line 41

def primitive?
  primitives.include?(type)
end