From 0d45617ec2be9376bb83381d69cc09a49bb1d975 Mon Sep 17 00:00:00 2001 From: Kevin Clark Date: Wed, 18 Jun 2008 00:59:37 +0000 Subject: [PATCH] Finish up the CamelCase -> ruby_style changes git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@668921 13f79535-47bb-0310-9956-ffa450edef68 --- lib/rb/lib/thrift/protocol.rb | 3 +- lib/rb/lib/thrift/protocol/binaryprotocol.rb | 74 ++++++++++---------- lib/rb/lib/thrift/server/thttpserver.rb | 2 +- lib/rb/lib/thrift/server/tserver.rb | 12 ++-- lib/rb/lib/thrift/struct.rb | 12 ++-- lib/rb/lib/thrift/transport/thttpclient.rb | 2 +- lib/rb/lib/thrift/transport/tsocket.rb | 6 +- lib/rb/lib/thrift/transport/ttransport.rb | 17 ++--- 8 files changed, 65 insertions(+), 63 deletions(-) diff --git a/lib/rb/lib/thrift/protocol.rb b/lib/rb/lib/thrift/protocol.rb index 553d8d4e..e8a6cb7e 100644 --- a/lib/rb/lib/thrift/protocol.rb +++ b/lib/rb/lib/thrift/protocol.rb @@ -258,5 +258,6 @@ module Thrift end class TProtocolFactory - def getProtocol(trans); nil; end + def get_protocol(trans); nil; end + deprecate! :getProtocol => :get_protocol end diff --git a/lib/rb/lib/thrift/protocol/binaryprotocol.rb b/lib/rb/lib/thrift/protocol/binaryprotocol.rb index 6a69f5e3..682ecbf8 100644 --- a/lib/rb/lib/thrift/protocol/binaryprotocol.rb +++ b/lib/rb/lib/thrift/protocol/binaryprotocol.rb @@ -19,41 +19,41 @@ module Thrift end def write_message_begin(name, type, seqid) - writeI32(VERSION_1 | type) - writeString(name) - writeI32(seqid) + write_i32(VERSION_1 | type) + write_string(name) + write_i32(seqid) end def write_field_begin(name, type, id) - writeByte(type) - writeI16(id) + write_byte(type) + write_i16(id) end def write_field_stop() - writeByte(Thrift::Types::STOP) + write_byte(Thrift::Types::STOP) end def write_map_begin(ktype, vtype, size) - writeByte(ktype) - writeByte(vtype) - writeI32(size) + write_byte(ktype) + write_byte(vtype) + write_i32(size) end def write_list_begin(etype, size) - writeByte(etype) - writeI32(size) + write_byte(etype) + write_i32(size) end def write_set_begin(etype, size) - writeByte(etype) - writeI32(size) + write_byte(etype) + write_i32(size) end def write_bool(bool) if (bool) - writeByte(1) + write_byte(1) else - writeByte(0) + write_byte(0) end end @@ -80,56 +80,56 @@ module Thrift end def write_string(str) - writeI32(str.length) + write_i32(str.length) trans.write(str) end def read_message_begin() - version = readI32() + version = read_i32() if (version & VERSION_MASK != VERSION_1) raise ProtocolException.new(ProtocolException::BAD_VERSION, 'Missing version identifier') end type = version & 0x000000ff - name = readString() - seqid = readI32() + name = read_string() + seqid = read_i32() return name, type, seqid end def read_field_begin() - type = readByte() + type = read_byte() if (type === Types::STOP) return nil, type, 0 end - id = readI16() + id = read_i16() return nil, type, id end def read_map_begin() - ktype = readByte() - vtype = readByte() - size = readI32() + ktype = read_byte() + vtype = read_byte() + size = read_i32() return ktype, vtype, size end def read_list_begin() - etype = readByte() - size = readI32() + etype = read_byte() + size = read_i32() return etype, size end def read_set_begin() - etype = readByte() - size = readI32() + etype = read_byte() + size = read_i32() return etype, size end def read_bool() - byte = readByte() + byte = read_byte() return byte != 0 end def read_byte() - dat = trans.readAll(1) + dat = trans.read_all(1) val = dat[0] if (val > 0x7f) val = 0 - ((val - 1) ^ 0xff) @@ -138,7 +138,7 @@ module Thrift end def read_i16() - dat = trans.readAll(2) + dat = trans.read_all(2) val, = dat.unpack('n') if (val > 0x7fff) val = 0 - ((val - 1) ^ 0xffff) @@ -147,7 +147,7 @@ module Thrift end def read_i32() - dat = trans.readAll(4) + dat = trans.read_all(4) val, = dat.unpack('N') if (val > 0x7fffffff) val = 0 - ((val - 1) ^ 0xffffffff) @@ -156,7 +156,7 @@ module Thrift end def read_i64() - dat = trans.readAll(8) + dat = trans.read_all(8) hi, lo = dat.unpack('N2') if (hi > 0x7fffffff) hi = hi ^ 0xffffffff @@ -168,14 +168,14 @@ module Thrift end def read_double() - dat = trans.readAll(8) + dat = trans.read_all(8) val, = dat.unpack('G') return val end def read_string() - sz = readI32() - dat = trans.readAll(sz) + sz = read_i32() + dat = trans.read_all(sz) return dat end @@ -184,7 +184,7 @@ module Thrift end class TBinaryProtocolFactory < TProtocolFactory - def getProtocol(trans) + def get_protocol(trans) return TBinaryProtocol.new(trans) end end diff --git a/lib/rb/lib/thrift/server/thttpserver.rb b/lib/rb/lib/thrift/server/thttpserver.rb index e7206403..d6e85a16 100644 --- a/lib/rb/lib/thrift/server/thttpserver.rb +++ b/lib/rb/lib/thrift/server/thttpserver.rb @@ -22,7 +22,7 @@ class TSimpleMongrelHTTPServer response.start(200) do |head, out| head["Content-Type"] = "application/x-thrift" transport = TIOStreamTransport.new request.body, out - protocol = @protocol_factory.getProtocol transport + protocol = @protocol_factory.get_protocol transport @processor.process protocol, protocol end end diff --git a/lib/rb/lib/thrift/server/tserver.rb b/lib/rb/lib/thrift/server/tserver.rb index 363055d0..6e3830a2 100644 --- a/lib/rb/lib/thrift/server/tserver.rb +++ b/lib/rb/lib/thrift/server/tserver.rb @@ -36,8 +36,8 @@ class TSimpleServer < TServer @serverTransport.listen() while (true) client = @serverTransport.accept() - trans = @transportFactory.getTransport(client) - prot = @protocolFactory.getProtocol(trans) + trans = @transportFactory.get_transport(client) + prot = @protocolFactory.get_protocol(trans) begin while (true) @processor.process(prot, prot) @@ -66,8 +66,8 @@ class TThreadedServer < TServer @serverTransport.listen() while (true) client = @serverTransport.accept() - trans = @transportFactory.getTransport(client) - prot = @protocolFactory.getProtocol(trans) + trans = @transportFactory.get_transport(client) + prot = @protocolFactory.get_protocol(trans) Thread.new(prot, trans) do |p, t| begin while (true) @@ -113,8 +113,8 @@ class TThreadPoolServer < TServer begin while (true) client = @serverTransport.accept() - trans = @transportFactory.getTransport(client) - prot = @protocolFactory.getProtocol(trans) + trans = @transportFactory.get_transport(client) + prot = @protocolFactory.get_protocol(trans) begin while (true) @processor.process(prot, prot) diff --git a/lib/rb/lib/thrift/struct.rb b/lib/rb/lib/thrift/struct.rb index ee3a3604..393060e9 100644 --- a/lib/rb/lib/thrift/struct.rb +++ b/lib/rb/lib/thrift/struct.rb @@ -61,28 +61,28 @@ module Thrift value = field[:class].new value.read(iprot) elsif field[:type] == Types::MAP - key_type, val_type, size = iprot.readMapBegin + key_type, val_type, size = iprot.read_map_begin value = {} size.times do k = read_field(iprot, field_info(field[:key])) v = read_field(iprot, field_info(field[:value])) value[k] = v end - iprot.readMapEnd + iprot.read_map_end elsif field[:type] == Types::LIST - e_type, size = iprot.readListBegin + e_type, size = iprot.read_list_begin value = Array.new(size) do |n| read_field(iprot, field_info(field[:element])) end - iprot.readListEnd + iprot.read_list_end elsif field[:type] == Types::SET - e_type, size = iprot.readSetBegin + e_type, size = iprot.read_set_begin value = {} size.times do element = read_field(iprot, field_info(field[:element])) value[element] = true end - iprot.readSetEnd + iprot.read_set_end else value = iprot.read_type(field[:type]) end diff --git a/lib/rb/lib/thrift/transport/thttpclient.rb b/lib/rb/lib/thrift/transport/thttpclient.rb index 8eb3fd8e..2fe3c574 100644 --- a/lib/rb/lib/thrift/transport/thttpclient.rb +++ b/lib/rb/lib/thrift/transport/thttpclient.rb @@ -13,7 +13,7 @@ class THttpClient < TTransport @outbuf = "" end - def isOpen; true end + def open?; true end def read(sz); @inbuf.read sz end def write(buf); @outbuf << buf end def flush diff --git a/lib/rb/lib/thrift/transport/tsocket.rb b/lib/rb/lib/thrift/transport/tsocket.rb index 7f4eed4a..e6ce9a97 100644 --- a/lib/rb/lib/thrift/transport/tsocket.rb +++ b/lib/rb/lib/thrift/transport/tsocket.rb @@ -18,7 +18,7 @@ class TSocket < TTransport @handle = nil end - def setHandle(handle) + def set_handle(handle) @handle = handle end @@ -30,7 +30,7 @@ class TSocket < TTransport end end - def isOpen() + def open?() return !@handle.nil? end @@ -75,7 +75,7 @@ class TServerSocket < TServerTransport if (@handle != nil) sock = @handle.accept() trans = TSocket.new() - trans.setHandle(sock) + trans.set_handle(sock) return trans end return nil diff --git a/lib/rb/lib/thrift/transport/ttransport.rb b/lib/rb/lib/thrift/transport/ttransport.rb index 05324233..3d475b92 100644 --- a/lib/rb/lib/thrift/transport/ttransport.rb +++ b/lib/rb/lib/thrift/transport/ttransport.rb @@ -68,9 +68,10 @@ class TServerTransport end class TTransportFactory - def getTransport(trans) + def get_transport(trans) return trans end + deprecate! :getTransport => :get_transport end class TBufferedTransport < TTransport @@ -79,8 +80,8 @@ class TBufferedTransport < TTransport @wbuf = '' end - def isOpen() - return @transport.isOpen() + def open?() + return @transport.open?() end def open() @@ -107,7 +108,7 @@ class TBufferedTransport < TTransport end class TBufferedTransportFactory < TTransportFactory - def getTransport(transport) + def get_transport(transport) return TBufferedTransport.new(transport) end end @@ -194,18 +195,18 @@ class TFramedTransport < TTransport private def read_frame - buf = @transport.readAll(4) + buf = @transport.read_all(4) val = buf.unpack('N') sz = val[0] - @rbuf = @transport.readAll(sz) + @rbuf = @transport.read_all(sz) end end class TFramedTransportFactory < TTransportFactory - def getTransport(transport) + def get_transport(transport) return TFramedTransport.new(transport) end end @@ -282,7 +283,7 @@ class TIOStreamTransport < TTransport @output = output end - def isOpen; true end + def open?; true end def read(sz); @input.read(sz) end def write(buf); @output.write(buf) end end -- 2.17.1