## Where communities thrive

• Join over 1.5M+ people
• Join over 100K+ communities
• Free without limits
##### Activity
• Oct 15 11:25

mathieuleclaire on master

Update sbt-scalajs, scalajs-com… Merge pull request #141 from sc… (compare)

• Oct 15 11:25
mathieuleclaire closed #141
• Oct 15 11:15
scala-steward opened #141
• Sep 28 18:17
ochrons closed #140
• Sep 28 18:17
ochrons commented #140
• Sep 22 13:24
manosntoulias edited #140
• Sep 22 13:24
manosntoulias opened #140
• Sep 08 23:55
scala-steward opened #139
• Aug 30 06:44
scala-steward opened #138
• Jul 02 02:00
scala-steward opened #137
• Jun 28 01:08
scala-steward opened #136
• Jun 26 01:22
phb opened #135
• Jun 09 00:48
japgolly commented #127
• Jun 08 20:58
scala-steward opened #134
• Jun 08 20:58
scala-steward opened #133
• Jun 08 20:58
scala-steward opened #132
• Jun 08 20:58
scala-steward opened #131
• Jun 08 20:58
scala-steward opened #130
• Jun 08 06:11
ochrons closed #127
• Jun 08 06:11
ochrons commented #127
Nils Kilden-Pedersen
@nilskp
gotcha. Thanks for clarifying.
Otto Chrons
@ochrons
:+1:
moritz bust
@busti

I am trying to pickle a custom collection type using a transformPickler.
The collection is a strictly alternating sequence of two types and is implemented like this: class Alternating[Even, Odd](val first: Even, val rest: Seq[(Odd, Even)])
My Pickling code looks like this:

  implicit def alternatingPickler[Even, Odd] =
transformPickler[Alternating[Even, Odd], (Even, Seq[(Odd, Even)])] {
case (first, rest) => Alternating(first, rest)
} (a => (a.first, a.rest))

I am getting an error message when compiling:

[error] C:\Users\mbust\Documents\projects\delta-t\modules\core\shared\src\main\scala\io\delta_t\collection\serializers\Boopickle.scala:14:7: exception during macro expansion:
[error] java.lang.RuntimeException: Enclosure: source-C:\Users\mbust\Documents\projects\delta-t\modules\core\shared\src\main\scala\io\delta_t\collection\serializers\Boopickle.scala,line-14,offset=432, type = Even
[error]         at boopickle.PicklerMaterializersImpl\$.materializePickler(PicklerMaterializersImpl.scala:106)
[error]     } (a => (a.first, a.rest))
[error]       ^
Does transformPickler support generics? Or is there something else I am doing wrong?
Otto Chrons
@ochrons
you need to provide implicit picklers for Even and Odd
moritz bust
@busti
Like this implicit def alternatingPickler[Even : Pickler, Odd : Pickler]?
Otto Chrons
@ochrons
yea
moritz bust
@busti
Neat, thanks :)
moritz bust
@busti
The interface of transformPickler compared to compositePickler.addTransform is a bit odd.
In the former it is (transformFrom)(transformTo) and in the latter it is (transformTo, transformFrom).
Is there a reason for that?
Otto Chrons
@ochrons
the curried version allows using the types from the first argument in the second argument
with addTransform that is not needed IIRC
so often you don't need to specify the types manually, like in the example
implicit val datePickler = transformPickler((t: Long) => new java.util.Date(t))(_.getTime)
moritz bust
@busti
@ochrons Thanks :)
One more thing...
Can I serialize partially applied functions?
case class FooModel(number: Int, text: String)

def setNumber(to: Int)(state: FooModel): FooModel =
state.copy(number = to)

