Class: PG::Replication::Buffer

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/pg/replication/buffer.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_string(str) ⇒ Object



9
10
11
# File 'lib/pg/replication/buffer.rb', line 9

def self.from_string(str)
  new(StringIO.new(str))
end

Instance Method Details

#read_boolObject



17
18
19
# File 'lib/pg/replication/buffer.rb', line 17

def read_bool
  read_int8 == 1
end

#read_charObject



13
14
15
# File 'lib/pg/replication/buffer.rb', line 13

def read_char
  read_int8.chr
end

#read_cstringObject



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/pg/replication/buffer.rb', line 42

def read_cstring
  str = String.new
  loop do
    case read_char
    in "\0"
      return str
    in chr
      str << chr
    end
  end
end

#read_int16Object



25
26
27
# File 'lib/pg/replication/buffer.rb', line 25

def read_int16
  read_bytes(2).unpack("n").first
end

#read_int32Object



29
30
31
# File 'lib/pg/replication/buffer.rb', line 29

def read_int32
  read_bytes(4).unpack("N").first
end

#read_int64Object



33
34
35
# File 'lib/pg/replication/buffer.rb', line 33

def read_int64
  read_bytes(8).unpack("Q>").first
end

#read_int8Object



21
22
23
# File 'lib/pg/replication/buffer.rb', line 21

def read_int8
  readbyte
end

#read_timestampObject



37
38
39
40
# File 'lib/pg/replication/buffer.rb', line 37

def read_timestamp
  usecs = Time.new(2_000, 1, 1, 0, 0, 0, 0).to_i * 10**6 + read_int64
  Time.at(usecs / 10**6, usecs % 10**6, :microsecond)
end