Class: StringIO

Inherits:
Object
  • Object
show all
Defined in:
lib/rcs-common/utf16le.rb,
lib/rcs-common/serializer.rb

Instance Method Summary collapse

Instance Method Details

#read_ascii_stringObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rcs-common/utf16le.rb', line 27

def read_ascii_string
  # at least the null terminator
  return '' if self.size < 1

  # empty string by default
  str = ''
  # read until the end of buffer or null termination
  until self.tell == self.size do
    t = self.read(1)
    break if t == "\0"
    str << t
  end

  return str
end

#read_dwordObject



8
9
10
# File 'lib/rcs-common/serializer.rb', line 8

def read_dword
  self.read(4).unpack('L').shift
end

#read_utf16le_stringObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rcs-common/utf16le.rb', line 8

def read_utf16le_string
  # at least the null terminator
  return '' if self.size < 2

  # empty string by default
  str = ''
  # read until the end of buffer or null termination
  until self.eof? do
    t = self.read(2)
    break if t == "\0\0"
    str << t
  end

  # misaligned string
  return '' if str.bytesize % 2 != 0

  return str
end