class PostgresPR::Utils::NativeBuffer
Constants
- NUL
Public Class Methods
of_size(size)
click to toggle source
# File lib/postgres-pr/utils/buffer.rb, line 43 def self.of_size(size) new('#'*size, 'r+') end
Public Instance Methods
copy_from_stream(stream, n)
click to toggle source
# File lib/postgres-pr/utils/buffer.rb, line 76 def copy_from_stream(stream, n) raise ArgumentError if n < 0 while n > 0 str = stream.read(n) write(str) n -= str.size end raise if n < 0 end
read_cstring()
click to toggle source
returns a Ruby string without the trailing NUL
character
# File lib/postgres-pr/utils/buffer.rb, line 94 def read_cstring s = readline(NUL) s.chop! s end
read_int16_network()
click to toggle source
# File lib/postgres-pr/utils/buffer.rb, line 56 def read_int16_network byte1, byte2 = readbyte, readbyte (byte1 < 128 ? byte1 : byte1 - 256) * 256 + byte2 end
read_int32_network()
click to toggle source
# File lib/postgres-pr/utils/buffer.rb, line 60 def read_int32_network byte1, byte2 = readbyte, readbyte byte3, byte4 = readbyte, readbyte ((((byte1 < 128 ? byte1 : byte1 - 256) * 256 + byte2) * 256) + byte3) * 256 + byte4 end
write_byte(byte)
click to toggle source
# File lib/postgres-pr/utils/buffer.rb, line 66 def write_byte(byte) write(byte.chr) end
write_cstring(cstr)
click to toggle source
# File lib/postgres-pr/utils/buffer.rb, line 87 def write_cstring(cstr) raise ArgumentError, "Invalid Ruby/cstring" if cstr.include?(NUL) write(cstr) write(NUL) end
write_int16_network(int16)
click to toggle source
# File lib/postgres-pr/utils/buffer.rb, line 72 def write_int16_network(int16) write([int16].pack('n')) end
write_int32_network(int32)
click to toggle source
# File lib/postgres-pr/utils/buffer.rb, line 69 def write_int32_network(int32) write([int32].pack('N')) end