Class: Asciidoctor::Diagram::BinaryIO

Inherits:
Object
  • Object
show all
Defined in:
lib/asciidoctor-diagram/util/binaryio.rb

Overview

Helper class to read binary values from a String

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ BinaryIO

Returns a new instance of BinaryIO.



6
7
8
9
# File 'lib/asciidoctor-diagram/util/binaryio.rb', line 6

def initialize(string)
  @data = string
  @offset = 0
end

Instance Method Details

#read_string(length, encoding = Encoding::ASCII_8BIT) ⇒ Object



35
36
37
38
39
# File 'lib/asciidoctor-diagram/util/binaryio.rb', line 35

def read_string(length, encoding = Encoding::ASCII_8BIT)
  str = @data[@offset,length]
  @offset += length
  str.force_encoding(encoding)
end

#read_uint16_beObject



11
12
13
14
15
# File 'lib/asciidoctor-diagram/util/binaryio.rb', line 11

def read_uint16_be
  uint16 = @data[@offset,2].unpack('n')[0]
  @offset += 2
  uint16
end

#read_uint16_leObject



17
18
19
20
21
# File 'lib/asciidoctor-diagram/util/binaryio.rb', line 17

def read_uint16_le
  uint16 = @data[@offset,2].unpack('v')[0]
  @offset += 2
  uint16
end

#read_uint32_beObject



23
24
25
26
27
# File 'lib/asciidoctor-diagram/util/binaryio.rb', line 23

def read_uint32_be
  uint32 = @data[@offset,4].unpack('N')[0]
  @offset += 4
  uint32
end

#read_uint32_leObject



29
30
31
32
33
# File 'lib/asciidoctor-diagram/util/binaryio.rb', line 29

def read_uint32_le
  uint32 = @data[@offset,4].unpack('V')[0]
  @offset += 4
  uint32
end

#skip(length) ⇒ Object



41
42
43
# File 'lib/asciidoctor-diagram/util/binaryio.rb', line 41

def skip(length)
  @offset += length
end