Class: YARP::Pack::Directive

Inherits:
Object
  • Object
show all
Defined in:
lib/yarp/pack.rb,
ext/yarp/api_pack.c

Constant Summary collapse

ENDIAN_DESCRIPTIONS =
{
  AGNOSTIC_ENDIAN: 'agnostic',
  LITTLE_ENDIAN: 'little-endian (VAX)',
  BIG_ENDIAN: 'big-endian (network)',
  NATIVE_ENDIAN: 'native-endian',
  ENDIAN_NA: 'n/a'
}
SIGNED_DESCRIPTIONS =
{
  UNSIGNED: 'unsigned',
  SIGNED: 'signed',
  SIGNED_NA: 'n/a'
}
SIZE_DESCRIPTIONS =
{
  SIZE_SHORT: 'short',
  SIZE_INT: 'int-width',
  SIZE_LONG: 'long',
  SIZE_LONG_LONG: 'long long',
  SIZE_8: '8-bit',
  SIZE_16: '16-bit',
  SIZE_32: '32-bit',
  SIZE_64: '64-bit',
  SIZE_P: 'pointer-width'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version, variant, source, type, signed, endian, size, length_type, length) ⇒ Directive

Returns a new instance of Directive.



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/yarp/pack.rb', line 60

def initialize(version, variant, source, type, signed, endian, size, length_type, length)
  @version = version
  @variant = variant
  @source = source
  @type = type
  @signed = signed
  @endian = endian
  @size = size
  @length_type = length_type
  @length = length
end

Instance Attribute Details

#endianObject (readonly)

Returns the value of attribute endian.



58
59
60
# File 'lib/yarp/pack.rb', line 58

def endian
  @endian
end

#lengthObject (readonly)

Returns the value of attribute length.



58
59
60
# File 'lib/yarp/pack.rb', line 58

def length
  @length
end

#length_typeObject (readonly)

Returns the value of attribute length_type.



58
59
60
# File 'lib/yarp/pack.rb', line 58

def length_type
  @length_type
end

#signedObject (readonly)

Returns the value of attribute signed.



58
59
60
# File 'lib/yarp/pack.rb', line 58

def signed
  @signed
end

#sizeObject (readonly)

Returns the value of attribute size.



58
59
60
# File 'lib/yarp/pack.rb', line 58

def size
  @size
end

#sourceObject (readonly)

Returns the value of attribute source.



58
59
60
# File 'lib/yarp/pack.rb', line 58

def source
  @source
end

#typeObject (readonly)

Returns the value of attribute type.



58
59
60
# File 'lib/yarp/pack.rb', line 58

def type
  @type
end

#variantObject (readonly)

Returns the value of attribute variant.



58
59
60
# File 'lib/yarp/pack.rb', line 58

def variant
  @variant
end

#versionObject (readonly)

Returns the value of attribute version.



58
59
60
# File 'lib/yarp/pack.rb', line 58

def version
  @version
end

Instance Method Details

#describeObject



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/yarp/pack.rb', line 98

def describe
  case type
  when SPACE
    'whitespace'
  when COMMENT
    'comment'
  when INTEGER
    if size == SIZE_8
      base = "#{SIGNED_DESCRIPTIONS[signed]} #{SIZE_DESCRIPTIONS[size]} integer"
    else
      base = "#{SIGNED_DESCRIPTIONS[signed]} #{SIZE_DESCRIPTIONS[size]} #{ENDIAN_DESCRIPTIONS[endian]} integer"
    end
    case length_type
    when LENGTH_FIXED
      if length > 1
        base + ", x#{length}"
      else
        base
      end
    when LENGTH_MAX
      base + ', as many as possible'
    end
  when UTF8
    'UTF-8 character'
  when BER
    'BER-compressed integer'
  when FLOAT
    "#{SIZE_DESCRIPTIONS[size]} #{ENDIAN_DESCRIPTIONS[endian]} float"
  when STRING_SPACE_PADDED
    'arbitrary binary string (space padded)'
  when STRING_NULL_PADDED
    'arbitrary binary string (null padded, count is width)'
  when STRING_NULL_TERMINATED
    'arbitrary binary string (null padded, count is width), except that null is added with *'
  when STRING_MSB
    'bit string (MSB first)'
  when STRING_LSB
    'bit string (LSB first)'
  when STRING_HEX_HIGH
    'hex string (high nibble first)'
  when STRING_HEX_LOW
    'hex string (low nibble first)'
  when STRING_UU
    'UU-encoded string'
  when STRING_MIME
    'quoted printable, MIME encoding'
  when STRING_BASE64
    'base64 encoded string'
  when STRING_FIXED
    'pointer to a structure (fixed-length string)'
  when STRING_POINTER
    'pointer to a null-terminated string'
  when MOVE
    'move to absolute position'
  when BACK
    'back up a byte'
  when NULL
    'null byte'
  else
    raise
  end
end