Class: AVP
Overview
Represents a Diameter AVP. Use this for non-vendor-specific AVPs, and its subclass VendorSpecificAVP for ones defined for a particular vendor.
Direct Known Subclasses
Constant Summary
Constant Summary
Constants included from AVPType
AVPType::GROUPED, AVPType::IPADDR, AVPType::OCTETSTRING, AVPType::U32
Instance Attribute Summary (collapse)
-
- (Fixnum) code
readonly
The AVP Code.
-
- (true, false) mandatory
readonly
Whether this AVP is mandatory (i.e. its M flag is set).
- - (Boolean) vendor_specific? readonly
Data getters/setters for different AVP types (collapse)
-
- (Float) float32
Returns this AVP's byte data, interpreted as a Float32.
-
- (void) float32=(value)
Sets this AVP's byte data to a Float32.
-
- (Float) float64
Returns this AVP's byte data, interpreted as a Float64.
-
- (void) float64=(value)
Sets this AVP's byte data to a Float64.
-
- (Array<AVP>) grouped_value
Returns this AVP's byte data, interpreted as a Grouped AVP.
-
- (void) grouped_value=(avps)
Sets this AVP's byte data to a Grouped AVP.
-
- (AVP?) inner_avp(name)
For a grouped AVP, returns the first AVP with this name it contains.
-
- (Array<AVP>) inner_avps(name)
For a grouped AVP, returns all AVPs it contains with this name.
-
- (Fixnum) int32
Returns this AVP's byte data, interpreted as an Integer32.
-
- (void) int32=(value)
Sets this AVP's byte data to an Integer32.
-
- (Fixnum) int64
Returns this AVP's byte data, interpreted as an Integer64.
-
- (void) int64=(value)
Sets this AVP's byte data to an Integer64.
-
- (IPAddr) ip_address
Returns this AVP's byte data, interpreted as an Address.
-
- (void) ip_address=(value)
Sets this AVP's byte data to an Address.
-
- (String) octet_string
Returns this AVP's byte data, interpreted as an OctetString.
-
- (void) octet_string=(value)
Sets this AVP's byte data to an OctetString.
-
- (Fixnum) uint32
Returns this AVP's byte data, interpreted as an Unsigned32.
-
- (void) uint32=(value)
Sets this AVP's byte data to an Unsigned32.
-
- (Fixnum) uint64
Returns this AVP's byte data, interpreted as an Unsigned64.
-
- (void) uint64=(value)
Sets this AVP's byte data to an Unsigned64.
Class Method Summary (collapse)
-
+ (AVP) create(name, val, options = {})
Creates an AVP by name, and assigns it a value.
Instance Method Summary (collapse)
-
- (AVP) initialize(code, options = {})
constructor
A new instance of AVP.
-
- (Object) to_s
Returns a string representation of this AVP.
-
- (String) to_wire
Returns this AVP encoded properly as bytes in network byte order, suitable for sending over a TCP or SCTP connection.
Methods included from AVPParser
mandatory_bit, parse_avps_int, vendor_id_bit
Constructor Details
- (AVP) initialize(code, options = {})
Returns a new instance of AVP
88 89 90 91 92 93 |
# File 'lib/diameter/avp.rb', line 88 def initialize(code, = {}) @code = code @content = [:content] || '' @mandatory = [:mandatory] @mandatory = true if @mandatory.nil? end |
Instance Attribute Details
- (Fixnum) code (readonly)
Returns The AVP Code
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 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 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 |
# File 'lib/diameter/avp.rb', line 82 class AVP include AVPType attr_reader :code, :mandatory include AVPParser def initialize(code, = {}) @code = code @content = [:content] || '' @mandatory = [:mandatory] @mandatory = true if @mandatory.nil? end # Creates an AVP by name, and assigns it a value. # # @param name The name of the AVP, e.g. "Origin-Host" # @param val The value of the AVP. Must be of the type defined for # that AVP - e.g. a Fixnum for an AVP defined as Unsigned32, a # String for an AVP defined as OctetString, or an IPAddr for an AVP # defined as IPAddress. # @return [AVP] The AVP that was created. def self.create(name, val, ={}) code, type, vendor = AVPNames.get(name) avp = if (vendor != 0) VendorSpecificAVP.new(code, vendor, ) else AVP.new(code, ) end set_content(avp, type, val) avp end # Returns this AVP encoded properly as bytes in network byte order, # suitable for sending over a TCP or SCTP connection. See # {http://tools.ietf.org/html/rfc6733#section-4.1} for the # format. # # @return [String] The bytes representing this AVP def to_wire length_8, length_16 = UInt24.to_u8_and_u16(@content.length + 8) avp_flags = @mandatory ? '01000000' : '00000000' header = [@code, avp_flags, length_8, length_16].pack('NB8Cn') header + self.padded_content end # Guessing the type of an AVP and displaying it sensibly is complex, # so this is a complex method (but one that has a unity of purpose, # so can't easily be broken down). Disable several Rubocop # complexity metrics to reflect this. # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity # rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity # Returns a string representation of this AVP. Makes a best-effort # attempt to guess the type of the content (even for unknown AVPs) # and display it sensibly. # # @example # avp.to_s => "AVP 267, mandatory: true, content as int32: 1" def to_s has_all_ascii_values = @content.bytes.reject { |c| (32 < c && c < 126) }.empty? could_be_32bit_num = (@content.length == 4) could_be_64bit_num = (@content.length == 8) could_be_ip = ((@content.length == 6 && @content[0..1] == "\x00\x01") || (@content.length == 18 && @content[0..1] == "\x00\x02")) maybe_grouped = !(has_all_ascii_values || could_be_64bit_num || could_be_32bit_num || could_be_ip) s = to_s_first_line s += ", content as string: #{@content}" if has_all_ascii_values s += ", content as int32: #{uint32}" if could_be_32bit_num s += ", content as int64: #{uint64}" if could_be_64bit_num s += ", content as ip: #{ip_address}" if could_be_ip s += ", grouped AVP, #{grouped_value.collect(&:to_s)}" if maybe_grouped s end # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity # rubocop:enable Metrics/MethodLength, Metrics/PerceivedComplexity # @!attribute [r] vendor_specific? # @return [true, false] Whether this AVP is mandatory (i.e. its M flag is set) def vendor_specific? false end # @!group Data getters/setters for different AVP types # Returns this AVP's byte data, interpreted as a {http://tools.ietf.org/html/rfc6733#section-4.4 Grouped AVP}. # # @return [Array<AVP>] The contained AVPs. def grouped_value AVPParser::parse_avps_int(@content) end # Sets this AVP's byte data to a {http://tools.ietf.org/html/rfc6733#section-4.4 Grouped AVP}. # # @param [Array<AVP>] avps The AVPs that should be contained within # this AVP. # @return [void] def grouped_value=(avps) new_content = '' avps.each { |a| new_content += a.to_wire } @content = new_content end # For a grouped AVP, returns the first AVP with this name it # contains. # # @param [String] name The AVP name # @return [AVP] if this AVP is found inside the Grouped AVP # @return [nil] if this AVP is not found inside the Grouped AVP def inner_avp(name) avps = inner_avps(name) if avps.empty? nil else avps[0] end end # For a grouped AVP, returns all AVPs it contains with this name. # # @param [String] name The AVP name # @return [Array<AVP>] def inner_avps(name) code, _type, _vendor = AVPNames.get(name) self.grouped_value.select { |a| a.code == code} end # Even though it is just "the raw bytes in the content", # octet_string is only one way of interpreting the AVP content and # shouldn't be treated differently to the others, so disable the # TrivialAccessors warning. # rubocop:disable Style/TrivialAccessors # Returns this AVP's byte data, interpreted as an OctetString. # # @return [String] The contained OctetString. def octet_string @content end # Sets this AVP's byte data to an OctetString. # # @param [String] value The octets to use as the value. # @return [void] def octet_string=(value) @content = value end # rubocop:enable Style/TrivialAccessors # Returns this AVP's byte data, interpreted as an Integer32. # # @return [Fixnum] The contained Integer32. def int32 @content.unpack('l>')[0] end # Sets this AVP's byte data to an Integer32. # # @param [Fixnum] value # @return [void] def int32=(value) @content = [value].pack('l>') end # Returns this AVP's byte data, interpreted as an Integer64. # # @return [Fixnum] The contained Integer64. def int64 @content.unpack('q>')[0] end # Sets this AVP's byte data to an Integer64. # # @param [Fixnum] value # @return [void] def int64=(value) @content = [value].pack('q>') end # Returns this AVP's byte data, interpreted as an Unsigned32. # # @return [Fixnum] The contained Unsigned32. def uint32 @content.unpack('N')[0] end # Sets this AVP's byte data to an Unsigned32. # # @param [Fixnum] value # @return [void] def uint32=(value) @content = [value].pack('N') end # Returns this AVP's byte data, interpreted as an Unsigned64. # # @return [Fixnum] The contained Unsigned64. def uint64 @content.unpack('Q>')[0] end # Sets this AVP's byte data to an Unsigned64. # # @param [Fixnum] value # @return [void] def uint64=(value) @content = [value].pack('Q>') end # Returns this AVP's byte data, interpreted as a Float32. # # @return [Float] The contained Float32. def float32 @content.unpack('g')[0] end # Sets this AVP's byte data to a Float32. # # @param [Float] value # @return [void] def float32=(value) @content = [value].pack('g') end # Returns this AVP's byte data, interpreted as a Float64. # # @return [Float] The contained Float64. def float64 @content.unpack('G')[0] end # Sets this AVP's byte data to a Float64. # # @param [Float] value # @return [void] def float64=(value) @content = [value].pack('G') end # Returns this AVP's byte data, interpreted as an {http://tools.ietf.org/html/rfc6733#section-4.3.1 Address}. # # @return [IPAddr] The contained {http://tools.ietf.org/html/rfc6733#section-4.3.1 Address}. def ip_address IPAddr.new_ntoh(@content[2..-1]) end # Sets this AVP's byte data to an Address. # # @param [IPAddr] value # @return [void] def ip_address=(value) bytes = if value.ipv4? [1].pack('n') else [2].pack('n') end bytes += value.hton @content = bytes end # @!endgroup private def self.set_content(avp, type, val) case type when GROUPED avp.grouped_value = val when U32 avp.uint32 = val when OCTETSTRING avp.octet_string = val when IPADDR avp.ip_address = val end end def to_s_first_line "AVP #{@code}, mandatory: #{@mandatory}" end protected def padded_content wire_content = @content while ((wire_content.length % 4) != 0) wire_content += "\x00" end wire_content end end |
- (true, false) mandatory (readonly)
Returns Whether this AVP is mandatory (i.e. its M flag is set)
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 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 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 |
# File 'lib/diameter/avp.rb', line 82 class AVP include AVPType attr_reader :code, :mandatory include AVPParser def initialize(code, = {}) @code = code @content = [:content] || '' @mandatory = [:mandatory] @mandatory = true if @mandatory.nil? end # Creates an AVP by name, and assigns it a value. # # @param name The name of the AVP, e.g. "Origin-Host" # @param val The value of the AVP. Must be of the type defined for # that AVP - e.g. a Fixnum for an AVP defined as Unsigned32, a # String for an AVP defined as OctetString, or an IPAddr for an AVP # defined as IPAddress. # @return [AVP] The AVP that was created. def self.create(name, val, ={}) code, type, vendor = AVPNames.get(name) avp = if (vendor != 0) VendorSpecificAVP.new(code, vendor, ) else AVP.new(code, ) end set_content(avp, type, val) avp end # Returns this AVP encoded properly as bytes in network byte order, # suitable for sending over a TCP or SCTP connection. See # {http://tools.ietf.org/html/rfc6733#section-4.1} for the # format. # # @return [String] The bytes representing this AVP def to_wire length_8, length_16 = UInt24.to_u8_and_u16(@content.length + 8) avp_flags = @mandatory ? '01000000' : '00000000' header = [@code, avp_flags, length_8, length_16].pack('NB8Cn') header + self.padded_content end # Guessing the type of an AVP and displaying it sensibly is complex, # so this is a complex method (but one that has a unity of purpose, # so can't easily be broken down). Disable several Rubocop # complexity metrics to reflect this. # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity # rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity # Returns a string representation of this AVP. Makes a best-effort # attempt to guess the type of the content (even for unknown AVPs) # and display it sensibly. # # @example # avp.to_s => "AVP 267, mandatory: true, content as int32: 1" def to_s has_all_ascii_values = @content.bytes.reject { |c| (32 < c && c < 126) }.empty? could_be_32bit_num = (@content.length == 4) could_be_64bit_num = (@content.length == 8) could_be_ip = ((@content.length == 6 && @content[0..1] == "\x00\x01") || (@content.length == 18 && @content[0..1] == "\x00\x02")) maybe_grouped = !(has_all_ascii_values || could_be_64bit_num || could_be_32bit_num || could_be_ip) s = to_s_first_line s += ", content as string: #{@content}" if has_all_ascii_values s += ", content as int32: #{uint32}" if could_be_32bit_num s += ", content as int64: #{uint64}" if could_be_64bit_num s += ", content as ip: #{ip_address}" if could_be_ip s += ", grouped AVP, #{grouped_value.collect(&:to_s)}" if maybe_grouped s end # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity # rubocop:enable Metrics/MethodLength, Metrics/PerceivedComplexity # @!attribute [r] vendor_specific? # @return [true, false] Whether this AVP is mandatory (i.e. its M flag is set) def vendor_specific? false end # @!group Data getters/setters for different AVP types # Returns this AVP's byte data, interpreted as a {http://tools.ietf.org/html/rfc6733#section-4.4 Grouped AVP}. # # @return [Array<AVP>] The contained AVPs. def grouped_value AVPParser::parse_avps_int(@content) end # Sets this AVP's byte data to a {http://tools.ietf.org/html/rfc6733#section-4.4 Grouped AVP}. # # @param [Array<AVP>] avps The AVPs that should be contained within # this AVP. # @return [void] def grouped_value=(avps) new_content = '' avps.each { |a| new_content += a.to_wire } @content = new_content end # For a grouped AVP, returns the first AVP with this name it # contains. # # @param [String] name The AVP name # @return [AVP] if this AVP is found inside the Grouped AVP # @return [nil] if this AVP is not found inside the Grouped AVP def inner_avp(name) avps = inner_avps(name) if avps.empty? nil else avps[0] end end # For a grouped AVP, returns all AVPs it contains with this name. # # @param [String] name The AVP name # @return [Array<AVP>] def inner_avps(name) code, _type, _vendor = AVPNames.get(name) self.grouped_value.select { |a| a.code == code} end # Even though it is just "the raw bytes in the content", # octet_string is only one way of interpreting the AVP content and # shouldn't be treated differently to the others, so disable the # TrivialAccessors warning. # rubocop:disable Style/TrivialAccessors # Returns this AVP's byte data, interpreted as an OctetString. # # @return [String] The contained OctetString. def octet_string @content end # Sets this AVP's byte data to an OctetString. # # @param [String] value The octets to use as the value. # @return [void] def octet_string=(value) @content = value end # rubocop:enable Style/TrivialAccessors # Returns this AVP's byte data, interpreted as an Integer32. # # @return [Fixnum] The contained Integer32. def int32 @content.unpack('l>')[0] end # Sets this AVP's byte data to an Integer32. # # @param [Fixnum] value # @return [void] def int32=(value) @content = [value].pack('l>') end # Returns this AVP's byte data, interpreted as an Integer64. # # @return [Fixnum] The contained Integer64. def int64 @content.unpack('q>')[0] end # Sets this AVP's byte data to an Integer64. # # @param [Fixnum] value # @return [void] def int64=(value) @content = [value].pack('q>') end # Returns this AVP's byte data, interpreted as an Unsigned32. # # @return [Fixnum] The contained Unsigned32. def uint32 @content.unpack('N')[0] end # Sets this AVP's byte data to an Unsigned32. # # @param [Fixnum] value # @return [void] def uint32=(value) @content = [value].pack('N') end # Returns this AVP's byte data, interpreted as an Unsigned64. # # @return [Fixnum] The contained Unsigned64. def uint64 @content.unpack('Q>')[0] end # Sets this AVP's byte data to an Unsigned64. # # @param [Fixnum] value # @return [void] def uint64=(value) @content = [value].pack('Q>') end # Returns this AVP's byte data, interpreted as a Float32. # # @return [Float] The contained Float32. def float32 @content.unpack('g')[0] end # Sets this AVP's byte data to a Float32. # # @param [Float] value # @return [void] def float32=(value) @content = [value].pack('g') end # Returns this AVP's byte data, interpreted as a Float64. # # @return [Float] The contained Float64. def float64 @content.unpack('G')[0] end # Sets this AVP's byte data to a Float64. # # @param [Float] value # @return [void] def float64=(value) @content = [value].pack('G') end # Returns this AVP's byte data, interpreted as an {http://tools.ietf.org/html/rfc6733#section-4.3.1 Address}. # # @return [IPAddr] The contained {http://tools.ietf.org/html/rfc6733#section-4.3.1 Address}. def ip_address IPAddr.new_ntoh(@content[2..-1]) end # Sets this AVP's byte data to an Address. # # @param [IPAddr] value # @return [void] def ip_address=(value) bytes = if value.ipv4? [1].pack('n') else [2].pack('n') end bytes += value.hton @content = bytes end # @!endgroup private def self.set_content(avp, type, val) case type when GROUPED avp.grouped_value = val when U32 avp.uint32 = val when OCTETSTRING avp.octet_string = val when IPADDR avp.ip_address = val end end def to_s_first_line "AVP #{@code}, mandatory: #{@mandatory}" end protected def padded_content wire_content = @content while ((wire_content.length % 4) != 0) wire_content += "\x00" end wire_content end end |
- (Boolean) vendor_specific? (readonly)
172 173 174 |
# File 'lib/diameter/avp.rb', line 172 def vendor_specific? false end |
Class Method Details
+ (AVP) create(name, val, options = {})
Creates an AVP by name, and assigns it a value.
103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/diameter/avp.rb', line 103 def self.create(name, val, ={}) code, type, vendor = AVPNames.get(name) avp = if (vendor != 0) VendorSpecificAVP.new(code, vendor, ) else AVP.new(code, ) end set_content(avp, type, val) avp end |
Instance Method Details
- (Float) float32
Returns this AVP's byte data, interpreted as a Float32.
309 310 311 |
# File 'lib/diameter/avp.rb', line 309 def float32 @content.unpack('g')[0] end |
- (void) float32=(value)
This method returns an undefined value.
Sets this AVP's byte data to a Float32.
317 318 319 |
# File 'lib/diameter/avp.rb', line 317 def float32=(value) @content = [value].pack('g') end |
- (Float) float64
Returns this AVP's byte data, interpreted as a Float64.
324 325 326 |
# File 'lib/diameter/avp.rb', line 324 def float64 @content.unpack('G')[0] end |
- (void) float64=(value)
This method returns an undefined value.
Sets this AVP's byte data to a Float64.
332 333 334 |
# File 'lib/diameter/avp.rb', line 332 def float64=(value) @content = [value].pack('G') end |
- (Array<AVP>) grouped_value
Returns this AVP's byte data, interpreted as a Grouped AVP.
181 182 183 |
# File 'lib/diameter/avp.rb', line 181 def grouped_value AVPParser::parse_avps_int(@content) end |
- (void) grouped_value=(avps)
This method returns an undefined value.
Sets this AVP's byte data to a Grouped AVP.
190 191 192 193 194 |
# File 'lib/diameter/avp.rb', line 190 def grouped_value=(avps) new_content = '' avps.each { |a| new_content += a.to_wire } @content = new_content end |
- (AVP?) inner_avp(name)
For a grouped AVP, returns the first AVP with this name it contains.
202 203 204 205 206 207 208 209 210 |
# File 'lib/diameter/avp.rb', line 202 def inner_avp(name) avps = inner_avps(name) if avps.empty? nil else avps[0] end end |
- (Array<AVP>) inner_avps(name)
For a grouped AVP, returns all AVPs it contains with this name.
216 217 218 219 220 |
# File 'lib/diameter/avp.rb', line 216 def inner_avps(name) code, _type, _vendor = AVPNames.get(name) self.grouped_value.select { |a| a.code == code} end |
- (Fixnum) int32
Returns this AVP's byte data, interpreted as an Integer32.
249 250 251 |
# File 'lib/diameter/avp.rb', line 249 def int32 @content.unpack('l>')[0] end |
- (void) int32=(value)
This method returns an undefined value.
Sets this AVP's byte data to an Integer32.
257 258 259 |
# File 'lib/diameter/avp.rb', line 257 def int32=(value) @content = [value].pack('l>') end |
- (Fixnum) int64
Returns this AVP's byte data, interpreted as an Integer64.
264 265 266 |
# File 'lib/diameter/avp.rb', line 264 def int64 @content.unpack('q>')[0] end |
- (void) int64=(value)
This method returns an undefined value.
Sets this AVP's byte data to an Integer64.
272 273 274 |
# File 'lib/diameter/avp.rb', line 272 def int64=(value) @content = [value].pack('q>') end |
- (IPAddr) ip_address
Returns this AVP's byte data, interpreted as an Address.
339 340 341 |
# File 'lib/diameter/avp.rb', line 339 def ip_address IPAddr.new_ntoh(@content[2..-1]) end |
- (void) ip_address=(value)
This method returns an undefined value.
Sets this AVP's byte data to an Address.
347 348 349 350 351 352 353 354 355 356 |
# File 'lib/diameter/avp.rb', line 347 def ip_address=(value) bytes = if value.ipv4? [1].pack('n') else [2].pack('n') end bytes += value.hton @content = bytes end |
- (String) octet_string
Returns this AVP's byte data, interpreted as an OctetString.
232 233 234 |
# File 'lib/diameter/avp.rb', line 232 def octet_string @content end |
- (void) octet_string=(value)
This method returns an undefined value.
Sets this AVP's byte data to an OctetString.
240 241 242 |
# File 'lib/diameter/avp.rb', line 240 def octet_string=(value) @content = value end |
- (Object) to_s
Returns a string representation of this AVP. Makes a best-effort attempt to guess the type of the content (even for unknown AVPs) and display it sensibly.
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/diameter/avp.rb', line 143 def to_s has_all_ascii_values = @content.bytes.reject { |c| (32 < c && c < 126) }.empty? could_be_32bit_num = (@content.length == 4) could_be_64bit_num = (@content.length == 8) could_be_ip = ((@content.length == 6 && @content[0..1] == "\x00\x01") || (@content.length == 18 && @content[0..1] == "\x00\x02")) maybe_grouped = !(has_all_ascii_values || could_be_64bit_num || could_be_32bit_num || could_be_ip) s = to_s_first_line s += ", content as string: #{@content}" if has_all_ascii_values s += ", content as int32: #{uint32}" if could_be_32bit_num s += ", content as int64: #{uint64}" if could_be_64bit_num s += ", content as ip: #{ip_address}" if could_be_ip s += ", grouped AVP, #{grouped_value.collect(&:to_s)}" if maybe_grouped s end |
- (String) to_wire
Returns this AVP encoded properly as bytes in network byte order, suitable for sending over a TCP or SCTP connection. See http://tools.ietf.org/html/rfc6733#section-4.1 for the format.
122 123 124 125 126 127 |
# File 'lib/diameter/avp.rb', line 122 def to_wire length_8, length_16 = UInt24.to_u8_and_u16(@content.length + 8) avp_flags = @mandatory ? '01000000' : '00000000' header = [@code, avp_flags, length_8, length_16].pack('NB8Cn') header + self.padded_content end |
- (Fixnum) uint32
Returns this AVP's byte data, interpreted as an Unsigned32.
279 280 281 |
# File 'lib/diameter/avp.rb', line 279 def uint32 @content.unpack('N')[0] end |
- (void) uint32=(value)
This method returns an undefined value.
Sets this AVP's byte data to an Unsigned32.
287 288 289 |
# File 'lib/diameter/avp.rb', line 287 def uint32=(value) @content = [value].pack('N') end |
- (Fixnum) uint64
Returns this AVP's byte data, interpreted as an Unsigned64.
294 295 296 |
# File 'lib/diameter/avp.rb', line 294 def uint64 @content.unpack('Q>')[0] end |
- (void) uint64=(value)
This method returns an undefined value.
Sets this AVP's byte data to an Unsigned64.
302 303 304 |
# File 'lib/diameter/avp.rb', line 302 def uint64=(value) @content = [value].pack('Q>') end |