From thrift-commits-return-1167cervantesmichelle@example.net Mon Mar 01 09:46:40 2010 Return-Path: <thrift-commits-return-1167cervantesmichelle@example.net> Delivered-To: cervantesmichelle@example.net Received: (qmail 93003 invoked from network); 1 Mar 2010 09:46:40 -0000 Received: from unknown (HELO mail.apache.org) (83.161.120.155) by 83.161.120.155 with SMTP; 1 Mar 2010 09:46:40 -0000 Received: (qmail 66697 invoked by uid 500); 28 Feb 2010 05:20:00 -0000 Delivered-To: cervantesmichelle@example.net Received: (qmail 66648 invoked by uid 500); 28 Feb 2010 05:19:59 -0000 Mailing-List: contact cervantesmichelle@example.net; run by ezmlm Precedence: bulk List-Help: <mailto:cervantesmichelle@example.net> List-Unsubscribe: <mailto:cervantesmichelle@example.net> List-Post: <mailto:cervantesmichelle@example.net> List-Id: <thrift-commits.incubator.apache.org> Reply-To: cervantesmichelle@example.net Delivered-To: mailing list cervantesmichelle@example.net Received: (qmail 66629 invoked by uid 99); 28 Feb 2010 05:19:59 -0000 Received: from athena.apache.org (HELO athena.apache.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 28 Feb 2010 05:19:59 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [83.161.120.155] (HELO eris.apache.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 28 Feb 2010 05:19:59 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id CF1AB238890A; Sun, 28 Feb 2010 05:19:38 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r917130 - in /incubator/thrift/trunk: compiler/cpp/src/generate/t_java_generator.cc lib/java/src/org/apache/thrift/TUnion.java Date: Sun, 28 Feb 2010 05:19:38 -0000 To: cervantesmichelle@example.net From: cervantesmichelle@example.net X-Mailer: svnmailer-1.0.8 Message-Id: <cervantesmichelle@example.net> Author: bryanduxbury Date: Sun Feb 28 05:19:38 2010 New Revision: 917130 URL: http://svn.apache.org/viewvc?rev=917130&view=rev Log: THRIFT-716. java: Field names can conflict with local variables in code for unions This patch resolves the name clash issue by removing the unnecessary parameters from the generated method and using the protected variables directly instead. Modified: incubator/thrift/trunk/compiler/cpp/src/generate/t_java_generator.cc incubator/thrift/trunk/lib/java/src/org/apache/thrift/TUnion.java Modified: incubator/thrift/trunk/compiler/cpp/src/generate/t_java_generator.cc URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/compiler/cpp/src/generate/t_java_generator.cc?rev=917130&r1=917129&r2=917130&view=diff ============================================================================== --- incubator/thrift/trunk/compiler/cpp/src/generate/t_java_generator.cc (original) +++ incubator/thrift/trunk/compiler/cpp/src/generate/t_java_generator.cc Sun Feb 28 05:19:38 2010 @@ -915,11 +915,11 @@ void t_java_generator888a:dbb7:2d49:b3f6:8605:bf4e:caed:e5a4generate_write_value(ofstream& out, t_struct* tstruct) { indent(out) << "@Override" << endl; - indent(out) << "protected void writeValue(TProtocol oprot, _Fields setField, Object value) throws TException {" << endl; + indent(out) << "protected void writeValue(TProtocol oprot) throws TException {" << endl; indent_up(); - indent(out) << "switch (setField) {" << endl; + indent(out) << "switch (setField_) {" << endl; indent_up(); const vector<t_field*>& members = tstruct->get_members(); @@ -931,14 +931,14 @@ indent(out) << "case " << constant_name(field->get_name()) << ":" << endl; indent_up(); indent(out) << type_name(field->get_type(), true, false) << " " << field->get_name() - << " = (" << type_name(field->get_type(), true, false) << ")getFieldValue();" << endl; + << " = (" << type_name(field->get_type(), true, false) << ")value_;" << endl; generate_serialize_field(out, field, ""); indent(out) << "return;" << endl; indent_down(); } indent(out) << "default:" << endl; - indent(out) << " throw new IllegalStateException(\"Cannot write union with unknown field \" + setField);" << endl; + indent(out) << " throw new IllegalStateException(\"Cannot write union with unknown field \" + setField_);" << endl; indent_down(); indent(out) << "}" << endl; Modified: incubator/thrift/trunk/lib/java/src/org/apache/thrift/TUnion.java URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/java/src/org/apache/thrift/TUnion.java?rev=917130&r1=917129&r2=917130&view=diff ============================================================================== --- incubator/thrift/trunk/lib/java/src/org/apache/thrift/TUnion.java (original) +++ incubator/thrift/trunk/lib/java/src/org/apache/thrift/TUnion.java Sun Feb 28 05:19:38 2010 @@ -163,7 +163,7 @@ } oprot.writeStructBegin(getStructDesc()); oprot.writeFieldBegin(getFieldDesc(setField_)); - writeValue(oprot, setField_, value_); + writeValue(oprot); oprot.writeFieldEnd(); oprot.writeFieldStop(); oprot.writeStructEnd(); @@ -185,7 +185,7 @@ */ protected abstract Object readValue(TProtocol iprot, TField field) throws TException; - protected abstract void writeValue(TProtocol oprot, F setField, Object value) throws TException; + protected abstract void writeValue(TProtocol oprot) throws TException; protected abstract TStruct getStructDesc(); From thrift-commits-return-1168cervantesmichelle@example.net Tue Mar 02 18:34:29 2010 Return-Path: <thrift-commits-return-1168cervantesmichelle@example.net> Delivered-To: cervantesmichelle@example.net Received: (qmail 16268 invoked from network); 2 Mar 2010 18:34:29 -0000 Received: from unknown (HELO mail.apache.org) (83.161.120.155) by 83.161.120.155 with SMTP; 2 Mar 2010 18:34:29 -0000 Received: (qmail 90173 invoked by uid 500); 2 Mar 2010 18:34:25 -0000 Delivered-To: cervantesmichelle@example.net Received: (qmail 90132 invoked by uid 500); 2 Mar 2010 18:34:24 -0000 Mailing-List: contact cervantesmichelle@example.net; run by ezmlm Precedence: bulk List-Help: <mailto:cervantesmichelle@example.net> List-Unsubscribe: <mailto:cervantesmichelle@example.net> List-Post: <mailto:cervantesmichelle@example.net> List-Id: <thrift-commits.incubator.apache.org> Reply-To: cervantesmichelle@example.net Delivered-To: mailing list cervantesmichelle@example.net Received: (qmail 90121 invoked by uid 99); 2 Mar 2010 18:34:24 -0000 Received: from nike.apache.org (HELO nike.apache.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Mar 2010 18:34:24 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [83.161.120.155] (HELO eris.apache.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Mar 2010 18:34:22 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 4E05D23889E5; Tue, 2 Mar 2010 18:34:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r918137 - in /incubator/thrift/trunk/lib/rb: lib/thrift/transport/http_client_transport.rb spec/http_client_spec.rb Date: Tue, 02 Mar 2010 18:34:01 -0000 To: cervantesmichelle@example.net From: cervantesmichelle@example.net X-Mailer: svnmailer-1.0.8 Message-Id: <cervantesmichelle@example.net> X-Virus-Checked: Checked by ClamAV on apache.org Author: bryanduxbury Date: Tue Mar 2 18:34:00 2010 New Revision: 918137 URL: http://svn.apache.org/viewvc?rev=918137&view=rev Log: THRIFT-720. rb: HTTPClientTransport ignores url parameters This patch causes the url parameters to be sent as expected. Patch by Tony Kamenick. Modified: incubator/thrift/trunk/lib/rb/lib/thrift/transport/http_client_transport.rb incubator/thrift/trunk/lib/rb/spec/http_client_spec.rb Modified: incubator/thrift/trunk/lib/rb/lib/thrift/transport/http_client_transport.rb URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/transport/http_client_transport.rb?rev=918137&r1=918136&r2=918137&view=diff ============================================================================== --- incubator/thrift/trunk/lib/rb/lib/thrift/transport/http_client_transport.rb (original) +++ incubator/thrift/trunk/lib/rb/lib/thrift/transport/http_client_transport.rb Tue Mar 2 18:34:00 2010 @@ -37,7 +37,7 @@ http = Net888a:dbb7:2d49:b3f6:8605:bf4e:caed:e5a4HTTP.new @url.host, @url.port http.use_ssl = @url.scheme == "https" headers = { 'Content-Type' => 'application/x-thrift' } - resp, data = http.post(@url.path, @outbuf, headers) + resp, data = http.post(@url.request_uri, @outbuf, headers) @inbuf = StringIO.new data @outbuf = "" end Modified: incubator/thrift/trunk/lib/rb/spec/http_client_spec.rb URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/spec/http_client_spec.rb?rev=918137&r1=918136&r2=918137&view=diff ============================================================================== --- incubator/thrift/trunk/lib/rb/spec/http_client_spec.rb (original) +++ incubator/thrift/trunk/lib/rb/spec/http_client_spec.rb Tue Mar 2 18:34:00 2010 @@ -24,7 +24,7 @@ describe HTTPClientTransport do before(:each) do - @client = HTTPClientTransport.new("http://my.domain.com/path/to/service") + @client = HTTPClientTransport.new("http://my.domain.com/path/to/service?param=value") end it "should always be open" do @@ -39,7 +39,7 @@ Net888a:dbb7:2d49:b3f6:8605:bf4e:caed:e5a4HTTP.should_receive(:new).with("my.domain.com", 80).and_return do mock("Net888a:dbb7:2d49:b3f6:8605:bf4e:caed:e5a4HTTP").tee do |http| http.should_receive(:use_ssl=).with(false) - http.should_receive(:post).with("/path/to/service", "a test frame", {"Content-Type"=>"application/x-thrift"}).and_return([nil, "data"]) + http.should_receive(:post).with("/path/to/service?param=value", "a test frame", {"Content-Type"=>"application/x-thrift"}).and_return([nil, "data"]) end end @client.flush From thrift-commits-return-1169cervantesmichelle@example.net Tue Mar 02 18:40:23 2010 Return-Path: <thrift-commits-return-1169cervantesmichelle@example.net> Delivered-To: cervantesmichelle@example.net Received: (qmail 23995 invoked from network); 2 Mar 2010 18:40:23 -0000 Received: from unknown (HELO mail.apache.org) (83.161.120.155) by 83.161.120.155 with SMTP; 2 Mar 2010 18:40:23 -0000 Received: (qmail 2311 invoked by uid 500); 2 Mar 2010 18:40:18 -0000 Delivered-To: cervantesmichelle@example.net Received: (qmail 2296 invoked by uid 500); 2 Mar 2010 18:40:18 -0000 Mailing-List: contact cervantesmichelle@example.net; run by ezmlm Precedence: bulk List-Help: <mailto:cervantesmichelle@example.net> List-Unsubscribe: <mailto:cervantesmichelle@example.net> List-Post: <mailto:cervantesmichelle@example.net> List-Id: <thrift-commits.incubator.apache.org> Reply-To: cervantesmichelle@example.net Delivered-To: mailing list cervantesmichelle@example.net Received: (qmail 2289 invoked by uid 99); 2 Mar 2010 18:40:18 -0000 Received: from athena.apache.org (HELO athena.apache.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Mar 2010 18:40:18 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [83.161.120.155] (HELO eris.apache.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Mar 2010 18:40:18 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 3220123889B6; Tue, 2 Mar 2010 18:39:58 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r918142 - in /incubator/thrift/trunk/lib/java: build.xml src/org/apache/thrift/transport/TFramedTransport.java test/org/apache/thrift/test/transport/ test/org/apache/thrift/test/transport/TFramedTransportTest.java Date: Tue, 02 Mar 2010 18:39:58 -0000 To: cervantesmichelle@example.net From: cervantesmichelle@example.net X-Mailer: svnmailer-1.0.8 Message-Id: <cervantesmichelle@example.net> Author: bryanduxbury Date: Tue Mar 2 18:39:57 2010 New Revision: 918142 URL: http://svn.apache.org/viewvc?rev=918142&view=rev Log: THRIFT-711. java: TFramedTransport should support direct buffer access This patch adds direct buffer read access to TFramedTransport as well as a simple test for reading, direct buffer reading, and writing. Added: incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/transport/ incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/transport/TFramedTransportTest.java Modified: incubator/thrift/trunk/lib/java/build.xml incubator/thrift/trunk/lib/java/src/org/apache/thrift/transport/TFramedTransport.java Modified: incubator/thrift/trunk/lib/java/build.xml URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/java/build.xml?rev=918142&r1=918141&r2=918142&view=diff ============================================================================== --- incubator/thrift/trunk/lib/java/build.xml (original) +++ incubator/thrift/trunk/lib/java/build.xml Tue Mar 2 18:39:57 2010 @@ -186,6 +186,8 @@ classpathref="test.classpath" failonerror="true" /> <java classname="org.apache.thrift.test.PartialDeserializeTest" classpathref="test.classpath" failonerror="true" /> + <java classname="org.apache.thrift.test.transport.TFramedTransportTest" + classpathref="test.classpath" failonerror="true" /> </target> <target name="testclient" description="Run a test client"> Modified: incubator/thrift/trunk/lib/java/src/org/apache/thrift/transport/TFramedTransport.java URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/java/src/org/apache/thrift/transport/TFramedTransport.java?rev=918142&r1=918141&r2=918142&view=diff ============================================================================== --- incubator/thrift/trunk/lib/java/src/org/apache/thrift/transport/TFramedTransport.java (original) +++ incubator/thrift/trunk/lib/java/src/org/apache/thrift/transport/TFramedTransport.java Tue Mar 2 18:39:57 2010 @@ -19,8 +19,6 @@ package org.apache.thrift.transport; -import java.io.ByteArrayInputStream; - import org.apache.thrift.TByteArrayOutputStream; /** @@ -43,7 +41,7 @@ /** * Buffer for input */ - private ByteArrayInputStream readBuffer_ = null; + private TMemoryInputTransport readBuffer_ = new TMemoryInputTransport(new byte[0]); public static class Factory extends TTransportFactory { public Factory() { @@ -87,8 +85,24 @@ return readBuffer_.read(buf, off, len); } + public byte[] getBuffer() { + return readBuffer_.getBuffer(); + } + + public int getBufferPosition() { + return readBuffer_.getBufferPosition(); + } + + public int getBytesRemainingInBuffer() { + return readBuffer_.getBytesRemainingInBuffer(); + } + + public void consumeBuffer(int len) { + readBuffer_.consumeBuffer(len); + } + + private final byte[] i32rd = new byte[4]; private void readFrame() throws TTransportException { - byte[] i32rd = new byte[4]; transport_.readAll(i32rd, 0, 4); int size = ((i32rd[0] & 0xff) << 24) | @@ -99,10 +113,10 @@ if (size < 0) { throw new TTransportException("Read a negative frame size (" + size + ")!"); } - + byte[] buff = new byte[size]; transport_.readAll(buff, 0, size); - readBuffer_ = new ByteArrayInputStream(buff); + readBuffer_.reset(buff); } public void write(byte[] buf, int off, int len) throws TTransportException { Added: incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/transport/TFramedTransportTest.java URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/transport/TFramedTransportTest.java?rev=918142&view=auto ============================================================================== --- incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/transport/TFramedTransportTest.java (added) +++ incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/transport/TFramedTransportTest.java Tue Mar 2 18:39:57 2010 @@ -0,0 +1,164 @@ +package org.apache.thrift.test.transport; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.util.Arrays; + +import org.apache.thrift.transport.TFramedTransport; +import org.apache.thrift.transport.TIOStreamTransport; +import org.apache.thrift.transport.TMemoryBuffer; +import org.apache.thrift.transport.TTransport; +import org.apache.thrift.transport.TTransportException; + +public class TFramedTransportTest { + public static class WriteCountingTransport extends TTransport { + private int writeCount = 0; + private final TTransport trans; + + public WriteCountingTransport(TTransport underlying) { + trans = underlying; + } + + @Override + public void close() {} + + @Override + public boolean isOpen() {return true;} + + @Override + public void open() throws TTransportException {} + + @Override + public int read(byte[] buf, int off, int len) throws TTransportException { + return 0; + } + + @Override + public void write(byte[] buf, int off, int len) throws TTransportException { + writeCount ++; + trans.write(buf, off, len); + } + } + + public static class ReadCountingTransport extends TTransport { + public int readCount = 0; + private TTransport trans; + + public ReadCountingTransport(TTransport underlying) { + trans = underlying; + } + + @Override + public void close() {} + + @Override + public boolean isOpen() {return true;} + + @Override + public void open() throws TTransportException {} + + @Override + public int read(byte[] buf, int off, int len) throws TTransportException { + readCount++; + return trans.read(buf, off, len); + } + + @Override + public void write(byte[] buf, int off, int len) throws TTransportException {} + } + + public static void main(String[] args) throws TTransportException, IOException { + testWrite(); + testRead(); + testDirectRead(); + } + + private static void testWrite() throws TTransportException, IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + WriteCountingTransport countingTrans = new WriteCountingTransport(new TIOStreamTransport(baos)); + TTransport trans = new TFramedTransport(countingTrans); + + trans.write(byteSequence(0,100)); + failUnless(countingTrans.writeCount == 0); + trans.write(byteSequence(101,200)); + trans.write(byteSequence(201,255)); + failUnless(countingTrans.writeCount == 0); + + trans.flush(); + failUnless(countingTrans.writeCount == 2); + + DataInputStream din = new DataInputStream(new ByteArrayInputStream(baos.toByteArray())); + failUnless(din.readInt() == 256); + + byte[] buf = new byte[256]; + din.read(buf, 0, 256); + failUnless(Arrays.equals(byteSequence(0,255), buf)); + } + + private static void testRead() throws IOException, TTransportException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + dos.writeInt(50); + dos.write(byteSequence(0, 49)); + + TMemoryBuffer membuf = new TMemoryBuffer(0); + membuf.write(baos.toByteArray()); + + ReadCountingTransport countTrans = new ReadCountingTransport(membuf); + TFramedTransport trans = new TFramedTransport(countTrans); + + byte[] readBuf = new byte[10]; + trans.read(readBuf, 0, 10); + failUnless(Arrays.equals(readBuf, byteSequence(0,9))); + + trans.read(readBuf, 0, 10); + failUnless(Arrays.equals(readBuf, byteSequence(10,19))); + + failUnless(countTrans.readCount == 2); + } + + private static void testDirectRead() throws IOException, TTransportException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + dos.writeInt(50); + dos.write(byteSequence(0, 49)); + + TMemoryBuffer membuf = new TMemoryBuffer(0); + membuf.write(baos.toByteArray()); + + ReadCountingTransport countTrans = new ReadCountingTransport(membuf); + TFramedTransport trans = new TFramedTransport(countTrans); + + failUnless(trans.getBytesRemainingInBuffer() == 0); + + byte[] readBuf = new byte[10]; + trans.read(readBuf, 0, 10); + failUnless(Arrays.equals(readBuf, byteSequence(0,9))); + + failUnless(trans.getBytesRemainingInBuffer() == 40); + failUnless(trans.getBufferPosition() == 10); + + trans.consumeBuffer(5); + failUnless(trans.getBytesRemainingInBuffer() == 35); + failUnless(trans.getBufferPosition() == 15); + + failUnless(countTrans.readCount == 2); + } + + private static void failUnless(boolean b) { + if (!b) { + throw new RuntimeException(); + } + } + + private static byte[] byteSequence(int start, int end) { + byte[] result = new byte[end-start+1]; + for (int i = 0; i <= (end-start); i++) { + result[i] = (byte)(start+i); + } + return result; + } +} From thrift-commits-return-1170cervantesmichelle@example.net Tue Mar 02 18:49:29 2010 Return-Path: <thrift-commits-return-1170cervantesmichelle@example.net> Delivered-To: cervantesmichelle@example.net Received: (qmail 26336 invoked from network); 2 Mar 2010 18:49:29 -0000 Received: from unknown (HELO mail.apache.org) (83.161.120.155) by 83.161.120.155 with SMTP; 2 Mar 2010 18:49:29 -0000 Received: (qmail 13624 invoked by uid 500); 2 Mar 2010 18:49:25 -0000 Delivered-To: cervantesmichelle@example.net Received: (qmail 13602 invoked by uid 500); 2 Mar 2010 18:49:25 -0000 Mailing-List: contact cervantesmichelle@example.net; run by ezmlm Precedence: bulk List-Help: <mailto:cervantesmichelle@example.net> List-Unsubscribe: <mailto:cervantesmichelle@example.net> List-Post: <mailto:cervantesmichelle@example.net> List-Id: <thrift-commits.incubator.apache.org> Reply-To: cervantesmichelle@example.net Delivered-To: mailing list cervantesmichelle@example.net Received: (qmail 13595 invoked by uid 99); 2 Mar 2010 18:49:24 -0000 Received: from athena.apache.org (HELO athena.apache.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Mar 2010 18:49:24 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [83.161.120.155] (HELO eris.apache.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Mar 2010 18:49:23 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 2F57823889B6; Tue, 2 Mar 2010 18:49:03 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r918147 - in /incubator/thrift/trunk/lib/java: ./ src/org/apache/thrift/protocol/ test/org/apache/thrift/test/ Date: Tue, 02 Mar 2010 18:49:03 -0000 To: cervantesmichelle@example.net From: cervantesmichelle@example.net X-Mailer: svnmailer-1.0.8 Message-Id: <cervantesmichelle@example.net> Author: bryanduxbury Date: Tue Mar 2 18:49:02 2010 New Revision: 918147 URL: http://svn.apache.org/viewvc?rev=918147&view=rev Log: THRIFT-710. java: TBinaryProtocol should access buffers directly when possible This patch makes TBinaryProtocol use direct buffer access in the relevant methods. Performance testing indicates as much as 2x speed boost, though your mileage may vary. Added: incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/ProtocolTestBase.java incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/TBinaryProtocolTest.java Modified: incubator/thrift/trunk/lib/java/build.xml incubator/thrift/trunk/lib/java/src/org/apache/thrift/protocol/TBinaryProtocol.java incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/SerializationBenchmark.java incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/TCompactProtocolTest.java Modified: incubator/thrift/trunk/lib/java/build.xml URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/java/build.xml?rev=918147&r1=918146&r2=918147&view=diff ============================================================================== --- incubator/thrift/trunk/lib/java/build.xml (original) +++ incubator/thrift/trunk/lib/java/build.xml Tue Mar 2 18:49:02 2010 @@ -168,6 +168,8 @@ classpathref="test.classpath" failonerror="true" /> <java classname="org.apache.thrift.test.TCompactProtocolTest" classpathref="test.classpath" failonerror="true" /> + <java classname="org.apache.thrift.test.TBinaryProtocolTest" + classpathref="test.classpath" failonerror="true" /> <java classname="org.apache.thrift.test.IdentityTest" classpathref="test.classpath" failonerror="true" /> <java classname="org.apache.thrift.test.EqualityTest" Modified: incubator/thrift/trunk/lib/java/src/org/apache/thrift/protocol/TBinaryProtocol.java URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/java/src/org/apache/thrift/protocol/TBinaryProtocol.java?rev=918147&r1=918146&r2=918147&view=diff ============================================================================== --- incubator/thrift/trunk/lib/java/src/org/apache/thrift/protocol/TBinaryProtocol.java (original) +++ incubator/thrift/trunk/lib/java/src/org/apache/thrift/protocol/TBinaryProtocol.java Tue Mar 2 18:49:02 2010 @@ -244,41 +244,75 @@ private byte[] bin = new byte[1]; public byte readByte() throws TException { + if (trans_.getBytesRemainingInBuffer() >= 1) { + byte b = trans_.getBuffer()[trans_.getBufferPosition()]; + trans_.consumeBuffer(1); + return b; + } readAll(bin, 0, 1); return bin[0]; } private byte[] i16rd = new byte[2]; public short readI16() throws TException { - readAll(i16rd, 0, 2); + byte[] buf = i16rd; + int off = 0; + + if (trans_.getBytesRemainingInBuffer() >= 2) { + buf = trans_.getBuffer(); + off = trans_.getBufferPosition(); + trans_.consumeBuffer(2); + } else { + readAll(i16rd, 0, 2); + } + return (short) - (((i16rd[0] & 0xff) << 8) | - ((i16rd[1] & 0xff))); + (((buf[off] & 0xff) << 8) | + ((buf[off+1] & 0xff))); } private byte[] i32rd = new byte[4]; public int readI32() throws TException { - readAll(i32rd, 0, 4); + byte[] buf = i32rd; + int off = 0; + + if (trans_.getBytesRemainingInBuffer() >= 4) { + buf = trans_.getBuffer(); + off = trans_.getBufferPosition(); + trans_.consumeBuffer(4); + } else { + readAll(i32rd, 0, 4); + } return - ((i32rd[0] & 0xff) << 24) | - ((i32rd[1] & 0xff) << 16) | - ((i32rd[2] & 0xff) << 8) | - ((i32rd[3] & 0xff)); + ((buf[off] & 0xff) << 24) | + ((buf[off+1] & 0xff) << 16) | + ((buf[off+2] & 0xff) << 8) | + ((buf[off+3] & 0xff)); } private byte[] i64rd = new byte[8]; public long readI64() throws TException { - readAll(i64rd, 0, 8); + byte[] buf = i64rd; + int off = 0; + + if (trans_.getBytesRemainingInBuffer() >= 8) { + buf = trans_.getBuffer(); + off = trans_.getBufferPosition(); + trans_.consumeBuffer(8); + } else { + readAll(i64rd, 0, 8); + } + return - ((long)(i64rd[0] & 0xff) << 56) | - ((long)(i64rd[1] & 0xff) << 48) | - ((long)(i64rd[2] & 0xff) << 40) | - ((long)(i64rd[3] & 0xff) << 32) | - ((long)(i64rd[4] & 0xff) << 24) | - ((long)(i64rd[5] & 0xff) << 16) | - ((long)(i64rd[6] & 0xff) << 8) | - ((long)(i64rd[7] & 0xff)); + ((long)(buf[off] & 0xff) << 56) | + ((long)(buf[off+1] & 0xff) << 48) | + ((long)(buf[off+2] & 0xff) << 40) | + ((long)(buf[off+3] & 0xff) << 32) | + ((long)(buf[off+4] & 0xff) << 24) | + ((long)(buf[off+5] & 0xff) << 16) | + ((long)(buf[off+6] & 0xff) << 8) | + ((long)(buf[off+7] & 0xff)); } public double readDouble() throws TException { @@ -287,6 +321,17 @@ public String readString() throws TException { int size = readI32(); + + if (trans_.getBytesRemainingInBuffer() >= size) { + try { + String s = new String(trans_.getBuffer(), trans_.getBufferPosition(), size, "UTF-8"); + trans_.consumeBuffer(size); + return s; + } catch (UnsupportedEncodingException e) { + throw new TException("JVM DOES NOT SUPPORT UTF-8"); + } + } + return readStringBody(size); } Added: incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/ProtocolTestBase.java URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/ProtocolTestBase.java?rev=918147&view=auto ============================================================================== --- incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/ProtocolTestBase.java (added) +++ incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/ProtocolTestBase.java Tue Mar 2 18:49:02 2010 @@ -0,0 +1,416 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.thrift.test; + +import java.util.Arrays; +import java.util.List; + +import org.apache.thrift.TBase; +import org.apache.thrift.TDeserializer; +import org.apache.thrift.TException; +import org.apache.thrift.TSerializer; +import org.apache.thrift.protocol.TBinaryProtocol; +import org.apache.thrift.protocol.TField; +import org.apache.thrift.protocol.TMessage; +import org.apache.thrift.protocol.TMessageType; +import org.apache.thrift.protocol.TProtocol; +import org.apache.thrift.protocol.TProtocolFactory; +import org.apache.thrift.protocol.TStruct; +import org.apache.thrift.protocol.TType; +import org.apache.thrift.transport.TMemoryBuffer; + +import thrift.test.CompactProtoTestStruct; +import thrift.test.HolyMoley; +import thrift.test.Nesting; +import thrift.test.OneOfEach; +import thrift.test.Srv; + +public abstract class ProtocolTestBase { + + protected abstract TProtocolFactory getFactory(); + + public void main() throws Exception { + testNakedByte(); + for (int i = 0; i < 128; i++) { + testByteField((byte)i); + testByteField((byte)-i); + } + + for (int s : Arrays.asList(0, 1, 7, 150, 15000, 0x7fff, -1, -7, -150, -15000, -0x7fff)) { + testNakedI16((short)s); + testI16Field((short)s); + } + + for (int i : Arrays.asList(0, 1, 7, 150, 15000, 31337, 0xffff, 0xffffff, -1, -7, -150, -15000, -0xffff, -0xffffff)) { + testNakedI32(i); + testI32Field(i); + } + + testNakedI64(0); + testI64Field(0); + for (int i = 0; i < 62; i++) { + testNakedI64(1L << i); + testNakedI64(-(1L << i)); + testI64Field(1L << i); + testI64Field(-(1L << i)); + } + + testDouble(); + + for (String s : Arrays.asList("", "short", "borderlinetiny", "a bit longer than the smallest possible")) { + testNakedString(s); + testStringField(s); + } + + for (byte[] b : Arrays.asList(new byte[0], new byte[]{0,1,2,3,4,5,6,7,8,9,10}, new byte[]{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14}, new byte[128])) { + testNakedBinary(b); + testBinaryField(b); + } + + testSerialization(OneOfEach.class, Fixtures.oneOfEach); + testSerialization(Nesting.class, Fixtures.nesting); + testSerialization(HolyMoley.class, Fixtures.holyMoley); + testSerialization(CompactProtoTestStruct.class, Fixtures.compactProtoTestStruct); + + testMessage(); + + testServerRequest(); + + testTDeserializer(); + } + + public void testNakedByte() throws Exception { + TMemoryBuffer buf = new TMemoryBuffer(0); + TProtocol proto = getFactory().getProtocol(buf); + proto.writeByte((byte)123); + byte out = proto.readByte(); + if (out != 123) { + throw new RuntimeException("Byte was supposed to be " + (byte)123 + " but was " + out); + } + } + + public void testByteField(final byte b) throws Exception { + testStructField(new StructFieldTestCase(TType.BYTE, (short)15) { + public void writeMethod(TProtocol proto) throws TException { + proto.writeByte(b); + } + + public void readMethod(TProtocol proto) throws TException { + byte result = proto.readByte(); + if (result != b) { + throw new RuntimeException("Byte was supposed to be " + (byte)b + " but was " + result); + } + } + }); + } + + public void testNakedI16(short n) throws Exception { + TMemoryBuffer buf = new TMemoryBuffer(0); + TProtocol proto = getFactory().getProtocol(buf); + proto.writeI16(n); + // System.out.println(buf.inspect()); + int out = proto.readI16(); + if (out != n) { + throw new RuntimeException("I16 was supposed to be " + n + " but was " + out); + } + } + + public void testI16Field(final short n) throws Exception { + testStructField(new StructFieldTestCase(TType.I16, (short)15) { + public void writeMethod(TProtocol proto) throws TException { + proto.writeI16(n); + } + + public void readMethod(TProtocol proto) throws TException { + short result = proto.readI16(); + if (result != n) { + throw new RuntimeException("I16 was supposed to be " + n + " but was " + result); + } + } + }); + } + + public void testNakedI32(int n) throws Exception { + TMemoryBuffer buf = new TMemoryBuffer(0); + TProtocol proto = getFactory().getProtocol(buf); + proto.writeI32(n); + // System.out.println(buf.inspect()); + int out = proto.readI32(); + if (out != n) { + throw new RuntimeException("I32 was supposed to be " + n + " but was " + out); + } + } + + public void testI32Field(final int n) throws Exception { + testStructField(new StructFieldTestCase(TType.I32, (short)15) { + public void writeMethod(TProtocol proto) throws TException { + proto.writeI32(n); + } + + public void readMethod(TProtocol proto) throws TException { + int result = proto.readI32(); + if (result != n) { + throw new RuntimeException("I32 was supposed to be " + n + " but was " + result); + } + } + }); + } + + public void testNakedI64(long n) throws Exception { + TMemoryBuffer buf = new TMemoryBuffer(0); + TProtocol proto = getFactory().getProtocol(buf); + proto.writeI64(n); + // System.out.println(buf.inspect()); + long out = proto.readI64(); + if (out != n) { + throw new RuntimeException("I64 was supposed to be " + n + " but was " + out); + } + } + + public void testI64Field(final long n) throws Exception { + testStructField(new StructFieldTestCase(TType.I64, (short)15) { + public void writeMethod(TProtocol proto) throws TException { + proto.writeI64(n); + } + + public void readMethod(TProtocol proto) throws TException { + long result = proto.readI64(); + if (result != n) { + throw new RuntimeException("I64 was supposed to be " + n + " but was " + result); + } + } + }); + } + + public void testDouble() throws Exception { + TMemoryBuffer buf = new TMemoryBuffer(1000); + TProtocol proto = getFactory().getProtocol(buf); + proto.writeDouble(123.456); + double out = proto.readDouble(); + if (out != 123.456) { + throw new RuntimeException("Double was supposed to be " + 123.456 + " but was " + out); + } + } + + public void testNakedString(String str) throws Exception { + TMemoryBuffer buf = new TMemoryBuffer(0); + TProtocol proto = getFactory().getProtocol(buf); + proto.writeString(str); + // System.out.println(buf.inspect()); + String out = proto.readString(); + if (!str.equals(out)) { + throw new RuntimeException("String was supposed to be '" + str + "' but was '" + out + "'"); + } + } + + public void testStringField(final String str) throws Exception { + testStructField(new StructFieldTestCase(TType.STRING, (short)15) { + public void writeMethod(TProtocol proto) throws TException { + proto.writeString(str); + } + + public void readMethod(TProtocol proto) throws TException { + String result = proto.readString(); + if (!result.equals(str)) { + throw new RuntimeException("String was supposed to be " + str + " but was " + result); + } + } + }); + } + + public void testNakedBinary(byte[] data) throws Exception { + TMemoryBuffer buf = new TMemoryBuffer(0); + TProtocol proto = getFactory().getProtocol(buf); + proto.writeBinary(data); + // System.out.println(buf.inspect()); + byte[] out = proto.readBinary(); + if (!Arrays.equals(data, out)) { + throw new RuntimeException("Binary was supposed to be '" + data + "' but was '" + out + "'"); + } + } + + public void testBinaryField(final byte[] data) throws Exception { + testStructField(new StructFieldTestCase(TType.STRING, (short)15) { + public void writeMethod(TProtocol proto) throws TException { + proto.writeBinary(data); + } + + public void readMethod(TProtocol proto) throws TException { + byte[] result = proto.readBinary(); + if (!Arrays.equals(data, result)) { + throw new RuntimeException("Binary was supposed to be '" + bytesToString(data) + "' but was '" + bytesToString(result) + "'"); + } + } + }); + + } + + public <T extends TBase> void testSerialization(Class<T> klass, T obj) throws Exception { + TMemoryBuffer buf = new TMemoryBuffer(0); + TBinaryProtocol binproto = new TBinaryProtocol(buf); + + try { + obj.write(binproto); + // System.out.println("Size in binary protocol: " + buf.length()); + + buf = new TMemoryBuffer(0); + TProtocol proto = getFactory().getProtocol(buf); + + obj.write(proto); + System.out.println("Size in " + proto.getClass().getSimpleName() + ": " + buf.length()); + // System.out.println(buf.inspect()); + + T objRead = klass.newInstance(); + objRead.read(proto); + if (!obj.equals(objRead)) { + System.out.println("Expected: " + obj.toString()); + System.out.println("Actual: " + objRead.toString()); + // System.out.println(buf.inspect()); + throw new RuntimeException("Objects didn't match!"); + } + } catch (Exception e) { + System.out.println(buf.inspect()); + throw e; + } + } + + public void testMessage() throws Exception { + List<TMessage> msgs = Arrays.asList(new TMessage[]{ + new TMessage("short message name", TMessageType.CALL, 0), + new TMessage("1", TMessageType.REPLY, 12345), + new TMessage("loooooooooooooooooooooooooooooooooong", TMessageType.EXCEPTION, 1 << 16), + new TMessage("Janky", TMessageType.CALL, 0), + }); + + for (TMessage msg : msgs) { + TMemoryBuffer buf = new TMemoryBuffer(0); + TProtocol proto = getFactory().getProtocol(buf); + TMessage output = null; + + proto.writeMessageBegin(msg); + proto.writeMessageEnd(); + + output = proto.readMessageBegin(); + + if (!msg.equals(output)) { + throw new RuntimeException("Message was supposed to be " + msg + " but was " + output); + } + } + } + + public void testServerRequest() throws Exception { + Srv.Iface handler = new Srv.Iface() { + public int Janky(int i32arg) throws TException { + return i32arg * 2; + } + + public int primitiveMethod() throws TException { + return 0; + } + + public CompactProtoTestStruct structMethod() throws TException { + return null; + } + + public void voidMethod() throws TException { + } + + public void methodWithDefaultArgs(int something) throws TException { + } + }; + + Srv.Processor testProcessor = new Srv.Processor(handler); + + TMemoryBuffer clientOutTrans = new TMemoryBuffer(0); + TProtocol clientOutProto = getFactory().getProtocol(clientOutTrans); + TMemoryBuffer clientInTrans = new TMemoryBuffer(0); + TProtocol clientInProto = getFactory().getProtocol(clientInTrans); + + Srv.Client testClient = new Srv.Client(clientInProto, clientOutProto); + + testClient.send_Janky(1); + // System.out.println(clientOutTrans.inspect()); + testProcessor.process(clientOutProto, clientInProto); + // System.out.println(clientInTrans.inspect()); + int result = testClient.recv_Janky(); + if (result != 2) { + throw new RuntimeException("Got an unexpected result: " + result); + } + } + + private void testTDeserializer() throws TException { + TSerializer ser = new TSerializer(getFactory()); + byte[] bytes = ser.serialize(Fixtures.compactProtoTestStruct); + + TDeserializer deser = new TDeserializer(getFactory()); + CompactProtoTestStruct cpts = new CompactProtoTestStruct(); + deser.deserialize(cpts, bytes); + + if (!Fixtures.compactProtoTestStruct.equals(cpts)) { + throw new RuntimeException(Fixtures.compactProtoTestStruct + " and " + cpts + " do not match!"); + } + } + + // + // Helper methods + // + + private static String bytesToString(byte[] bytes) { + String s = ""; + for (int i = 0; i < bytes.length; i++) { + s += Integer.toHexString((int)bytes[i]) + " "; + } + return s; + } + + private void testStructField(StructFieldTestCase testCase) throws Exception { + TMemoryBuffer buf = new TMemoryBuffer(0); + TProtocol proto = getFactory().getProtocol(buf); + + TField field = new TField("test_field", testCase.type_, testCase.id_); + proto.writeStructBegin(new TStruct("test_struct")); + proto.writeFieldBegin(field); + testCase.writeMethod(proto); + proto.writeFieldEnd(); + proto.writeStructEnd(); + + // System.out.println(buf.inspect()); + + proto.readStructBegin(); + TField readField = proto.readFieldBegin(); + // TODO: verify the field is as expected + if (!field.equals(readField)) { + throw new RuntimeException("Expected " + field + " but got " + readField); + } + testCase.readMethod(proto); + proto.readStructEnd(); + } + + public static abstract class StructFieldTestCase { + byte type_; + short id_; + public StructFieldTestCase(byte type, short id) { + type_ = type; + id_ = id; + } + + public abstract void writeMethod(TProtocol proto) throws TException; + public abstract void readMethod(TProtocol proto) throws TException; + } +} Modified: incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/SerializationBenchmark.java URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/SerializationBenchmark.java?rev=918147&r1=918146&r2=918147&view=diff ============================================================================== --- incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/SerializationBenchmark.java (original) +++ incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/SerializationBenchmark.java Tue Mar 2 18:49:02 2010 @@ -20,13 +20,16 @@ package org.apache.thrift.test; -import java.io.ByteArrayInputStream; +import org.apache.thrift.TBase; +import org.apache.thrift.protocol.TBinaryProtocol; +import org.apache.thrift.protocol.TProtocol; +import org.apache.thrift.protocol.TProtocolFactory; +import org.apache.thrift.transport.TMemoryBuffer; +import org.apache.thrift.transport.TMemoryInputTransport; +import org.apache.thrift.transport.TTransport; +import org.apache.thrift.transport.TTransportException; -import org.apache.thrift.*; -import org.apache.thrift.protocol.*; -import org.apache.thrift.transport.*; - -import thrift.test.*; +import thrift.test.OneOfEach; public class SerializationBenchmark { private final static int HOW_MANY = 10000000; @@ -55,7 +58,7 @@ } long endTime = System.currentTimeMillis(); - System.out.println("Test time: " + (endTime - startTime) + " ms"); + System.out.println("Serialization test time: " + (endTime - startTime) + " ms"); } public static <T extends TBase> void testDeserialization(TProtocolFactory factory, T object, Class<T> klass) throws Exception { @@ -63,14 +66,14 @@ object.write(factory.getProtocol(buf)); byte[] serialized = new byte[100*1024]; buf.read(serialized, 0, 100*1024); - + long startTime = System.currentTimeMillis(); for (int i = 0; i < HOW_MANY; i++) { T o2 = klass.newInstance(); - o2.read(factory.getProtocol(new TIOStreamTransport(new ByteArrayInputStream(serialized)))); + o2.read(factory.getProtocol(new TMemoryInputTransport(serialized))); } long endTime = System.currentTimeMillis(); - - System.out.println("Test time: " + (endTime - startTime) + " ms"); + + System.out.println("Deserialization test time: " + (endTime - startTime) + " ms"); } } \ No newline at end of file Added: incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/TBinaryProtocolTest.java URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/TBinaryProtocolTest.java?rev=918147&view=auto ============================================================================== --- incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/TBinaryProtocolTest.java (added) +++ incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/TBinaryProtocolTest.java Tue Mar 2 18:49:02 2010 @@ -0,0 +1,17 @@ +package org.apache.thrift.test; + +import org.apache.thrift.protocol.TBinaryProtocol; +import org.apache.thrift.protocol.TProtocolFactory; + +public class TBinaryProtocolTest extends ProtocolTestBase { + + public static void main(String[] args) throws Exception { + new TBinaryProtocolTest().main(); + } + + @Override + protected TProtocolFactory getFactory() { + return new TBinaryProtocol.Factory(); + } + +} Modified: incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/TCompactProtocolTest.java URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/TCompactProtocolTest.java?rev=918147&r1=918146&r2=918147&view=diff ============================================================================== --- incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/TCompactProtocolTest.java (original) +++ incubator/thrift/trunk/lib/java/test/org/apache/thrift/test/TCompactProtocolTest.java Tue Mar 2 18:49:02 2010 @@ -20,447 +20,18 @@ package org.apache.thrift.test; -import java.util.Arrays; -import java.util.List; - -import org.apache.thrift.TBase; -import org.apache.thrift.TDeserializer; -import org.apache.thrift.TException; -import org.apache.thrift.TSerializer; -import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.protocol.TCompactProtocol; -import org.apache.thrift.protocol.TField; -import org.apache.thrift.protocol.TMessage; -import org.apache.thrift.protocol.TMessageType; -import org.apache.thrift.protocol.TProtocol; import org.apache.thrift.protocol.TProtocolFactory; -import org.apache.thrift.protocol.TStruct; -import org.apache.thrift.protocol.TType; -import org.apache.thrift.transport.TMemoryBuffer; - -import thrift.test.CompactProtoTestStruct; -import thrift.test.HolyMoley; -import thrift.test.Nesting; -import thrift.test.OneOfEach; -import thrift.test.Srv; - -public class TCompactProtocolTest { - - static TProtocolFactory factory = new TCompactProtocol.Factory(); - - public static void main(String[] args) throws Exception { - testNakedByte(); - for (int i = 0; i < 128; i++) { - testByteField((byte)i); - testByteField((byte)-i); - } - - testNakedI16((short)0); - testNakedI16((short)1); - testNakedI16((short)15000); - testNakedI16((short)0x7fff); - testNakedI16((short)-1); - testNakedI16((short)-15000); - testNakedI16((short)-0x7fff); - - testI16Field((short)0); - testI16Field((short)1); - testI16Field((short)7); - testI16Field((short)150); - testI16Field((short)15000); - testI16Field((short)0x7fff); - testI16Field((short)-1); - testI16Field((short)-7); - testI16Field((short)-150); - testI16Field((short)-15000); - testI16Field((short)-0x7fff); - - testNakedI32(0); - testNakedI32(1); - testNakedI32(15000); - testNakedI32(0xffff); - testNakedI32(-1); - testNakedI32(-15000); - testNakedI32(-0xffff); - - testI32Field(0); - testI32Field(1); - testI32Field(7); - testI32Field(150); - testI32Field(15000); - testI32Field(31337); - testI32Field(0xffff); - testI32Field(0xffffff); - testI32Field(-1); - testI32Field(-7); - testI32Field(-150); - testI32Field(-15000); - testI32Field(-0xffff); - testI32Field(-0xffffff); - - testNakedI64(0); - for (int i = 0; i < 62; i++) { - testNakedI64(1L << i); - testNakedI64(-(1L << i)); - } - - testI64Field(0); - for (int i = 0; i < 62; i++) { - testI64Field(1L << i); - testI64Field(-(1L << i)); - } - - testDouble(); - - testNakedString(""); - testNakedString("short"); - testNakedString("borderlinetiny"); - testNakedString("a bit longer than the smallest possible"); - - testStringField(""); - testStringField("short"); - testStringField("borderlinetiny"); - testStringField("a bit longer than the smallest possible"); - - testNakedBinary(new byte[]{}); - testNakedBinary(new byte[]{0,1,2,3,4,5,6,7,8,9,10}); - testNakedBinary(new byte[]{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14}); - testNakedBinary(new byte[128]); - - testBinaryField(new byte[]{}); - testBinaryField(new byte[]{0,1,2,3,4,5,6,7,8,9,10}); - testBinaryField(new byte[]{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14}); - testBinaryField(new byte[128]); - - testSerialization(OneOfEach.class, Fixtures.oneOfEach); - testSerialization(Nesting.class, Fixtures.nesting); - testSerialization(HolyMoley.class, Fixtures.holyMoley); - testSerialization(CompactProtoTestStruct.class, Fixtures.compactProtoTestStruct); - - testMessage(); - - testServerRequest(); - - testTDeserializer(); - } - - public static void testNakedByte() throws Exception { - TMemoryBuffer buf = new TMemoryBuffer(0); - TProtocol proto = factory.getProtocol(buf); - proto.writeByte((byte)123); - byte out = proto.readByte(); - if (out != 123) { - throw new RuntimeException("Byte was supposed to be " + (byte)123 + " but was " + out); - } - } - - public static void testByteField(final byte b) throws Exception { - testStructField(new StructFieldTestCase(TType.BYTE, (short)15) { - public void writeMethod(TProtocol proto) throws TException { - proto.writeByte(b); - } - - public void readMethod(TProtocol proto) throws TException { - byte result = proto.readByte(); - if (result != b) { - throw new RuntimeException("Byte was supposed to be " + (byte)b + " but was " + result); - } - } - }); - } - public static void testNakedI16(short n) throws Exception { - TMemoryBuffer buf = new TMemoryBuffer(0); - TProtocol proto = factory.getProtocol(buf); - proto.writeI16(n); - // System.out.println(buf.inspect()); - int out = proto.readI16(); - if (out != n) { - throw new RuntimeException("I16 was supposed to be " + n + " but was " + out); - } - } - - public static void testI16Field(final short n) throws Exception { - testStructField(new StructFieldTestCase(TType.I16, (short)15) { - public void writeMethod(TProtocol proto) throws TException { - proto.writeI16(n); - } - - public void readMethod(TProtocol proto) throws TException { - short result = proto.readI16(); - if (result != n) { - throw new RuntimeException("I16 was supposed to be " + n + " but was " + result); - } - } - }); - } - - public static void testNakedI32(int n) throws Exception { - TMemoryBuffer buf = new TMemoryBuffer(0); - TProtocol proto = factory.getProtocol(buf); - proto.writeI32(n); - // System.out.println(buf.inspect()); - int out = proto.readI32(); - if (out != n) { - throw new RuntimeException("I32 was supposed to be " + n + " but was " + out); - } - } - - public static void testI32Field(final int n) throws Exception { - testStructField(new StructFieldTestCase(TType.I32, (short)15) { - public void writeMethod(TProtocol proto) throws TException { - proto.writeI32(n); - } - - public void readMethod(TProtocol proto) throws TException { - int result = proto.readI32(); - if (result != n) { - throw new RuntimeException("I32 was supposed to be " + n + " but was " + result); - } - } - }); - - } - - public static void testNakedI64(long n) throws Exception { - TMemoryBuffer buf = new TMemoryBuffer(0); - TProtocol proto = factory.getProtocol(buf); - proto.writeI64(n); - // System.out.println(buf.inspect()); - long out = proto.readI64(); - if (out != n) { - throw new RuntimeException("I64 was supposed to be " + n + " but was " + out); - } - } - - public static void testI64Field(final long n) throws Exception { - testStructField(new StructFieldTestCase(TType.I64, (short)15) { - public void writeMethod(TProtocol proto) throws TException { - proto.writeI64(n); - } - - public void readMethod(TProtocol proto) throws TException { - long result = proto.readI64(); - if (result != n) { - throw new RuntimeException("I64 was supposed to be " + n + " but was " + result); - } - } - }); - } - - public static void testDouble() throws Exception { - TMemoryBuffer buf = new TMemoryBuffer(1000); - TProtocol proto = factory.getProtocol(buf); - proto.writeDouble(123.456); - double out = proto.readDouble(); - if (out != 123.456) { - throw new RuntimeException("Double was supposed to be " + 123.456 + " but was " + out); - } - } - - public static void testNakedString(String str) throws Exception { - TMemoryBuffer buf = new TMemoryBuffer(0); - TProtocol proto = factory.getProtocol(buf); - proto.writeString(str); - // System.out.println(buf.inspect()); - String out = proto.readString(); - if (!str.equals(out)) { - throw new RuntimeException("String was supposed to be '" + str + "' but was '" + out + "'"); - } - } +public class TCompactProtocolTest extends ProtocolTestBase { - public static void testStringField(final String str) throws Exception { - testStructField(new StructFieldTestCase(TType.STRING, (short)15) { - public void writeMethod(TProtocol proto) throws TException { - proto.writeString(str); - } - - public void readMethod(TProtocol proto) throws TException { - String result = proto.readString(); - if (!result.equals(str)) { - throw new RuntimeException("String was supposed to be " + str + " but was " + result); - } - } - }); - } - - public static void testNakedBinary(byte[] data) throws Exception { - TMemoryBuffer buf = new TMemoryBuffer(0); - TProtocol proto = factory.getProtocol(buf); - proto.writeBinary(data); - // System.out.println(buf.inspect()); - byte[] out = proto.readBinary(); - if (!Arrays.equals(data, out)) { - throw new RuntimeException("Binary was supposed to be '" + data + "' but was '" + out + "'"); - } - } - - public static void testBinaryField(final byte[] data) throws Exception { - testStructField(new StructFieldTestCase(TType.STRING, (short)15) { - public void writeMethod(TProtocol proto) throws TException { - proto.writeBinary(data); - } - - public void readMethod(TProtocol proto) throws TException { - byte[] result = proto.readBinary(); - if (!Arrays.equals(data, result)) { - throw new RuntimeException("Binary was supposed to be '" + bytesToString(data) + "' but was '" + bytesToString(result) + "'"); - } - } - }); - - } - - public static <T extends TBase> void testSerialization(Class<T> klass, T obj) throws Exception { - TMemoryBuffer buf = new TMemoryBuffer(0); - TBinaryProtocol binproto = new TBinaryProtocol(buf); - - try { - obj.write(binproto); - // System.out.println("Size in binary protocol: " + buf.length()); - - buf = new TMemoryBuffer(0); - TProtocol proto = factory.getProtocol(buf); - - obj.write(proto); - System.out.println("Size in compact protocol: " + buf.length()); - // System.out.println(buf.inspect()); - - T objRead = klass.newInstance(); - objRead.read(proto); - if (!obj.equals(objRead)) { - System.out.println("Expected: " + obj.toString()); - System.out.println("Actual: " + objRead.toString()); - // System.out.println(buf.inspect()); - throw new RuntimeException("Objects didn't match!"); - } - } catch (Exception e) { - System.out.println(buf.inspect()); - throw e; - } - } - - public static void testMessage() throws Exception { - List<TMessage> msgs = Arrays.asList(new TMessage[]{ - new TMessage("short message name", TMessageType.CALL, 0), - new TMessage("1", TMessageType.REPLY, 12345), - new TMessage("loooooooooooooooooooooooooooooooooong", TMessageType.EXCEPTION, 1 << 16), - new TMessage("Janky", TMessageType.CALL, 0), - }); - - for (TMessage msg : msgs) { - TMemoryBuffer buf = new TMemoryBuffer(0); - TProtocol proto = factory.getProtocol(buf); - TMessage output = null; - - proto.writeMessageBegin(msg); - proto.writeMessageEnd(); - - output = proto.readMessageBegin(); - - if (!msg.equals(output)) { - throw new RuntimeException("Message was supposed to be " + msg + " but was " + output); - } - } - } - - public static void testServerRequest() throws Exception { - Srv.Iface handler = new Srv.Iface() { - public int Janky(int i32arg) throws TException { - return i32arg * 2; - } - - public int primitiveMethod() throws TException { - return 0; - } - - public CompactProtoTestStruct structMethod() throws TException { - return null; - } - - public void voidMethod() throws TException { - } - - public void methodWithDefaultArgs(int something) throws TException { - } - }; - - Srv.Processor testProcessor = new Srv.Processor(handler); - - TMemoryBuffer clientOutTrans = new TMemoryBuffer(0); - TProtocol clientOutProto = factory.getProtocol(clientOutTrans); - TMemoryBuffer clientInTrans = new TMemoryBuffer(0); - TProtocol clientInProto = factory.getProtocol(clientInTrans); - - Srv.Client testClient = new Srv.Client(clientInProto, clientOutProto); - - testClient.send_Janky(1); - // System.out.println(clientOutTrans.inspect()); - testProcessor.process(clientOutProto, clientInProto); - // System.out.println(clientInTrans.inspect()); - int result = testClient.recv_Janky(); - if (result != 2) { - throw new RuntimeException("Got an unexpected result: " + result); - } - } - - // - // Helper methods - // - - private static String bytesToString(byte[] bytes) { - String s = ""; - for (int i = 0; i < bytes.length; i++) { - s += Integer.toHexString((int)bytes[i]) + " "; - } - return s; + public static void main(String[] args) throws Exception { + new TCompactProtocolTest().main(); } - private static void testStructField(StructFieldTestCase testCase) throws Exception { - TMemoryBuffer buf = new TMemoryBuffer(0); - TProtocol proto = factory.getProtocol(buf); - - TField field = new TField("test_field", testCase.type_, testCase.id_); - proto.writeStructBegin(new TStruct("test_struct")); - proto.writeFieldBegin(field); - testCase.writeMethod(proto); - proto.writeFieldEnd(); - proto.writeStructEnd(); - - // System.out.println(buf.inspect()); - - proto.readStructBegin(); - TField readField = proto.readFieldBegin(); - // TODO: verify the field is as expected - if (!field.equals(readField)) { - throw new RuntimeException("Expected " + field + " but got " + readField); - } - testCase.readMethod(proto); - proto.readStructEnd(); - } - - public static abstract class StructFieldTestCase { - byte type_; - short id_; - public StructFieldTestCase(byte type, short id) { - type_ = type; - id_ = id; - } - - public abstract void writeMethod(TProtocol proto) throws TException; - public abstract void readMethod(TProtocol proto) throws TException; - } - private static void testTDeserializer() throws TException { - TSerializer ser = new TSerializer(new TCompactProtocol.Factory()); - byte[] bytes = ser.serialize(Fixtures.compactProtoTestStruct); - - TDeserializer deser = new TDeserializer(new TCompactProtocol.Factory()); - CompactProtoTestStruct cpts = new CompactProtoTestStruct(); - deser.deserialize(cpts, bytes); - - if (!Fixtures.compactProtoTestStruct.equals(cpts)) { - throw new RuntimeException(Fixtures.compactProtoTestStruct + " and " + cpts + " do not match!"); - } + @Override + protected TProtocolFactory getFactory() { + return new TCompactProtocol.Factory(); } } \ No newline at end of file From thrift-commits-return-1171cervantesmichelle@example.net Fri Mar 05 07:52:29 2010 Return-Path: <thrift-commits-return-1171cervantesmichelle@example.net> Delivered-To: cervantesmichelle@example.net Received: (qmail 59658 invoked from network); 5 Mar 2010 07:52:29 -0000 Received: from unknown (HELO mail.apache.org) (83.161.120.155) by 83.161.120.155 with SMTP; 5 Mar 2010 07:52:29 -0000 Received: (qmail 10347 invoked by uid 500); 5 Mar 2010 07:52:16 -0000 Delivered-To: cervantesmichelle@example.net Received: (qmail 10292 invoked by uid 500); 5 Mar 2010 07:52:14 -0000 Mailing-List: contact cervantesmichelle@example.net; run by ezmlm Precedence: bulk List-Help: <mailto:cervantesmichelle@example.net> List-Unsubscribe: <mailto:cervantesmichelle@example.net> List-Post: <mailto:cervantesmichelle@example.net> List-Id: <thrift-commits.incubator.apache.org> Reply-To: cervantesmichelle@example.net Delivered-To: mailing list cervantesmichelle@example.net Received: (qmail 10285 invoked by uid 99); 5 Mar 2010 07:52:13 -0000 Received: from athena.apache.org (HELO athena.apache.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 05 Mar 2010 07:52:13 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [83.161.120.155] (HELO eris.apache.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 05 Mar 2010 07:52:12 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 2DB7F238890A; Fri, 5 Mar 2010 07:51:52 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r919325 - in /incubator/thrift/trunk: compiler/cpp/src/parse/t_field.h compiler/cpp/src/thrifty.yy test/AnnotationTest.thrift Date: Fri, 05 Mar 2010 07:51:52 -0000 To: cervantesmichelle@example.net From: cervantesmichelle@example.net X-Mailer: svnmailer-1.0.8 Message-Id: <cervantesmichelle@example.net> Author: dreiss Date: Fri Mar 5 07:51:51 2010 New Revision: 919325 URL: http://svn.apache.org/viewvc?rev=919325&view=rev Log: THRIFT-564. Support arbitrary annotations on struct fields This is subtly different from a type annotation, since some bits of metadata only make sense in the context of a single structure field, like whether the field is required, or whether the C++ code should use a pointer for it. This change doesn't define any meaningful annotations. It just sets up the parsing infrastructure. I have no idea if $10 will work with older versions of yacc. It seems to work fine with bison. Modified: incubator/thrift/trunk/compiler/cpp/src/parse/t_field.h incubator/thrift/trunk/compiler/cpp/src/thrifty.yy incubator/thrift/trunk/test/AnnotationTest.thrift Modified: incubator/thrift/trunk/compiler/cpp/src/parse/t_field.h URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/compiler/cpp/src/parse/t_field.h?rev=919325&r1=919324&r2=919325&view=diff ============================================================================== --- incubator/thrift/trunk/compiler/cpp/src/parse/t_field.h (original) +++ incubator/thrift/trunk/compiler/cpp/src/parse/t_field.h Fri Mar 5 07:51:51 2010 @@ -133,6 +133,7 @@ } }; + st888a:dbb7:2d49:b3f6:8605:bf4e:caed:e5a4map<st888a:dbb7:2d49:b3f6:8605:bf4e:caed:e5a4string, st888a:dbb7:2d49:b3f6:8605:bf4e:caed:e5a4string> annotations_; private: t_type* type_; Modified: incubator/thrift/trunk/compiler/cpp/src/thrifty.yy URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/compiler/cpp/src/thrifty.yy?rev=919325&r1=919324&r2=919325&view=diff ============================================================================== --- incubator/thrift/trunk/compiler/cpp/src/thrifty.yy (original) +++ incubator/thrift/trunk/compiler/cpp/src/thrifty.yy Fri Mar 5 07:51:51 2010 @@ -853,7 +853,7 @@ } Field: - CaptureDocText FieldIdentifier FieldRequiredness FieldType tok_identifier FieldValue XsdOptional XsdNillable XsdAttributes CommaOrSemicolonOptional + CaptureDocText FieldIdentifier FieldRequiredness FieldType tok_identifier FieldValue XsdOptional XsdNillable XsdAttributes TypeAnnotations CommaOrSemicolonOptional { pdebug("tok_int_constant : Field -> FieldType tok_identifier"); if ($2 < 0) { @@ -878,6 +878,10 @@ if ($9 != NULL) { $$->set_xsd_attrs($9); } + if ($10 != NULL) { + $$->annotations_ = $10->annotations_; + delete $10; + } } FieldIdentifier: Modified: incubator/thrift/trunk/test/AnnotationTest.thrift URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/test/AnnotationTest.thrift?rev=919325&r1=919324&r2=919325&view=diff ============================================================================== --- incubator/thrift/trunk/test/AnnotationTest.thrift (original) +++ incubator/thrift/trunk/test/AnnotationTest.thrift Fri Mar 5 07:51:51 2010 @@ -20,8 +20,8 @@ typedef list<i32> ( cpp.template = "st888a:dbb7:2d49:b3f6:8605:bf4e:caed:e5a4list" ) int_linked_list struct foo { - 1: i32 bar; - 2: i32 baz; + 1: i32 bar ( presence = "required" ); + 2: i32 baz ( presence = "manual", cpp.use_pointer = "", ); 3: i32 qux; 4: i32 bop; } ( From thrift-commits-return-1172cervantesmichelle@example.net Tue Mar 09 00:50:04 2010 Return-Path: <thrift-commits-return-1172cervantesmichelle@example.net> Delivered-To: cervantesmichelle@example.net Received: (qmail 37532 invoked from network); 9 Mar 2010 00:50:04 -0000 Received: from unknown (HELO mail.apache.org) (83.161.120.155) by 83.161.120.155 with SMTP; 9 Mar 2010 00:50:04 -0000 Received: (qmail 4264 invoked by uid 500); 9 Mar 2010 00:49:36 -0000 Delivered-To: cervantesmichelle@example.net Received: (qmail 3761 invoked by uid 500); 9 Mar 2010 00:49:36 -0000 Mailing-List: contact cervantesmichelle@example.net; run by ezmlm Precedence: bulk List-Help: <mailto:cervantesmichelle@example.net> List-Unsubscribe: <mailto:cervantesmichelle@example.net> List-Post: <mailto:cervantesmichelle@example.net> List-Id: <thrift-commits.incubator.apache.org> Reply-To: cervantesmichelle@example.net Delivered-To: mailing list cervantesmichelle@example.net Received: (qmail 3510 invoked by uid 99); 9 Mar 2010 00:49:36 -0000 Received: from athena.apache.org (HELO athena.apache.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Mar 2010 00:49:35 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [83.161.120.155] (HELO eris.apache.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Mar 2010 00:49:35 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id B19EA23888CE; Tue, 9 Mar 2010 00:49:14 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r920597 - /incubator/thrift/trunk/lib/cpp/src/protocol/TCompactProtocol.h Date: Tue, 09 Mar 2010 00:49:14 -0000 To: cervantesmichelle@example.net From: cervantesmichelle@example.net X-Mailer: svnmailer-1.0.8 Message-Id: <cervantesmichelle@example.net> Author: dreiss Date: Tue Mar 9 00:49:14 2010 New Revision: 920597 URL: http://svn.apache.org/viewvc?rev=920597&view=rev Log: THRIFT-706. cpp: Fix memory leak of string_buf_ in TCompactProtocol Modified: incubator/thrift/trunk/lib/cpp/src/protocol/TCompactProtocol.h Modified: incubator/thrift/trunk/lib/cpp/src/protocol/TCompactProtocol.h URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/cpp/src/protocol/TCompactProtocol.h?rev=920597&r1=920596&r2=920597&view=diff ============================================================================== --- incubator/thrift/trunk/lib/cpp/src/protocol/TCompactProtocol.h (original) +++ incubator/thrift/trunk/lib/cpp/src/protocol/TCompactProtocol.h Tue Mar 9 00:49:14 2010 @@ -109,6 +109,9 @@ boolValue_.hasBoolValue = false; } + ~TCompactProtocol() { + free(string_buf_); + } /** From thrift-commits-return-1173cervantesmichelle@example.net Tue Mar 09 05:15:24 2010 Return-Path: <thrift-commits-return-1173cervantesmichelle@example.net> Delivered-To: cervantesmichelle@example.net Received: (qmail 91360 invoked from network); 9 Mar 2010 05:15:24 -0000 Received: from unknown (HELO mail.apache.org) (83.161.120.155) by 83.161.120.155 with SMTP; 9 Mar 2010 05:15:24 -0000 Received: (qmail 54218 invoked by uid 500); 9 Mar 2010 05:14:58 -0000 Delivered-To: cervantesmichelle@example.net Received: (qmail 54154 invoked by uid 500); 9 Mar 2010 05:14:56 -0000 Mailing-List: contact cervantesmichelle@example.net; run by ezmlm Precedence: bulk List-Help: <mailto:cervantesmichelle@example.net> List-Unsubscribe: <mailto:cervantesmichelle@example.net> List-Post: <mailto:cervantesmichelle@example.net> List-Id: <thrift-commits.incubator.apache.org> Reply-To: cervantesmichelle@example.net Delivered-To: mailing list cervantesmichelle@example.net Received: (qmail 54147 invoked by uid 99); 9 Mar 2010 05:14:55 -0000 Received: from athena.apache.org (HELO athena.apache.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Mar 2010 05:14:55 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [83.161.120.155] (HELO eris.apache.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Mar 2010 05:14:54 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id E38DD23888CE; Tue, 9 Mar 2010 05:14:34 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r920656 - /incubator/thrift/trunk/lib/java/src/org/apache/thrift/TDeserializer.java Date: Tue, 09 Mar 2010 05:14:34 -0000 To: cervantesmichelle@example.net From: cervantesmichelle@example.net X-Mailer: svnmailer-1.0.8 Message-Id: <cervantesmichelle@example.net> Author: bryanduxbury Date: Tue Mar 9 05:14:34 2010 New Revision: 920656 URL: http://svn.apache.org/viewvc?rev=920656&view=rev Log: THRIFT-656. java: TDeserializer.toString is misnamed Modified: incubator/thrift/trunk/lib/java/src/org/apache/thrift/TDeserializer.java Modified: incubator/thrift/trunk/lib/java/src/org/apache/thrift/TDeserializer.java URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/java/src/org/apache/thrift/TDeserializer.java?rev=920656&r1=920655&r2=920656&view=diff ============================================================================== --- incubator/thrift/trunk/lib/java/src/org/apache/thrift/TDeserializer.java (original) +++ incubator/thrift/trunk/lib/java/src/org/apache/thrift/TDeserializer.java Tue Mar 9 05:14:34 2010 @@ -141,7 +141,7 @@ public class TDeserializer { * @param base The object to read into * @param data The string to read from */ - public void toString(TBase base, String data) throws TException { + public void fromString(TBase base, String data) throws TException { deserialize(base, data.getBytes()); } } From thrift-commits-return-1175cervantesmichelle@example.net Tue Mar 09 05:20:00 2010 Return-Path: <thrift-commits-return-1175cervantesmichelle@example.net> Delivered-To: cervantesmichelle@example.net Received: (qmail 92704 invoked from network); 9 Mar 2010 05:20:00 -0000 Received: from unknown (HELO mail.apache.org) (83.161.120.155) by 83.161.120.155 with SMTP; 9 Mar 2010 05:20:00 -0000 Received: (qmail 58163 invoked by uid 500); 9 Mar 2010 05:19:35 -0000 Delivered-To: cervantesmichelle@example.net Received: (qmail 58092 invoked by uid 500); 9 Mar 2010 05:19:35 -0000 Mailing-List: contact cervantesmichelle@example.net; run by ezmlm Precedence: bulk List-Help: <mailto:cervantesmichelle@example.net> List-Unsubscribe: <mailto:cervantesmichelle@example.net> List-Post: <mailto:cervantesmichelle@example.net> List-Id: <thrift-commits.incubator.apache.org> Reply-To: cervantesmichelle@example.net Delivered-To: mailing list cervantesmichelle@example.net Received: (qmail 58084 invoked by uid 99); 9 Mar 2010 05:19:34 -0000 Received: from nike.apache.org (HELO nike.apache.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Mar 2010 05:19:34 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [83.161.120.155] (HELO eris.apache.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Mar 2010 05:19:32 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id AEC1B23889E7; Tue, 9 Mar 2010 05:19:11 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r920658 - /incubator/thrift/trunk/lib/java/src/org/apache/thrift/protocol/TBinaryProtocol.java Date: Tue, 09 Mar 2010 05:19:11 -0000 To: cervantesmichelle@example.net From: cervantesmichelle@example.net X-Mailer: svnmailer-1.0.8 Message-Id: <cervantesmichelle@example.net> X-Virus-Checked: Checked by ClamAV on apache.org Author: dreiss Date: Tue Mar 9 05:19:11 2010 New Revision: 920658 URL: http://svn.apache.org/viewvc?rev=920658&view=rev Log: THRIFT-657. java: Detect negative length in TBinaryProtocol Modified: incubator/thrift/trunk/lib/java/src/org/apache/thrift/protocol/TBinaryProtocol.java Modified: incubator/thrift/trunk/lib/java/src/org/apache/thrift/protocol/TBinaryProtocol.java URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/java/src/org/apache/thrift/protocol/TBinaryProtocol.java?rev=920658&r1=920657&r2=920658&view=diff ============================================================================== --- incubator/thrift/trunk/lib/java/src/org/apache/thrift/protocol/TBinaryProtocol.java (original) +++ incubator/thrift/trunk/lib/java/src/org/apache/thrift/protocol/TBinaryProtocol.java Tue Mar 9 05:19:11 2010 @@ -365,6 +365,9 @@ public class TBinaryProtocol extends TPr } protected void checkReadLength(int length) throws TException { + if (length < 0) { + throw new TException("Negative length: " + length); + } if (checkReadLength_) { readLength_ -= length; if (readLength_ < 0) { From thrift-commits-return-1174cervantesmichelle@example.net Tue Mar 09 05:20:01 2010 Return-Path: <thrift-commits-return-1174cervantesmichelle@example.net> Delivered-To: cervantesmichelle@example.net Received: (qmail 92705 invoked from network); 9 Mar 2010 05:20:00 -0000 Received: from unknown (HELO mail.apache.org) (83.161.120.155) by 83.161.120.155 with SMTP; 9 Mar 2010 05:20:00 -0000 Received: (qmail 58147 invoked by uid 500); 9 Mar 2010 05:19:35 -0000 Delivered-To: cervantesmichelle@example.net Received: (qmail 58082 invoked by uid 500); 9 Mar 2010 05:19:33 -0000 Mailing-List: contact cervantesmichelle@example.net; run by ezmlm Precedence: bulk List-Help: <mailto:cervantesmichelle@example.net> List-Unsubscribe: <mailto:cervantesmichelle@example.net> List-Post: <mailto:cervantesmichelle@example.net> List-Id: <thrift-commits.incubator.apache.org> Reply-To: cervantesmichelle@example.net Delivered-To: mailing list cervantesmichelle@example.net Received: (qmail 58073 invoked by uid 99); 9 Mar 2010 05:19:32 -0000 Received: from nike.apache.org (HELO nike.apache.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Mar 2010 05:19:32 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [83.161.120.155] (HELO eris.apache.org) (83.161.120.155) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Mar 2010 05:19:30 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 2FE5423888CE; Tue, 9 Mar 2010 05:19:09 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r920657 - /incubator/thrift/trunk/compiler/cpp/src/thrifty.yy Date: Tue, 09 Mar 2010 05:19:09 -0000 To: cervantesmichelle@example.net From: cervantesmichelle@example.net X-Mailer: svnmailer-1.0.8 Message-Id: <cervantesmichelle@example.net> X-Virus-Checked: Checked by ClamAV on apache.org Author: dreiss Date: Tue Mar 9 05:19:08 2010 New Revision: 920657 URL: http://svn.apache.org/viewvc?rev=920657&view=rev Log: THRIFT-655. Allow structs to be typedef'ed Modified: incubator/thrift/trunk/compiler/cpp/src/thrifty.yy Modified: incubator/thrift/trunk/compiler/cpp/src/thrifty.yy URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/compiler/cpp/src/thrifty.yy?rev=920657&r1=920656&r2=920657&view=diff ============================================================================== --- incubator/thrift/trunk/compiler/cpp/src/thrifty.yy (original) +++ incubator/thrift/trunk/compiler/cpp/src/thrifty.yy Tue Mar 9 05:19:08 2010 @@ -168,7 +168,6 @@ const int struct_is_union = 1; %type<ttype> TypeDefinition %type<ttypedef> Typedef -%type<ttype> DefinitionType %type<ttype> TypeAnnotations %type<ttype> TypeAnnotationList @@ -483,9 +482,9 @@ TypeDefinition: } Typedef: - tok_typedef DefinitionType tok_identifier + tok_typedef FieldType tok_identifier { - pdebug("TypeDef -> tok_typedef DefinitionType tok_identifier"); + pdebug("TypeDef -> tok_typedef FieldType tok_identifier"); t_typedef *td = new t_typedef(g_program, $2, $3); $$ = td; } @@ -933,18 +932,6 @@ FieldValue: $$ = NULL; } -DefinitionType: - BaseType - { - pdebug("DefinitionType -> BaseType"); - $$ = $1; - } -| ContainerType - { - pdebug("DefinitionType -> ContainerType"); - $$ = $1; - } - FunctionType: FieldType { From thrift-commits-return-1176cervantesmichelle@example.net Tue Mar 09 05:20:03 2010 Return-Path: <thrift-commits-return-1176cervantesmichelle@example.net> Delivered-To: cervantesmichelle@example.net Received: (qmail 92721 invoked from network); 9 Mar 2010 05:20:03 -0000 Received: from unknown (HELO mail.apache.org) (83.161.120.155) by 83.161.120.155 with SMTP; 9 Mar
{'source': 'Apache Software Foundation Public Mail Archives'}