Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 2 commits
  • 13 files changed
  • 0 commit comments
  • 2 contributors
Commits on Apr 16, 2013
@jjmmcc jjmmcc scrooge: make scrooge-runtime 3 backwards compatible with scrooge-run…
…time 2

Via some method redirection and the introduction of ThriftStructCodec3 which extends ThriftStructCodec, scrooge-runtime 3 should now be drop-in compatible with scrooge-runtime 2 (I actually tested this in the birdcage with the tweetypie project).  That means with this change:
  - scrooge-runtime in the birdcage can be replaced with scrooge-runtime 3
  - all projects in the birdcage that currently use scrooge2 can use scrooge-runtime 3 without any changes (except pom)
  - scrooge 2 and scrooge 3 generated code can coexist in the same project without dependency conflicts
  - conversion from scrooge 2 to 3 can be done more safely on a project by project basis, rather than having to upgrade the entire birdcage

There are still some difficult cases, such as with value-add libraries like gizmoduck-twiggy, but the problem space is now smaller.

RB_ID=139582
b43e7d1
@chunyan chunyan release 3.1.1 2f6f94e
View
12 CHANGELOG
@@ -1,11 +1,21 @@
+3.1.1 - 04/16/2013
+===============================================================================
+* BREAKING CHANGE:
+ We finally made scrooge-runtime to be backward with Scrooge 2. This requires
+ a name change for the ThriftStructCodec. From now on, all objects generated
+ by Scrooge 3 will use ThriftStructCodec3.
+ This will affect you only if your code is using ThriftStructCodec directly,
+ which is not common.
+* add language option tag to scrooge-maven-plugin, thanks to @eirslett
+* some directory reorganization of the demos
+
3.1.0 - 04/11/2013
===============================================================================
* Dependency changes: now on util/finagle 6.3.0
* demo project now shows how to construct finagle server and client using
generated code
* --ostrich flag implies --finagle flag
-
3.0.9 - 03/27/2013
===============================================================================
* Remove "provided" scope of finagle in scrooge-runtime. So it brings Finagle
View
4 demos/scrooge-maven-demo/pom.xml
@@ -65,7 +65,7 @@
<dependency>
<groupId>com.twitter</groupId>
<artifactId>scrooge-runtime</artifactId>
- <version>3.0.9</version>
+ <version>3.1.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
@@ -144,7 +144,7 @@
<plugin>
<groupId>com.twitter</groupId>
<artifactId>scrooge-maven-plugin</artifactId>
- <version>3.1.1-SNAPSHOT</version>
+ <version>3.1.1</version>
<configuration>
<thriftNamespaceMappings>
<thriftNamespaceMapping>
View
2 pom.xml
@@ -4,7 +4,7 @@
<groupId>com.twitter</groupId>
<artifactId>scrooge</artifactId>
<packaging>pom</packaging>
- <version>3.1.1-SNAPSHOT</version>
+ <version>3.1.1</version>
<name>scrooge</name>
<url>http://github.com/twitter/scrooge</url>
<description>A Thrift generator for Scala</description>
View
4 scrooge-generator/pom.xml
@@ -8,7 +8,7 @@
<parent>
<groupId>com.twitter</groupId>
<artifactId>scrooge</artifactId>
- <version>3.1.1-SNAPSHOT</version>
+ <version>3.1.1</version>
</parent>
<properties>
<git.dir>${project.basedir}/../../.git</git.dir>
@@ -25,7 +25,7 @@
<dependency>
<groupId>com.twitter</groupId>
<artifactId>scrooge-runtime</artifactId>
- <version>3.1.1-SNAPSHOT</version>
+ <version>3.1.1</version>
<scope>test</scope>
</dependency>
<!-- library dependencies -->
View
1 scrooge-generator/src/main/resources/javagen/service.java
@@ -3,6 +3,7 @@
import com.twitter.scrooge.Option;
import com.twitter.scrooge.ThriftStruct;
import com.twitter.scrooge.ThriftStructCodec;
+import com.twitter.scrooge.ThriftStructCodec3;
import com.twitter.scrooge.Utilities;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
View
5 scrooge-generator/src/main/resources/javagen/struct.java
@@ -6,6 +6,7 @@
import com.twitter.scrooge.Utilities;
import com.twitter.scrooge.ThriftStruct;
import com.twitter.scrooge.ThriftStructCodec;
+import com.twitter.scrooge.ThriftStructCodec3;
import org.apache.thrift.protocol.*;
import java.nio.ByteBuffer;
import java.net.InetSocketAddress;
@@ -74,7 +75,8 @@ public Builder copy() {
return builder;
}
- public static ThriftStructCodec<{{StructName}}> CODEC = new ThriftStructCodec<{{StructName}}>() {
+ public static ThriftStructCodec<{{StructName}}> CODEC = new ThriftStructCodec3<{{StructName}}>() {
+ @Override
public {{StructName}} decode(TProtocol _iprot) throws org.apache.thrift.TException {
Builder builder = new Builder();
{{#fields}}
@@ -109,6 +111,7 @@ public Builder copy() {
}
}
+ @Override
public void encode({{StructName}} struct, TProtocol oprot) throws org.apache.thrift.TException {
struct.write(oprot);
}
View
3 scrooge-generator/src/main/resources/javagen/union.java
@@ -6,6 +6,7 @@
import com.twitter.scrooge.Utilities;
import com.twitter.scrooge.ThriftStruct;
import com.twitter.scrooge.ThriftStructCodec;
+import com.twitter.scrooge.ThriftStructCodec3;
import org.apache.thrift.protocol.*;
import java.nio.ByteBuffer;
import java.net.InetSocketAddress;
@@ -40,7 +41,7 @@
*/
public final Field setField;
- public static ThriftStructCodec<{{StructName}}> CODEC = new ThriftStructCodec<{{StructName}}>() {
+ public static ThriftStructCodec<{{StructName}}> CODEC = new ThriftStructCodec3<{{StructName}}>() {
public {{StructName}} decode(TProtocol _iprot) throws org.apache.thrift.TException {
{{StructName}} result = null;
_iprot.readStructBegin();
View
2 scrooge-generator/src/main/resources/scalagen/service.scala
@@ -1,6 +1,6 @@
package {{package}}
-import com.twitter.scrooge.{ThriftStruct, ThriftStructCodec}
+import com.twitter.scrooge.{ThriftStruct, ThriftStructCodec, ThriftStructCodec3}
import java.net.InetSocketAddress
import java.nio.ByteBuffer
import org.apache.thrift.protocol._
View
14 scrooge-generator/src/main/resources/scalagen/struct.scala
@@ -1,7 +1,7 @@
{{#public}}
package {{package}}
-import com.twitter.scrooge.{ThriftException, ThriftStruct, ThriftStructCodec}
+import com.twitter.scrooge.{ThriftException, ThriftStruct, ThriftStructCodec3}
import org.apache.thrift.protocol._
import java.nio.ByteBuffer
{{#withFinagleClient}}
@@ -12,7 +12,7 @@ import scala.collection.{Map, Set}
{{/public}}
{{docstring}}
-object {{StructName}} extends ThriftStructCodec[{{StructName}}] {
+object {{StructName}} extends ThriftStructCodec3[{{StructName}}] {
val Struct = new TStruct("{{StructNameForWire}}")
{{#fields}}
val {{fieldConst}} = new TField("{{fieldNameForWire}}", TType.{{constType}}, {{id}})
@@ -31,8 +31,8 @@ object {{StructName}} extends ThriftStructCodec[{{StructName}}] {
{{/fields}}
}
- def encode(_item: {{StructName}}, _oproto: TProtocol) { _item.write(_oproto) }
- def decode(_iprot: TProtocol) = Immutable.decode(_iprot)
+ override def encode(_item: {{StructName}}, _oproto: TProtocol) { _item.write(_oproto) }
+ override def decode(_iprot: TProtocol) = Immutable.decode(_iprot)
def apply(_iprot: TProtocol): {{StructName}} = decode(_iprot)
@@ -56,9 +56,9 @@ object {{StructName}} extends ThriftStructCodec[{{StructName}}] {
def unapply(_item: {{StructName}}): Option[{{product}}] = Some(_item)
{{/arityN}}
- object Immutable extends ThriftStructCodec[{{StructName}}] {
- def encode(_item: {{StructName}}, _oproto: TProtocol) { _item.write(_oproto) }
- def decode(_iprot: TProtocol) = {
+ object Immutable extends ThriftStructCodec3[{{StructName}}] {
+ override def encode(_item: {{StructName}}, _oproto: TProtocol) { _item.write(_oproto) }
+ override def decode(_iprot: TProtocol) = {
{{#fields}}
var {{fieldName}}: {{fieldType}} = {{defaultReadValue}}
var {{gotName}} = false
View
8 scrooge-generator/src/main/resources/scalagen/union.scala
@@ -1,7 +1,7 @@
{{#public}}
package {{package}}
-import com.twitter.scrooge.{ThriftStruct, ThriftStructCodec}
+import com.twitter.scrooge.{ThriftStruct, ThriftStructCodec3}
import org.apache.thrift.protocol._
import java.nio.ByteBuffer
{{#withFinagleClient}}
@@ -16,14 +16,14 @@ sealed trait {{StructName}} extends {{parentType}}
{{docstring}}
@javax.annotation.Generated(value = Array("com.twitter.scrooge.Compiler"), date = "{{date}}")
-object {{StructName}} extends ThriftStructCodec[{{StructName}}] {
+object {{StructName}} extends ThriftStructCodec3[{{StructName}}] {
val Union = new TStruct("{{StructNameForWire}}")
{{#fields}}
val {{fieldConst}} = new TField("{{fieldNameForWire}}", TType.{{constType}}, {{id}})
{{/fields}}
- def encode(_item: {{StructName}}, _oprot: TProtocol) { _item.write(_oprot) }
- def decode(_iprot: TProtocol): {{StructName}} = {
+ override def encode(_item: {{StructName}}, _oprot: TProtocol) { _item.write(_oprot) }
+ override def decode(_iprot: TProtocol): {{StructName}} = {
var _result: {{StructName}} = null
_iprot.readStructBegin()
val _field = _iprot.readFieldBegin()
View
4 scrooge-maven-plugin/pom.xml
@@ -10,7 +10,7 @@
<parent>
<groupId>com.twitter</groupId>
<artifactId>scrooge</artifactId>
- <version>3.1.1-SNAPSHOT</version>
+ <version>3.1.1</version>
</parent>
<build>
<pluginManagement>
@@ -115,7 +115,7 @@
<dependency>
<groupId>com.twitter</groupId>
<artifactId>scrooge-generator</artifactId>
- <version>3.1.1-SNAPSHOT</version>
+ <version>3.1.1</version>
</dependency>
</dependencies>
<reporting>
View
2 scrooge-runtime/pom.xml
@@ -7,7 +7,7 @@
<parent>
<groupId>com.twitter</groupId>
<artifactId>scrooge</artifactId>
- <version>3.1.1-SNAPSHOT</version>
+ <version>3.1.1</version>
</parent>
<properties>
<git.dir>${project.basedir}/../../.git</git.dir>
View
25 scrooge-runtime/src/main/scala/com/twitter/scrooge/ThriftStruct.scala
@@ -7,18 +7,33 @@ trait ThriftStruct {
def write(oprot: TProtocol)
}
-abstract class ThriftStructCodec[T <: ThriftStruct] {
+/**
+ * A trait encapsulating the logic for encoding and decoding a specific thrift struct
+ * type. The methods encoder and decoder are used by scrooge2 generated code, but are
+ * now deprecated. scrooge3 generated code uses encode and decode.
+ */
+trait ThriftStructCodec[T <: ThriftStruct] {
@throws(classOf[org.apache.thrift.TException])
- def encode(t: T, oprot: TProtocol)
+ def encode(t: T, oprot: TProtocol) = encoder(t, oprot)
@throws(classOf[org.apache.thrift.TException])
- def decode(iprot: TProtocol): T
+ def decode(iprot: TProtocol): T = decoder(iprot)
lazy val metaData = new ThriftStructMetaData(this)
@deprecated("your code is generated by an outdated version of scrooge-generator", "2.7.0")
- def encoder: (T, TProtocol) => Unit = encode _
+ def encoder: (T, TProtocol) => Unit
@deprecated("your code is generated by an outdated version of scrooge-generator", "2.7.0")
- def decoder: TProtocol => T = decode _
+ def decoder: TProtocol => T
}
+
+/**
+ * structs generated by scrooge3 will extends this base class, which provides implementations
+ * for the deprecated encoder/decoder methods that depend on encode and decode, which are
+ * generated.
+ */
+abstract class ThriftStructCodec3[T <: ThriftStruct] extends ThriftStructCodec[T] {
+ override val encoder: (T, TProtocol) => Unit = encode _
+ override val decoder: TProtocol => T = decode _
+}

No commit comments for this range

Something went wrong with that request. Please try again.