val foo = setNumber(5) // is it possible to serialize this ?
Otto Chrons
@ochrons
sure, if you provide a Pickler ;)
but in reality, probably not
because your pickler has no way of figuring out what arguments have already been supplied
you would have to describe the arguments some other way, like with a case class
or by building a chain of classes with apply functions returning the next class
moritz bust
@busti
Yeah, I am using case classes right now to do this, but it makes things really verbose.
@ochrons Thanks again :)
moritz bust
@busti
To give a bit of context, my environment is very similar to DIODE, but I have a hard requirement on being able to serialize actions. The idea is to have actions defined as def (a: Int, b: String) = Action { state => state.copy(foo = a, bar = b) }.
I guess that I could make this work with a macro, which generates a serialisation method and adds it to the Action object.
Otto Chrons
@ochrons
moritz bust
@busti
@ochrons I have read the docs of cats Free[_] for the past hour or so.
I have looked at them before, but I am not quite sure what you intend. Is your suggestion to implement Actions as an algebra and have two separate compilers, one for serialization and one for state mutation?
Otto Chrons
@ochrons
well, Free is able to capture the Actions and then you can serialize it easily
since it's just a bunch of case classes
Rok Kralj
@strelec
I have two questions:
1. Have there been any changes that could affect the binary format since 1.3.0?
1. Do we consider scala.js 1.0.0 stable enough to push a boopickle release for it?
Dennis
Hi! Is there a clever way to find out which types are automatically derived the most times (ie duplications that would benefit from explicitly creating the pickler in a central place so that its macro is generated only once). Because I am using sloth for client-server communications I need to use auto-derivation as the sloth macros generate case classes that I could otherwise not serialize.
Dennis
aha its in the docs, sorry, thought I did read everything .. great!
Otto Chrons
@ochrons
should be no obstacles publishing Boopickle for 1.0.0
Tushar Mathur
@tusharmath
case class Point(x: Int, y: Int)

val p = Point(5, 10)
val points = Vector(p, p, p, p)
val bb = Pickle.intoBytes(points)
.
.
val newPoints = Unpickle[Vector[Point]].fromBytes(bb)
this example from gitbook doesn't work
Unpickle does not take type parameters
How else do we use it ?
Rok Kralj
@strelec
The error is only in the IDE, not when compiling with scalac
Rok Kralj
@strelec
@ochrons Why is boopickle encoding a zero in front of every object
For example Vector(Point(1,2), Point(3,4), Point(5,6)) serializes into Array(3, 0, 1, 2, 0, 3, 4, 0, 5, 6)
Tushar Mathur
@tusharmath
@strelec yeah got that eventually.
but why is that ?
how can i fix it?
Otto Chrons
@ochrons
@strelec because it uses that to encode things like null and also for references to the same object
Marc Grue
@marcgrue

Struggled to find a way to pickle bytes running throuch a WebSocket in a Play Scala-js project and finally got it working. While I was at it I made my whole autowiring setup more generic so that I only have to configure the moving parts when adding a new api for instance.

Having a generic interface also allows to avoid messing around with websocket callbacks and instead use the exact same api as we do when using ajax:

// autowire websocket wire handle
object fooWireWS extends AutowireWebSocket[FooApi]("foo")

// Make type-safe api calls throuch websocket...
fooWireWS().incr(curNumber).call().foreach { n =>
println("got an incremented number from the server via WebSocket: " + n)
}

Long story short - made a minimal sample project with all generic autowire plumbing separated out into a few generic util classes. Pretty neat me thinks. Hope this will be useful for others. Let me know if you have any comments or suggestions for improvements.

PS: You'll also find an ajax vs websocket performance test, yay...

Rok Kralj
@strelec
@ochrons Thanks Otto! It does seem a bit wasteful, we could enforce acyclic and non-null structures. Protocol buffers use this extra byte to provide backwards and forwards compatibility.
Rok Kralj
@strelec
For the ScalaJS 1.0.0 release are you waiting for a pull request?
Tushar Mathur
@tusharmath

Unknown object coding: 78

How should I debug this error?

Trond Bjerkestrand
like you can encode a List[Int] and decode it as Vector[Int] no problem