Packing a third party class

75 views
Skip to first unread message

Howard Lander

unread,
Jun 14, 2013, 4:22:30 PM6/14/13
to msg...@googlegroups.com
Hi all

Please forgive the newby question. If there is a more appropriate group for this question, please redirect me.

I'm trying to pack a class whose hierarchy contains an abstract class.  Specifically, I am trying to pack an instance of cern.colt.matrix.impl.RCDoubleMatrix2D (http://acs.lbl.gov/software/colt/api/cern/colt/matrix/impl/RCDoubleMatrix2D.html).  But I am getting the following exception:

org.msgpack.MessageTypeException: org.msgpack.template.builder.TemplateBuildException: Cannot build template for abstract class: cern.colt.matrix.DoubleMatrix2D

My code is very simple: it looks like this

     public void writeToDisk(String fileName) throws Exception {

         // Create packed byte array from this instance of this object.
         MessagePack thisPack = new MessagePack();
         thisPack.register(DoubleMatrix2D.class);
         thisPack.register(RCDoubleMatrix2D.class);
         byte[] theBytes = thisPack.write(this.similarityMatrix);

         // write it to the requested file
         try {
             FileOutputStream fos = new FileOutputStream(new File(fileName));
             BufferedOutputStream theStream = new BufferedOutputStream(fos);
             theStream.write(theBytes);
         } catch (Exception e) {
             throw e;
         }

     }

I did notice that there is an AbstractPacker class.  Is this what I need to use? Or do I need to think about one of the other serialization implementations?

Thanks for any help.
Howard




Masahiro Nakagawa

unread,
Jun 17, 2013, 11:10:59 PM6/17/13
to msg...@googlegroups.com
Hi Howard,

It is Java implementation, right?

Muga or sada,

Do you see any problem?


Thanks,
Masahiro


Howard




--
You received this message because you are subscribed to the Google Groups "MessagePack Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msgpack+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Tsuyoshi OZAWA

unread,
Jun 19, 2013, 2:36:54 AM6/19/13
to msg...@googlegroups.com
Hi Howard,

I apologize for delaying reply.

Very straightforward method to pack DoubleMatrix2D class is to extract 
double[][] by using DoubleMatrix2D#getQuick() method.
I don't confirm double[][] can be serialized directly, but double[][] can be serialized as array of double. 
Is it suitable for your use case?

Muga Nishizawa

unread,
Jun 19, 2013, 2:57:27 AM6/19/13
to msg...@googlegroups.com
Hi Howard,

Thank you for contacting us.

> I'm trying to pack a class whose hierarchy contains an abstract class.
> Specifically, I am trying to pack an instance of
> cern.colt.matrix.impl.RCDoubleMatrix2D
> (http://acs.lbl.gov/software/colt/api/cern/colt/matrix/impl/RCDoubleMatrix2D.html).
> But I am getting the following exception:
>
> org.msgpack.MessageTypeException: org.msgpack.template.builder.TemplateBuildException: Cannot build template for abstract class: cern.colt.matrix.DoubleMatrix2D

As you know, current version of msgpack-java cannot build (generate)
templates for abstract classes. The limitation is the specification
that I defined because 'read' method in template class for abstract
class shouldn't be called. But your application (template generation
of third-party's abstract class) is usual. I think that next version
of msgpack-java should provide new API for the solution.

> Very straightforward method to pack DoubleMatrix2D class is to extract
> double[][] by using DoubleMatrix2D#getQuick() method.
> I don't confirm double[][] can be serialized directly, but double[][] can
> be serialized as array of double. Is it suitable for your use case?

like this:

double[][] src = ... your double[][] object...;
Packer packer = msgpack.createPacker(...);
packer.write(src);
...
Unpacker u = msgpack.createUnpacker(in);
double[][] dst = u.read(double[][].class);

Thanks,
Muga
Reply all
Reply to author
Forward
0 new messages