Class: FFI::WIN32::GUID

Inherits:
Struct
  • Object
show all
Defined in:
lib/puppet/ffi/windows/api_types.rb

Overview

msdn.microsoft.com/en-us/library/windows/desktop/aa373931(v=vs.85).aspx typedef struct _GUID

DWORD Data1;
WORD  Data2;
WORD  Data3;
BYTE  Data4[8];

GUID;

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.[](s) ⇒ Object



232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/puppet/ffi/windows/api_types.rb', line 232

def self.[](s)
  raise _('Bad GUID format.') unless s =~ /^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$/i

  new.tap do |guid|
    guid[:Data1] = s[0, 8].to_i(16)
    guid[:Data2] = s[9, 4].to_i(16)
    guid[:Data3] = s[14, 4].to_i(16)
    guid[:Data4][0] = s[19, 2].to_i(16)
    guid[:Data4][1] = s[21, 2].to_i(16)
    s[24, 12].split('').each_slice(2).with_index do |a, i|
      guid[:Data4][i + 2] = a.join('').to_i(16)
    end
  end
end

Instance Method Details

#==(other) ⇒ Object



247
# File 'lib/puppet/ffi/windows/api_types.rb', line 247

def ==(other) Windows.memcmp(other, self, size) == 0 end