0

I'm playing with Pickled Scala signatures, writing bytes to a PickleBuffer and reading them back out with ShowPickled.

I can write and read back an Int as expected by using

PB.myBuf.writeByte(2)

giving the '2' (a reference to an entry number in this case) in

1(MyRecord) 2 40[case] 5.

But if I but that same code inside a conditional like:

if (ExtModClassRef.position==0) PB.myBuf.writeByte(2),

or

ExtModClassRef.position match {case 0 => PB.myBuf.writeByte(2)},

then the bytes that I read back are garbled:

0,4: CLASSsym 4: 1(MyRecordmodels\00\00...

instead of how the first few entries should be:

0,4: CLASSsym 4: 1(MyRecord) 2 40[case] 5 1,10: TYPEname 8: MyRecord 2,20: EXTMODCLASSref 1: 3(models) 3,23: TERMname 6: models

I'm puzzled as to how the if and match keywords could have any effect on what bytes are written.

And perhaps someone can suggest a fix or a workaround?

Thank you, Julian

4

1 回答 1

2

The only two ways I can see to influence what bytes are written are:

  1. ExtModClassRef.position actually isn't 0, so the bytes you expect to be written aren't, and when you write something else later, it corrupts the record.

  2. ExtModClassRef.position call modifies myBuf in some way.

It's impossible to determine which is the case (or perhaps something different) without seeing your own code.

于 2013-08-05T08:48:54.443 回答