Skip to content

Commit

Permalink
fix scala collection serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
chaokunyang committed Jan 5, 2024
1 parent 708b48c commit d90bec7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ abstract class AbstractScalaCollectionSerializer[A, T <: Iterable[A]](fury: Fury

override def read(buffer: MemoryBuffer): T = {
val collection = newCollection(buffer)
val numElements = getAndClearNumElements()
if (numElements != 0) readElements(fury, buffer, collection, numElements)
onCollectionRead(collection)
}

override def newCollection(buffer: MemoryBuffer): util.Collection[_] = {
numElements = buffer.readPositiveVarInt()
val numElements = buffer.readPositiveVarInt()
setNumElements(numElements)
val factory = fury.readRef(buffer).asInstanceOf[Factory[A, T]]
val builder = factory.newBuilder
builder.sizeHint(numElements)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ abstract class AbstractScalaMapSerializer[K, V, T](fury: Fury, cls: Class[T])

override def read(buffer: MemoryBuffer): T = {
val map = newMap(buffer)
if (this.numElements != 0) readElements(buffer, numElements, map)
val numElements = getAndClearNumElements()
if (numElements != 0) readElements(buffer, numElements, map)
onMapRead(map)
}

override def newMap(buffer: MemoryBuffer): util.Map[_, _] = {
numElements = buffer.readPositiveVarInt()
val numElements = buffer.readPositiveVarInt()
setNumElements(numElements)
val factory = fury.readRef(buffer).asInstanceOf[Factory[(K, V), T]]
val builder = factory.newBuilder
builder.sizeHint(numElements)
Expand Down

0 comments on commit d90bec7

Please sign in to comment.