Skip to content

Commit f341d51

Browse files
author
Sam Ritchie
committed
Merge branch 'release/0.2.2'
2 parents 56acd2c + 841f328 commit f341d51

9 files changed

Lines changed: 65 additions & 19 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
/src/intellij/*.iws
2929
/.cache
3030
/.idea
31+
/.idea_modules
3132
/.settings
3233

3334
# bak files produced by ./cleanup-commit

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# chill #
22

3+
### 0.2.2
4+
5+
* Custom RegexSerializer
6+
* ArrayBuffer serialization fix (#48)
7+
38
### 0.2.1
49
* Improve MeatLocker (safe to call get before serialization)
510
* Fix a bug with serialization of mutable collections

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Chill provides support for singletons, scala Objects and the following types:
4444

4545
## Maven
4646

47-
Current version is `0.2.1 `. groupid=`"com.twitter"` artifact=`"chill_2.9.2"` or artifact=`"chill_2.10"`.
47+
Current version is `0.2.2`. groupid=`"com.twitter"` artifact=`"chill_2.9.2"` or artifact=`"chill_2.10"`.
4848

4949
## Authors
5050

chill-scala/src/main/scala/com/twitter/chill/InjectiveSerializer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class InjectiveSerializer[T] private (injection: Injection[T, Array[Byte]]) exte
2323
def write(kser: Kryo, out: Output, obj: T) {
2424
val bytes = injection(obj)
2525
out.writeInt(bytes.length, true)
26-
out.writeBytes(bytes);
26+
out.writeBytes(bytes)
2727
}
2828

2929
def read(kser: Kryo, in: Input, cls: Class[T]): T = {

chill-scala/src/main/scala/com/twitter/chill/KryoBase.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ package com.twitter.chill
1919
import com.esotericsoftware.kryo.Kryo
2020
import com.esotericsoftware.kryo.KryoException
2121
import com.esotericsoftware.kryo.{ Serializer => KSerializer }
22-
import com.esotericsoftware.reflectasm.ConstructorAccess;
22+
import com.esotericsoftware.reflectasm.ConstructorAccess
2323
import com.esotericsoftware.kryo.serializers.FieldSerializer
2424

25-
import org.objenesis.instantiator.ObjectInstantiator;
26-
import org.objenesis.strategy.InstantiatorStrategy;
25+
import org.objenesis.instantiator.ObjectInstantiator
26+
import org.objenesis.strategy.InstantiatorStrategy
27+
28+
import java.lang.reflect.Constructor
29+
import java.lang.reflect.Modifier
2730

28-
import java.lang.reflect.Constructor;
29-
import java.lang.reflect.Modifier;
3031
/*
3132
* This is the base class of Kryo we use to fix specific scala
3233
* related issues discovered (ideally, this should be fixed in Kryo)
3334
*/
34-
3535
class KryoBase extends Kryo {
3636

3737
lazy val objSer = new ObjectSerializer[AnyRef]

chill-scala/src/main/scala/com/twitter/chill/KryoSerializer.scala

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ import com.esotericsoftware.kryo.Kryo
2020
import com.esotericsoftware.kryo.{ Serializer => KSerializer }
2121
import com.esotericsoftware.kryo.io.{ Input, Output }
2222

23-
import com.twitter.bijection.{ Base64String, Bufferable, ImplicitBijection, Injection }
24-
25-
import org.objenesis.strategy.StdInstantiatorStrategy
23+
import com.twitter.bijection.{ Bufferable, ImplicitBijection }
2624

2725
import scala.collection.immutable.{
2826
BitSet,
@@ -32,14 +30,14 @@ import scala.collection.immutable.{
3230
}
3331

3432
import scala.collection.mutable.{
35-
Builder,
3633
WrappedArray,
3734
Map => MMap,
3835
Set => MSet,
3936
ListBuffer,
4037
Queue => MQueue,
4138
Buffer
4239
}
40+
import scala.util.matching.Regex
4341

4442
object KryoSerializer {
4543

@@ -88,13 +86,17 @@ object KryoSerializer {
8886
* You should go from MOST specific, to least to specific when using
8987
* default serializers. The FIRST one found is the one used
9088
*/
91-
// wrapper array is abstract
92-
newK.forSubclass[WrappedArray[Any]](new WrappedArraySerializer[Any])
89+
newK
90+
.forSubclass[Regex](new RegexSerializer)
91+
// wrapper array is abstract
92+
.forSubclass[WrappedArray[Any]](new WrappedArraySerializer[Any])
9393
.forSubclass[BitSet](new BitSetSerializer)
9494
.forSubclass[java.util.PriorityQueue[AnyRef]](new PriorityQueueSerializer[AnyRef])
9595
.forTraversableSubclass(Queue.newBuilder[Any])
9696
// List is a sealed class, so there are only two subclasses:
9797
.forTraversableSubclass(List.newBuilder[Any])
98+
// add mutable Buffer before Vector, otherwise Vector is used
99+
.forTraversableSubclass(Buffer.newBuilder[Any], isImmutable = false)
98100
//Vector is a final class
99101
.forTraversableClass(Vector.newBuilder[Any])
100102
.forTraversableSubclass(IndexedSeq.newBuilder[Any])
@@ -109,7 +111,6 @@ object KryoSerializer {
109111
.forTraversableSubclass(MMap.newBuilder[Any,Any], isImmutable = false)
110112
.forTraversableSubclass(MSet.newBuilder[Any], isImmutable = false)
111113
.forTraversableSubclass(ListBuffer.newBuilder[Any], isImmutable = false)
112-
.forTraversableSubclass(Buffer.newBuilder[Any], isImmutable = false)
113114
// This should be last, lots of things are seq/iterable/traversable
114115
// These are questionable and might break things.
115116
// rarely will you only expect an iterable/traversable on the reverse
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
Copyright 2012 Twitter, Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package com.twitter.chill
18+
19+
import com.esotericsoftware.kryo.Kryo
20+
import com.esotericsoftware.kryo.{ Serializer => KSerializer }
21+
import com.esotericsoftware.kryo.io.{ Input, Output }
22+
import scala.util.matching.Regex
23+
24+
class RegexSerializer extends KSerializer[Regex] {
25+
def write(kser: Kryo, out: Output, obj: Regex) {
26+
out.writeString(obj.pattern.pattern)
27+
}
28+
29+
def read(kser: Kryo, in: Input, cls: Class[Regex]): Regex = {
30+
new Regex(in.readString)
31+
}
32+
}

chill-scala/src/test/scala/com/twitter/chill/KryoSpec.scala

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import scala.collection.immutable.BitSet
2222
import scala.collection.immutable.ListMap
2323
import scala.collection.immutable.HashMap
2424

25-
import scala.collection.mutable.{HashMap => MHashMap}
25+
import scala.collection.mutable.{ArrayBuffer => MArrayBuffer, HashMap => MHashMap}
2626

2727
import com.twitter.bijection.Bijection
2828

@@ -33,8 +33,8 @@ import com.twitter.bijection.Bijection
3333
*/
3434
case class TestCaseClassForSerialization(x : String, y : Int)
3535

36-
case class TestValMap(val map : Map[String,Double])
37-
case class TestValHashMap(val map : HashMap[String,Double])
36+
case class TestValMap(map: Map[String,Double])
37+
case class TestValHashMap(map: HashMap[String,Double])
3838
case class TestVarArgs(vargs: String*)
3939

4040
object WeekDay extends Enumeration {
@@ -55,6 +55,7 @@ class KryoSpec extends Specification with BaseProperties {
5555
0 to 100,
5656
(0 to 42).toList, Seq(1,100,1000),
5757
Map("good" -> 0.5, "bad" -> -1.0),
58+
MArrayBuffer(1,2,3,4,5),
5859
List(Some(MHashMap(1->1, 2->2)), None, Some(MHashMap(3->4))),
5960
Set(1,2,3,4,10),
6061
BitSet(),
@@ -165,5 +166,11 @@ class KryoSpec extends Specification with BaseProperties {
165166
val ml = MeatLocker(l)
166167
jrt(ml).get must_==(l)
167168
}
169+
"Handle Regex" in {
170+
val test = """\bhilarious""".r
171+
val roundtripped = rt(test)
172+
roundtripped.pattern.pattern must be_==(test.pattern.pattern)
173+
roundtripped.findFirstIn("hilarious").isDefined must beTrue
174+
}
168175
}
169176
}

project/Build.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ object ChillBuild extends Build {
1313
val sharedSettings = Project.defaultSettings ++
1414
mimaDefaultSettings ++ Seq(
1515

16-
version := "0.2.1",
16+
version := "0.2.2",
1717

1818
organization := "com.twitter",
1919

0 commit comments

Comments
 (0)