Class: PG::Replication::Buffer
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- PG::Replication::Buffer
- Defined in:
- lib/pg/replication/buffer.rb
Class Method Summary collapse
Instance Method Summary collapse
- #read_bool ⇒ Object
- #read_char ⇒ Object
- #read_cstring ⇒ Object
- #read_int16 ⇒ Object
- #read_int32 ⇒ Object
- #read_int64 ⇒ Object
- #read_int8 ⇒ Object
- #read_timestamp ⇒ Object
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_bool ⇒ Object
17 18 19 |
# File 'lib/pg/replication/buffer.rb', line 17 def read_bool read_int8 == 1 end |
#read_char ⇒ Object
13 14 15 |
# File 'lib/pg/replication/buffer.rb', line 13 def read_char read_int8.chr end |
#read_cstring ⇒ Object
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_int16 ⇒ Object
25 26 27 |
# File 'lib/pg/replication/buffer.rb', line 25 def read_int16 read_bytes(2).unpack("n").first end |
#read_int32 ⇒ Object
29 30 31 |
# File 'lib/pg/replication/buffer.rb', line 29 def read_int32 read_bytes(4).unpack("N").first end |
#read_int64 ⇒ Object
33 34 35 |
# File 'lib/pg/replication/buffer.rb', line 33 def read_int64 read_bytes(8).unpack("Q>").first end |
#read_int8 ⇒ Object
21 22 23 |
# File 'lib/pg/replication/buffer.rb', line 21 def read_int8 readbyte end |
#read_timestamp ⇒ Object
37 38 39 40 |
# File 'lib/pg/replication/buffer.rb', line 37 def 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 |