mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-10-20 22:31:33 +02:00
java: removes old benchmark codes
This commit is contained in:
@@ -1,38 +0,0 @@
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import org.msgpack.*;
|
||||
import org.msgpack.schema.*;
|
||||
|
||||
public class Generate {
|
||||
public static void main(String[] args) throws IOException
|
||||
{
|
||||
String source =
|
||||
"(class MediaContent"+
|
||||
" (package serializers.msgpack)"+
|
||||
" (field image (array (class Image"+
|
||||
" (field uri string)"+
|
||||
" (field title string)"+
|
||||
" (field width int)"+
|
||||
" (field height int)"+
|
||||
" (field size int))))"+
|
||||
" (field media (class Media"+
|
||||
" (field uri string)"+
|
||||
" (field title string)"+
|
||||
" (field width int)"+
|
||||
" (field height int)"+
|
||||
" (field format string)"+
|
||||
" (field duration long)"+
|
||||
" (field size long)"+
|
||||
" (field bitrate int)"+
|
||||
" (field person (array string))"+
|
||||
" (field player int)"+
|
||||
" (field copyright string)))"+
|
||||
" )";
|
||||
|
||||
Schema schema = Schema.parse(source);
|
||||
|
||||
Writer output = new OutputStreamWriter(System.out);
|
||||
ClassGenerator.write(schema, output);
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +0,0 @@
|
||||
#!/bin/sh
|
||||
svn checkout -r114 http://thrift-protobuf-compare.googlecode.com/svn/trunk/ thrift-protobuf-compare-base
|
||||
cp -rf thrift-protobuf-compare/tpc thrift-protobuf-compare-base
|
||||
cp ../target/msgpack*.jar thrift-protobuf-compare-base/tpc/lib/msgpack.jar
|
||||
cd thrift-protobuf-compare-base/tpc/
|
||||
ant compile
|
||||
./run-benchmark.sh
|
@@ -1,436 +0,0 @@
|
||||
package serializers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import serializers.msgpack.MessagePackDirectSerializer;
|
||||
import serializers.msgpack.MessagePackSpecificSerializer;
|
||||
import serializers.msgpack.MessagePackIndirectSerializer;
|
||||
import serializers.msgpack.MessagePackDynamicSerializer;
|
||||
import serializers.msgpack.MessagePackGenericSerializer;
|
||||
import serializers.avro.AvroGenericSerializer;
|
||||
import serializers.avro.specific.AvroSpecificSerializer;
|
||||
import serializers.kryo.KryoOptimizedSerializer;
|
||||
import serializers.kryo.KryoSerializer;
|
||||
|
||||
public class BenchmarkRunner
|
||||
{
|
||||
public final static int ITERATIONS = 2000;
|
||||
public final static int TRIALS = 20;
|
||||
|
||||
/**
|
||||
* Number of milliseconds to warm up for each operation type for each serializer. Let's
|
||||
* start with 3 seconds.
|
||||
*/
|
||||
final static long WARMUP_MSECS = 3000;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Set<ObjectSerializer> _serializers = new LinkedHashSet<ObjectSerializer>();
|
||||
|
||||
public static void main(String... args) throws Exception
|
||||
{
|
||||
BenchmarkRunner runner = new BenchmarkRunner();
|
||||
|
||||
// binary codecs first
|
||||
runner.addObjectSerializer(new MessagePackDirectSerializer());
|
||||
runner.addObjectSerializer(new MessagePackSpecificSerializer());
|
||||
runner.addObjectSerializer(new MessagePackIndirectSerializer());
|
||||
runner.addObjectSerializer(new MessagePackDynamicSerializer());
|
||||
runner.addObjectSerializer(new MessagePackGenericSerializer());
|
||||
runner.addObjectSerializer(new AvroGenericSerializer());
|
||||
runner.addObjectSerializer(new AvroSpecificSerializer());
|
||||
runner.addObjectSerializer(new ActiveMQProtobufSerializer());
|
||||
runner.addObjectSerializer(new ProtobufSerializer());
|
||||
runner.addObjectSerializer(new ThriftSerializer());
|
||||
runner.addObjectSerializer(new HessianSerializer());
|
||||
runner.addObjectSerializer(new KryoSerializer());
|
||||
runner.addObjectSerializer(new KryoOptimizedSerializer());
|
||||
|
||||
// None of the other serializers use compression, so we'll leave this out.
|
||||
// runner.addObjectSerializer(new KryoCompressedSerializer());
|
||||
|
||||
// then language default serializers
|
||||
runner.addObjectSerializer(new JavaSerializer());
|
||||
|
||||
runner.addObjectSerializer(new JavaExtSerializer());
|
||||
runner.addObjectSerializer(new ScalaSerializer());
|
||||
|
||||
// then Json
|
||||
runner.addObjectSerializer(new JsonSerializer());
|
||||
runner.addObjectSerializer(new JsonDataBindingSerializer());
|
||||
runner.addObjectSerializer(new JsonMarshallerSerializer());
|
||||
runner.addObjectSerializer(new ProtostuffJsonSerializer());
|
||||
runner.addObjectSerializer(new ProtostuffNumericJsonSerializer());
|
||||
// this is pretty slow; so slow that it's almost not worth keeping but:
|
||||
runner.addObjectSerializer(new GsonSerializer());
|
||||
|
||||
// then xml via stax, textual and binary
|
||||
runner.addObjectSerializer(new StaxSerializer("stax/woodstox",
|
||||
new com.ctc.wstx.stax.WstxInputFactory(),
|
||||
new com.ctc.wstx.stax.WstxOutputFactory()));
|
||||
runner.addObjectSerializer(new StaxSerializer("stax/aalto",
|
||||
new com.fasterxml.aalto.stax.InputFactoryImpl(),
|
||||
new com.fasterxml.aalto.stax.OutputFactoryImpl()));
|
||||
|
||||
runner.addObjectSerializer(new StaxSerializer("binaryxml/FI",
|
||||
new com.sun.xml.fastinfoset.stax.factory.StAXInputFactory(),
|
||||
new com.sun.xml.fastinfoset.stax.factory.StAXOutputFactory()));
|
||||
|
||||
// No point in running all 4 variants: let's just use fastest one:
|
||||
//runner.addObjectSerializer(new XStreamSerializer("xstream (xpp)", false, null, null));
|
||||
//runner.addObjectSerializer(new XStreamSerializer("xstream (xpp with conv)", true, null, null));
|
||||
//runner.addObjectSerializer(new XStreamSerializer("xstream (stax)", false, new com.ctc.wstx.stax.WstxInputFactory(), new com.ctc.wstx.stax.WstxOutputFactory()));
|
||||
runner.addObjectSerializer(new XStreamSerializer("xstream (stax with conv)",
|
||||
true,
|
||||
new com.ctc.wstx.stax.WstxInputFactory(),
|
||||
new com.ctc.wstx.stax.WstxOutputFactory()));
|
||||
runner.addObjectSerializer(new JavolutionXMLFormatSerializer());
|
||||
|
||||
runner.addObjectSerializer(new SbinarySerializer());
|
||||
// broken? Does not correctly round-trip:
|
||||
// runner.addObjectSerializer(new YamlSerializer());
|
||||
|
||||
System.out.println("Starting");
|
||||
|
||||
runner.start();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void addObjectSerializer(ObjectSerializer serializer)
|
||||
{
|
||||
_serializers.add(serializer);
|
||||
}
|
||||
|
||||
private <T> double createObjects(ObjectSerializer<T> serializer, int iterations) throws Exception
|
||||
{
|
||||
long start = System.nanoTime();
|
||||
for (int i = 0; i < iterations; i++)
|
||||
{
|
||||
serializer.create();
|
||||
}
|
||||
return iterationTime(System.nanoTime() - start, iterations);
|
||||
}
|
||||
|
||||
private double iterationTime(long delta, int iterations)
|
||||
{
|
||||
return (double) delta / (double) (iterations);
|
||||
}
|
||||
|
||||
private <T> double serializeDifferentObjects(ObjectSerializer<T> serializer, int iterations) throws Exception
|
||||
{
|
||||
long start = System.nanoTime();
|
||||
for (int i = 0; i < iterations; i++)
|
||||
{
|
||||
T obj = serializer.create();
|
||||
serializer.serialize(obj);
|
||||
}
|
||||
return iterationTime(System.nanoTime()-start, iterations);
|
||||
}
|
||||
|
||||
|
||||
private <T> double serializeSameObject(ObjectSerializer<T> serializer, int iterations) throws Exception
|
||||
{
|
||||
// let's reuse same instance to reduce overhead
|
||||
T obj = serializer.create();
|
||||
long delta = 0;
|
||||
for (int i = 0; i < iterations; i++)
|
||||
{
|
||||
long start = System.nanoTime();
|
||||
serializer.serialize(obj);
|
||||
delta += System.nanoTime() - start;
|
||||
if (i % 1000 == 0)
|
||||
doGc();
|
||||
}
|
||||
return iterationTime(delta, iterations);
|
||||
}
|
||||
|
||||
private <T> double deserializeNoFieldAccess(ObjectSerializer<T> serializer, int iterations) throws Exception
|
||||
{
|
||||
byte[] array = serializer.serialize(serializer.create());
|
||||
long start = System.nanoTime();
|
||||
T result = null;
|
||||
for (int i = 0; i < iterations; i++)
|
||||
{
|
||||
result = serializer.deserialize(array);
|
||||
}
|
||||
return iterationTime(System.nanoTime()-start, iterations);
|
||||
}
|
||||
|
||||
private <T> double deserializeAndCheckAllFields(CheckingObjectSerializer<T> serializer, int iterations) throws Exception
|
||||
{
|
||||
byte[] array = serializer.serialize(serializer.create());
|
||||
long delta = 0;
|
||||
for (int i = 0; i < iterations; i++)
|
||||
{
|
||||
long start = System.nanoTime();
|
||||
T obj = serializer.deserialize(array);
|
||||
serializer.checkAllFields(obj);
|
||||
delta += System.nanoTime() - start;
|
||||
}
|
||||
return iterationTime(delta, iterations);
|
||||
}
|
||||
|
||||
private <T> double deserializeAndCheckMediaField(CheckingObjectSerializer<T> serializer, int iterations) throws Exception
|
||||
{
|
||||
byte[] array = serializer.serialize(serializer.create());
|
||||
long delta = 0;
|
||||
for (int i = 0; i < iterations; i++)
|
||||
{
|
||||
long start = System.nanoTime();
|
||||
T obj = serializer.deserialize(array);
|
||||
serializer.checkMediaField(obj);
|
||||
delta += System.nanoTime() - start;
|
||||
}
|
||||
return iterationTime(delta, iterations);
|
||||
}
|
||||
|
||||
/**
|
||||
* JVM is not required to honor GC requests, but adding bit of sleep around request is
|
||||
* most likely to give it a chance to do it.
|
||||
*/
|
||||
private void doGc()
|
||||
{
|
||||
try {
|
||||
Thread.sleep(50L);
|
||||
} catch (InterruptedException ie) { }
|
||||
System.gc();
|
||||
try { // longer sleep afterwards (not needed by GC, but may help with scheduling)
|
||||
Thread.sleep(200L);
|
||||
} catch (InterruptedException ie) { }
|
||||
}
|
||||
|
||||
enum measurements
|
||||
{
|
||||
timeCreate, timeSerializeDifferentObjects, timeSerializeSameObject, timeDeserializeNoFieldAccess, timeDeserializeAndCheckMediaField, timeDeserializeAndCheckAllFields, totalTime, length
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void start() throws Exception
|
||||
{
|
||||
System.out.printf("%-24s, %15s, %15s, %15s, %15s, %15s, %15s, %15s, %10s\n",
|
||||
" ",
|
||||
"Object create",
|
||||
"Serialize",
|
||||
"/w Same Object",
|
||||
"Deserialize",
|
||||
"and Check Media",
|
||||
"and Check All",
|
||||
"Total Time",
|
||||
"Serialized Size");
|
||||
EnumMap<measurements, Map<String, Double>> values = new EnumMap<measurements, Map<String, Double>>(measurements.class);
|
||||
for (measurements m : measurements.values())
|
||||
values.put(m, new HashMap<String, Double>());
|
||||
|
||||
for (ObjectSerializer serializer : _serializers)
|
||||
{
|
||||
/*
|
||||
* Should only warm things for the serializer that we test next: HotSpot JIT will
|
||||
* otherwise spent most of its time optimizing slower ones... Use
|
||||
* -XX:CompileThreshold=1 to hint the JIT to start immediately
|
||||
*
|
||||
* Actually: 1 is often not a good value -- threshold is the number
|
||||
* of samples needed to trigger inlining, and there's no point in
|
||||
* inlining everything. Default value is in thousands, so lowering
|
||||
* it to, say, 1000 is usually better.
|
||||
*/
|
||||
warmCreation(serializer);
|
||||
doGc();
|
||||
double timeCreate = Double.MAX_VALUE;
|
||||
// do more iteration for object creation because of its short time
|
||||
for (int i = 0; i < TRIALS; i++)
|
||||
timeCreate = Math.min(timeCreate, createObjects(serializer, ITERATIONS * 100));
|
||||
|
||||
warmSerialization(serializer);
|
||||
|
||||
// actually: let's verify serializer actually works now:
|
||||
checkCorrectness(serializer);
|
||||
|
||||
doGc();
|
||||
double timeSerializeDifferentObjects = Double.MAX_VALUE;
|
||||
for (int i = 0; i < TRIALS; i++)
|
||||
timeSerializeDifferentObjects = Math.min(timeSerializeDifferentObjects, serializeDifferentObjects(serializer, ITERATIONS));
|
||||
|
||||
doGc();
|
||||
double timeSerializeSameObject = Double.MAX_VALUE;
|
||||
for (int i = 0; i < TRIALS; i++)
|
||||
timeSerializeSameObject = Math.min(timeSerializeSameObject, serializeSameObject(serializer, ITERATIONS));
|
||||
|
||||
warmDeserialization(serializer);
|
||||
|
||||
doGc();
|
||||
double timeDeserializeNoFieldAccess = Double.MAX_VALUE;
|
||||
for (int i = 0; i < TRIALS; i++)
|
||||
timeDeserializeNoFieldAccess = Math.min(timeDeserializeNoFieldAccess, deserializeNoFieldAccess(serializer, ITERATIONS));
|
||||
|
||||
double timeDeserializeAndCheckAllFields = Double.NaN;
|
||||
double timeDeserializeAndCheckMediaField = Double.NaN;
|
||||
|
||||
double totalTime = timeSerializeDifferentObjects + timeDeserializeNoFieldAccess;
|
||||
|
||||
if( serializer instanceof CheckingObjectSerializer) {
|
||||
CheckingObjectSerializer checkingSerializer = (CheckingObjectSerializer)serializer;
|
||||
|
||||
timeDeserializeAndCheckMediaField = Double.MAX_VALUE;
|
||||
doGc();
|
||||
for (int i = 0; i < TRIALS; i++)
|
||||
timeDeserializeAndCheckMediaField = Math.min(timeDeserializeAndCheckMediaField, deserializeAndCheckMediaField(checkingSerializer, ITERATIONS));
|
||||
|
||||
timeDeserializeAndCheckAllFields = Double.MAX_VALUE;
|
||||
doGc();
|
||||
for (int i = 0; i < TRIALS; i++)
|
||||
timeDeserializeAndCheckAllFields = Math.min(timeDeserializeAndCheckAllFields, deserializeAndCheckAllFields(checkingSerializer, ITERATIONS));
|
||||
|
||||
totalTime = timeSerializeDifferentObjects + timeDeserializeAndCheckAllFields;
|
||||
}
|
||||
|
||||
|
||||
byte[] array = serializer.serialize(serializer.create());
|
||||
System.out.printf("%-24s, %15.5f, %15.5f, %15.5f, %15.5f, %15.5f, %15.5f, %15.5f, %10d\n",
|
||||
serializer.getName(),
|
||||
timeCreate,
|
||||
timeSerializeDifferentObjects,
|
||||
timeSerializeSameObject,
|
||||
timeDeserializeNoFieldAccess,
|
||||
timeDeserializeAndCheckMediaField,
|
||||
timeDeserializeAndCheckAllFields,
|
||||
totalTime,
|
||||
array.length);
|
||||
|
||||
addValue(values, serializer.getName(), timeCreate, timeSerializeDifferentObjects, timeSerializeSameObject,
|
||||
timeDeserializeNoFieldAccess, timeDeserializeAndCheckMediaField, timeDeserializeAndCheckAllFields, totalTime, array.length);
|
||||
}
|
||||
printImages(values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method that tries to validate correctness of serializer, using
|
||||
* round-trip (construct, serializer, deserialize; compare objects
|
||||
* after steps 1 and 3).
|
||||
* Currently only done for StdMediaDeserializer...
|
||||
*/
|
||||
private void checkCorrectness(ObjectSerializer serializer)
|
||||
throws Exception
|
||||
{
|
||||
Object input = serializer.create();
|
||||
byte[] array = serializer.serialize(input);
|
||||
Object output = serializer.deserialize(array);
|
||||
|
||||
if (!input.equals(output)) {
|
||||
/* Should throw an exception; but for now (that we have a few
|
||||
* failures) let's just whine...
|
||||
*/
|
||||
String msg = "serializer '"+serializer.getName()+"' failed round-trip test (ser+deser produces Object different from input), input="+input+", output="+output;
|
||||
//throw new Exception("Error: "+msg);
|
||||
System.err.println("WARN: "+msg);
|
||||
}
|
||||
}
|
||||
|
||||
private void printImages(EnumMap<measurements, Map<String, Double>> values)
|
||||
{
|
||||
for (measurements m : values.keySet()) {
|
||||
Map<String, Double> map = values.get(m);
|
||||
ArrayList<Entry> list = new ArrayList(map.entrySet());
|
||||
Collections.sort(list, new Comparator<Entry>() {
|
||||
public int compare (Entry o1, Entry o2) {
|
||||
double diff = (Double)o1.getValue() - (Double)o2.getValue();
|
||||
return diff > 0 ? 1 : (diff < 0 ? -1 : 0);
|
||||
}
|
||||
});
|
||||
LinkedHashMap<String, Double> sortedMap = new LinkedHashMap<String, Double>();
|
||||
for (Entry<String, Double> entry : list) {
|
||||
if( !entry.getValue().isNaN() ) {
|
||||
sortedMap.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
printImage(sortedMap, m);
|
||||
}
|
||||
}
|
||||
|
||||
private void printImage(Map<String, Double> map, measurements m)
|
||||
{
|
||||
StringBuilder valSb = new StringBuilder();
|
||||
String names = "";
|
||||
double max = Double.MIN_NORMAL;
|
||||
for (Entry<String, Double> entry : map.entrySet())
|
||||
{
|
||||
valSb.append(entry.getValue()).append(',');
|
||||
max = Math.max(max, entry.getValue());
|
||||
names = entry.getKey() + '|' + names;
|
||||
}
|
||||
|
||||
int height = Math.min(30+map.size()*20, 430);
|
||||
double scale = max * 1.1;
|
||||
System.out.println("<img src='http://chart.apis.google.com/chart?chtt="
|
||||
+ m.name()
|
||||
+ "&chf=c||lg||0||FFFFFF||1||76A4FB||0|bg||s||EFEFEF&chs=689x"+height+"&chd=t:"
|
||||
+ valSb.toString().substring(0, valSb.length() - 1)
|
||||
+ "&chds=0,"+ scale
|
||||
+ "&chxt=y"
|
||||
+ "&chxl=0:|" + names.substring(0, names.length() - 1)
|
||||
+ "&chm=N *f*,000000,0,-1,10&lklk&chdlp=t&chco=660000|660033|660066|660099|6600CC|6600FF|663300|663333|663366|663399|6633CC|6633FF|666600|666633|666666&cht=bhg&chbh=10&nonsense=aaa.png'/>");
|
||||
|
||||
}
|
||||
|
||||
private void addValue(EnumMap<measurements, Map<String, Double>> values,
|
||||
String name,
|
||||
double timeCreate,
|
||||
double timeSerializeDifferentObjects,
|
||||
double timeSerializeSameObject,
|
||||
double timeDeserializeNoFieldAccess,
|
||||
double timeDeserializeAndCheckMediaField,
|
||||
double timeDeserializeAndCheckAllFields,
|
||||
double totalTime,
|
||||
double length)
|
||||
{
|
||||
|
||||
values.get(measurements.timeCreate).put(name, timeCreate);
|
||||
values.get(measurements.timeSerializeDifferentObjects).put(name, timeSerializeDifferentObjects);
|
||||
values.get(measurements.timeSerializeSameObject).put(name, timeSerializeSameObject);
|
||||
values.get(measurements.timeDeserializeNoFieldAccess).put(name, timeDeserializeNoFieldAccess);
|
||||
values.get(measurements.timeDeserializeAndCheckMediaField).put(name, timeDeserializeAndCheckMediaField);
|
||||
values.get(measurements.timeDeserializeAndCheckAllFields).put(name, timeDeserializeAndCheckAllFields);
|
||||
values.get(measurements.totalTime).put(name, totalTime);
|
||||
values.get(measurements.length).put(name, length);
|
||||
}
|
||||
|
||||
private <T> void warmCreation(ObjectSerializer<T> serializer) throws Exception
|
||||
{
|
||||
// Instead of fixed counts, let's try to prime by running for N seconds
|
||||
long endTime = System.currentTimeMillis() + WARMUP_MSECS;
|
||||
do
|
||||
{
|
||||
createObjects(serializer, 1);
|
||||
}
|
||||
while (System.currentTimeMillis() < endTime);
|
||||
}
|
||||
|
||||
private <T> void warmSerialization(ObjectSerializer<T> serializer) throws Exception
|
||||
{
|
||||
// Instead of fixed counts, let's try to prime by running for N seconds
|
||||
long endTime = System.currentTimeMillis() + WARMUP_MSECS;
|
||||
do
|
||||
{
|
||||
serializeDifferentObjects(serializer, 1);
|
||||
}
|
||||
while (System.currentTimeMillis() < endTime);
|
||||
}
|
||||
|
||||
private <T> void warmDeserialization(ObjectSerializer<T> serializer) throws Exception
|
||||
{
|
||||
// Instead of fixed counts, let's try to prime by running for N seconds
|
||||
long endTime = System.currentTimeMillis() + WARMUP_MSECS;
|
||||
do
|
||||
{
|
||||
deserializeNoFieldAccess(serializer, 1);
|
||||
}
|
||||
while (System.currentTimeMillis() < endTime);
|
||||
}
|
||||
}
|
@@ -1,239 +0,0 @@
|
||||
package serializers.msgpack;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
import org.msgpack.*;
|
||||
import org.msgpack.schema.ClassSchema;
|
||||
import org.msgpack.schema.FieldSchema;
|
||||
|
||||
public final class MediaContent implements MessagePackable, MessageConvertable, MessageUnpackable
|
||||
{
|
||||
private static final ClassSchema _SCHEMA = (ClassSchema)Schema.load("(class MediaContent (package serializers.msgpack) (field image (array (class Image (package serializers.msgpack) (field uri string) (field title string) (field width int) (field height int) (field size int)))) (field media (class Media (package serializers.msgpack) (field uri string) (field title string) (field width int) (field height int) (field format string) (field duration long) (field size long) (field bitrate int) (field person (array string)) (field player int) (field copyright string))))");
|
||||
public static ClassSchema getSchema() { return _SCHEMA; }
|
||||
|
||||
public List<Image> image;
|
||||
public Media media;
|
||||
|
||||
public MediaContent() { }
|
||||
|
||||
@Override
|
||||
public void messagePack(Packer _pk) throws IOException
|
||||
{
|
||||
_pk.packArray(2);
|
||||
FieldSchema[] _fields = _SCHEMA.getFields();
|
||||
_fields[0].getSchema().pack(_pk, image);
|
||||
_fields[1].getSchema().pack(_pk, media);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void messageConvert(Object obj) throws MessageTypeException
|
||||
{
|
||||
Object[] _source = ((List)obj).toArray();
|
||||
FieldSchema[] _fields = _SCHEMA.getFields();
|
||||
if(_source.length <= 0) { return; } this.image = (List<Image>)_fields[0].getSchema().convert(_source[0]);
|
||||
if(_source.length <= 1) { return; } this.media = (Media)_fields[1].getSchema().convert(_source[1]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void messageUnpack(Unpacker _pac) throws IOException, MessageTypeException {
|
||||
int _length = _pac.unpackArray();
|
||||
if(_length <= 0) { return; }
|
||||
int _image_length = _pac.unpackArray();
|
||||
this.image = new ArrayList(_image_length);
|
||||
for(int _i=0; _i < _image_length; ++_i) {
|
||||
Image _image_i = new Image();
|
||||
_image_i.messageUnpack(_pac);
|
||||
this.image.add(_image_i);
|
||||
}
|
||||
if(_length <= 1) { return; }
|
||||
this.media = new Media();
|
||||
this.media.messageUnpack(_pac);
|
||||
for(int _i=2; _i < _length; ++_i) { _pac.unpackObject(); }
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static MediaContent createFromMessage(Object[] _message)
|
||||
{
|
||||
MediaContent _self = new MediaContent();
|
||||
if(_message.length <= 0) { return _self; } _self.image = (List<Image>)_message[0];
|
||||
if(_message.length <= 1) { return _self; } _self.media = (Media)_message[1];
|
||||
return _self;
|
||||
}
|
||||
}
|
||||
|
||||
final class Image implements MessagePackable, MessageConvertable, MessageUnpackable
|
||||
{
|
||||
private static final ClassSchema _SCHEMA = (ClassSchema)Schema.load("(class Image (package serializers.msgpack) (field uri string) (field title string) (field width int) (field height int) (field size int))");
|
||||
public static ClassSchema getSchema() { return _SCHEMA; }
|
||||
|
||||
public String uri;
|
||||
public String title;
|
||||
public Integer width;
|
||||
public Integer height;
|
||||
public Integer size;
|
||||
|
||||
public Image() { }
|
||||
|
||||
@Override
|
||||
public void messagePack(Packer _pk) throws IOException
|
||||
{
|
||||
_pk.packArray(5);
|
||||
FieldSchema[] _fields = _SCHEMA.getFields();
|
||||
_fields[0].getSchema().pack(_pk, uri);
|
||||
_fields[1].getSchema().pack(_pk, title);
|
||||
_fields[2].getSchema().pack(_pk, width);
|
||||
_fields[3].getSchema().pack(_pk, height);
|
||||
_fields[4].getSchema().pack(_pk, size);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void messageConvert(Object obj) throws MessageTypeException
|
||||
{
|
||||
Object[] _source = ((List)obj).toArray();
|
||||
FieldSchema[] _fields = _SCHEMA.getFields();
|
||||
if(_source.length <= 0) { return; } this.uri = (String)_fields[0].getSchema().convert(_source[0]);
|
||||
if(_source.length <= 1) { return; } this.title = (String)_fields[1].getSchema().convert(_source[1]);
|
||||
if(_source.length <= 2) { return; } this.width = (Integer)_fields[2].getSchema().convert(_source[2]);
|
||||
if(_source.length <= 3) { return; } this.height = (Integer)_fields[3].getSchema().convert(_source[3]);
|
||||
if(_source.length <= 4) { return; } this.size = (Integer)_fields[4].getSchema().convert(_source[4]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void messageUnpack(Unpacker _pac) throws IOException, MessageTypeException {
|
||||
int _length = _pac.unpackArray();
|
||||
if(_length <= 0) { return; }
|
||||
this.uri = _pac.unpackString();
|
||||
if(_length <= 1) { return; }
|
||||
this.title = _pac.unpackString();
|
||||
if(_length <= 2) { return; }
|
||||
this.width = _pac.unpackInt();
|
||||
if(_length <= 3) { return; }
|
||||
this.height = _pac.unpackInt();
|
||||
if(_length <= 4) { return; }
|
||||
this.size = _pac.unpackInt();
|
||||
for(int _i=5; _i < _length; ++_i) { _pac.unpackObject(); }
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Image createFromMessage(Object[] _message)
|
||||
{
|
||||
Image _self = new Image();
|
||||
if(_message.length <= 0) { return _self; } _self.uri = (String)_message[0];
|
||||
if(_message.length <= 1) { return _self; } _self.title = (String)_message[1];
|
||||
if(_message.length <= 2) { return _self; } _self.width = (Integer)_message[2];
|
||||
if(_message.length <= 3) { return _self; } _self.height = (Integer)_message[3];
|
||||
if(_message.length <= 4) { return _self; } _self.size = (Integer)_message[4];
|
||||
return _self;
|
||||
}
|
||||
}
|
||||
|
||||
final class Media implements MessagePackable, MessageConvertable, MessageUnpackable
|
||||
{
|
||||
private static final ClassSchema _SCHEMA = (ClassSchema)Schema.load("(class Media (package serializers.msgpack) (field uri string) (field title string) (field width int) (field height int) (field format string) (field duration long) (field size long) (field bitrate int) (field person (array string)) (field player int) (field copyright string))");
|
||||
public static ClassSchema getSchema() { return _SCHEMA; }
|
||||
|
||||
public String uri;
|
||||
public String title;
|
||||
public Integer width;
|
||||
public Integer height;
|
||||
public String format;
|
||||
public Long duration;
|
||||
public Long size;
|
||||
public Integer bitrate;
|
||||
public List<String> person;
|
||||
public Integer player;
|
||||
public String copyright;
|
||||
|
||||
public Media() { }
|
||||
|
||||
@Override
|
||||
public void messagePack(Packer _pk) throws IOException
|
||||
{
|
||||
_pk.packArray(11);
|
||||
FieldSchema[] _fields = _SCHEMA.getFields();
|
||||
_fields[0].getSchema().pack(_pk, uri);
|
||||
_fields[1].getSchema().pack(_pk, title);
|
||||
_fields[2].getSchema().pack(_pk, width);
|
||||
_fields[3].getSchema().pack(_pk, height);
|
||||
_fields[4].getSchema().pack(_pk, format);
|
||||
_fields[5].getSchema().pack(_pk, duration);
|
||||
_fields[6].getSchema().pack(_pk, size);
|
||||
_fields[7].getSchema().pack(_pk, bitrate);
|
||||
_fields[8].getSchema().pack(_pk, person);
|
||||
_fields[9].getSchema().pack(_pk, player);
|
||||
_fields[10].getSchema().pack(_pk, copyright);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void messageConvert(Object obj) throws MessageTypeException
|
||||
{
|
||||
Object[] _source = ((List)obj).toArray();
|
||||
FieldSchema[] _fields = _SCHEMA.getFields();
|
||||
if(_source.length <= 0) { return; } this.uri = (String)_fields[0].getSchema().convert(_source[0]);
|
||||
if(_source.length <= 1) { return; } this.title = (String)_fields[1].getSchema().convert(_source[1]);
|
||||
if(_source.length <= 2) { return; } this.width = (Integer)_fields[2].getSchema().convert(_source[2]);
|
||||
if(_source.length <= 3) { return; } this.height = (Integer)_fields[3].getSchema().convert(_source[3]);
|
||||
if(_source.length <= 4) { return; } this.format = (String)_fields[4].getSchema().convert(_source[4]);
|
||||
if(_source.length <= 5) { return; } this.duration = (Long)_fields[5].getSchema().convert(_source[5]);
|
||||
if(_source.length <= 6) { return; } this.size = (Long)_fields[6].getSchema().convert(_source[6]);
|
||||
if(_source.length <= 7) { return; } this.bitrate = (Integer)_fields[7].getSchema().convert(_source[7]);
|
||||
if(_source.length <= 8) { return; } this.person = (List<String>)_fields[8].getSchema().convert(_source[8]);
|
||||
if(_source.length <= 9) { return; } this.player = (Integer)_fields[9].getSchema().convert(_source[9]);
|
||||
if(_source.length <= 10) { return; } this.copyright = (String)_fields[10].getSchema().convert(_source[10]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void messageUnpack(Unpacker _pac) throws IOException, MessageTypeException {
|
||||
int _length = _pac.unpackArray();
|
||||
if(_length <= 0) { return; }
|
||||
this.uri = _pac.unpackString();
|
||||
if(_length <= 1) { return; }
|
||||
this.title = _pac.unpackString();
|
||||
if(_length <= 2) { return; }
|
||||
this.width = _pac.unpackInt();
|
||||
if(_length <= 3) { return; }
|
||||
this.height = _pac.unpackInt();
|
||||
if(_length <= 4) { return; }
|
||||
this.format = _pac.unpackString();
|
||||
if(_length <= 5) { return; }
|
||||
this.duration = _pac.unpackLong();
|
||||
if(_length <= 6) { return; }
|
||||
this.size = _pac.unpackLong();
|
||||
if(_length <= 7) { return; }
|
||||
this.bitrate = _pac.unpackInt();
|
||||
if(_length <= 8) { return; }
|
||||
int _person_length = _pac.unpackArray();
|
||||
this.person = new ArrayList(_person_length);
|
||||
for(int _i=0; _i < _person_length; ++_i) {
|
||||
String _person_i = _pac.unpackString();
|
||||
this.person.add(_person_i);
|
||||
}
|
||||
if(_length <= 9) { return; }
|
||||
this.player = _pac.unpackInt();
|
||||
if(_length <= 10) { return; }
|
||||
this.copyright = _pac.unpackString();
|
||||
for(int _i=11; _i < _length; ++_i) { _pac.unpackObject(); }
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Media createFromMessage(Object[] _message)
|
||||
{
|
||||
Media _self = new Media();
|
||||
if(_message.length <= 0) { return _self; } _self.uri = (String)_message[0];
|
||||
if(_message.length <= 1) { return _self; } _self.title = (String)_message[1];
|
||||
if(_message.length <= 2) { return _self; } _self.width = (Integer)_message[2];
|
||||
if(_message.length <= 3) { return _self; } _self.height = (Integer)_message[3];
|
||||
if(_message.length <= 4) { return _self; } _self.format = (String)_message[4];
|
||||
if(_message.length <= 5) { return _self; } _self.duration = (Long)_message[5];
|
||||
if(_message.length <= 6) { return _self; } _self.size = (Long)_message[6];
|
||||
if(_message.length <= 7) { return _self; } _self.bitrate = (Integer)_message[7];
|
||||
if(_message.length <= 8) { return _self; } _self.person = (List<String>)_message[8];
|
||||
if(_message.length <= 9) { return _self; } _self.player = (Integer)_message[9];
|
||||
if(_message.length <= 10) { return _self; } _self.copyright = (String)_message[10];
|
||||
return _self;
|
||||
}
|
||||
}
|
||||
|
@@ -1,21 +0,0 @@
|
||||
(class MediaContent
|
||||
(package serializers.msgpack)
|
||||
(field image (array (class Image
|
||||
(field uri string)
|
||||
(field title string)
|
||||
(field width int)
|
||||
(field height int)
|
||||
(field size int))))
|
||||
(field media (class Media
|
||||
(field uri string)
|
||||
(field title string)
|
||||
(field width int)
|
||||
(field height int)
|
||||
(field format string)
|
||||
(field duration long)
|
||||
(field size long)
|
||||
(field bitrate int)
|
||||
(field person (array string))
|
||||
(field player int)
|
||||
(field copyright string)))
|
||||
)
|
@@ -1,68 +0,0 @@
|
||||
package serializers.msgpack;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import org.msgpack.*;
|
||||
import serializers.ObjectSerializer;
|
||||
|
||||
public class MessagePackDirectSerializer implements ObjectSerializer<MediaContent>
|
||||
{
|
||||
public String getName() {
|
||||
return "msgpack-direct";
|
||||
}
|
||||
|
||||
public MediaContent create() throws Exception {
|
||||
Media media = new Media();
|
||||
media.uri = "http://javaone.com/keynote.mpg";
|
||||
media.format = "video/mpg4";
|
||||
media.title = "Javaone Keynote";
|
||||
media.duration = 1234567L;
|
||||
media.bitrate = 0;
|
||||
media.person = new ArrayList<String>(2);
|
||||
media.person.add("Bill Gates");
|
||||
media.person.add("Steve Jobs");
|
||||
media.player = 0;
|
||||
media.height = 0;
|
||||
media.width = 0;
|
||||
media.size = 123L;
|
||||
media.copyright = "";
|
||||
|
||||
Image image1 = new Image();
|
||||
image1.uri = "http://javaone.com/keynote_large.jpg";
|
||||
image1.width = 0;
|
||||
image1.height = 0;
|
||||
image1.size = 2;
|
||||
image1.title = "Javaone Keynote";
|
||||
|
||||
Image image2 = new Image();
|
||||
image2.uri = "http://javaone.com/keynote_thumbnail.jpg";
|
||||
image2.width = 0;
|
||||
image2.height = 0;
|
||||
image2.size = 1;
|
||||
image2.title = "Javaone Keynote";
|
||||
|
||||
MediaContent content = new MediaContent();
|
||||
content.media = media;
|
||||
content.image = new ArrayList<Image>(2);
|
||||
content.image.add(image1);
|
||||
content.image.add(image2);
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
public byte[] serialize(MediaContent content) throws Exception {
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
Packer pk = new Packer(os);
|
||||
pk.pack(content);
|
||||
return os.toByteArray();
|
||||
}
|
||||
|
||||
public MediaContent deserialize(byte[] array) throws Exception {
|
||||
Unpacker pac = new Unpacker();
|
||||
pac.wrap(array);
|
||||
MediaContent obj = new MediaContent();
|
||||
obj.messageUnpack(pac);
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
@@ -1,68 +0,0 @@
|
||||
package serializers.msgpack;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import org.msgpack.*;
|
||||
import serializers.ObjectSerializer;
|
||||
|
||||
public class MessagePackDynamicSerializer implements ObjectSerializer<Object>
|
||||
{
|
||||
public String getName() {
|
||||
return "msgpack-dynamic";
|
||||
}
|
||||
|
||||
public Object create() throws Exception {
|
||||
ArrayList media = new ArrayList(11);
|
||||
media.add("http://javaone.com/keynote.mpg");
|
||||
media.add("video/mpg4");
|
||||
media.add("Javaone Keynote");
|
||||
media.add(1234567L);
|
||||
media.add(0);
|
||||
ArrayList<String> person = new ArrayList<String>(2);
|
||||
person.add("Bill Gates");
|
||||
person.add("Steve Jobs");
|
||||
media.add(person);
|
||||
media.add(0);
|
||||
media.add(0);
|
||||
media.add(0);
|
||||
media.add(123L);
|
||||
media.add("");
|
||||
|
||||
ArrayList image1 = new ArrayList(5);
|
||||
image1.add("http://javaone.com/keynote_large.jpg");
|
||||
image1.add(0);
|
||||
image1.add(0);
|
||||
image1.add(2);
|
||||
image1.add("Javaone Keynote");
|
||||
|
||||
ArrayList image2 = new ArrayList(5);
|
||||
image2.add("http://javaone.com/keynote_thumbnail.jpg");
|
||||
image2.add(0);
|
||||
image2.add(0);
|
||||
image2.add(1);
|
||||
image2.add("Javaone Keynote");
|
||||
|
||||
ArrayList content = new ArrayList(2);
|
||||
content.add(media);
|
||||
ArrayList<Object> images = new ArrayList<Object>(2);
|
||||
images.add(image1);
|
||||
images.add(image2);
|
||||
content.add(images);
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
public byte[] serialize(Object content) throws Exception {
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
Packer pk = new Packer(os);
|
||||
pk.pack(content);
|
||||
return os.toByteArray();
|
||||
}
|
||||
|
||||
public Object deserialize(byte[] array) throws Exception {
|
||||
Unpacker pac = new Unpacker();
|
||||
pac.execute(array);
|
||||
return (Object)pac.getData();
|
||||
}
|
||||
}
|
||||
|
@@ -1,70 +0,0 @@
|
||||
package serializers.msgpack;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import org.msgpack.*;
|
||||
import serializers.ObjectSerializer;
|
||||
|
||||
public class MessagePackGenericSerializer implements ObjectSerializer<Object>
|
||||
{
|
||||
private static final Schema MEDIA_CONTENT_SCHEMA = Schema.parse("(class MediaContent (package serializers.msgpack) (field image (array (class Image (package serializers.msgpack) (field uri string) (field title string) (field width int) (field height int) (field size int)))) (field media (class Media (package serializers.msgpack) (field uri string) (field title string) (field width int) (field height int) (field format string) (field duration long) (field size long) (field bitrate int) (field person (array string)) (field player int) (field copyright string))))");
|
||||
|
||||
public String getName() {
|
||||
return "msgpack-generic";
|
||||
}
|
||||
|
||||
public Object create() throws Exception {
|
||||
HashMap<String,Object> media = new HashMap<String, Object>(11);
|
||||
media.put("uri", "http://javaone.com/keynote.mpg");
|
||||
media.put("format", "video/mpg4");
|
||||
media.put("title", "Javaone Keynote");
|
||||
media.put("duration", 1234567L);
|
||||
media.put("bitrate", 0);
|
||||
ArrayList<String> person = new ArrayList<String>(2);
|
||||
person.add("Bill Gates");
|
||||
person.add("Steve Jobs");
|
||||
media.put("person", person);
|
||||
media.put("player", 0);
|
||||
media.put("height", 0);
|
||||
media.put("width", 0);
|
||||
media.put("size", 123L);
|
||||
media.put("copyright", "");
|
||||
|
||||
HashMap<String,Object> image1 = new HashMap<String,Object>(5);
|
||||
image1.put("uri", "http://javaone.com/keynote_large.jpg");
|
||||
image1.put("width", 0);
|
||||
image1.put("height", 0);
|
||||
image1.put("size", 2);
|
||||
image1.put("title", "Javaone Keynote");
|
||||
|
||||
HashMap<String,Object> image2 = new HashMap<String,Object>(5);
|
||||
image2.put("uri", "http://javaone.com/keynote_thumbnail.jpg");
|
||||
image2.put("width", 0);
|
||||
image2.put("height", 0);
|
||||
image2.put("size", 1);
|
||||
image2.put("title", "Javaone Keynote");
|
||||
|
||||
HashMap<String,Object> content = new HashMap<String,Object>(2);
|
||||
content.put("media", media);
|
||||
ArrayList<Object> images = new ArrayList<Object>(2);
|
||||
images.add(image1);
|
||||
images.add(image2);
|
||||
content.put("image", images);
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
public byte[] serialize(Object content) throws Exception {
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
Packer pk = new Packer(os);
|
||||
pk.packWithSchema(content, MEDIA_CONTENT_SCHEMA);
|
||||
return os.toByteArray();
|
||||
}
|
||||
|
||||
public Object deserialize(byte[] array) throws Exception {
|
||||
Unpacker pac = new Unpacker().useSchema(MEDIA_CONTENT_SCHEMA);
|
||||
pac.execute(array);
|
||||
return (Object)pac.getData();
|
||||
}
|
||||
}
|
||||
|
@@ -1,67 +0,0 @@
|
||||
package serializers.msgpack;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import org.msgpack.*;
|
||||
import serializers.ObjectSerializer;
|
||||
|
||||
public class MessagePackIndirectSerializer implements ObjectSerializer<MediaContent>
|
||||
{
|
||||
public String getName() {
|
||||
return "msgpack-indirect";
|
||||
}
|
||||
|
||||
public MediaContent create() throws Exception {
|
||||
Media media = new Media();
|
||||
media.uri = "http://javaone.com/keynote.mpg";
|
||||
media.format = "video/mpg4";
|
||||
media.title = "Javaone Keynote";
|
||||
media.duration = 1234567L;
|
||||
media.bitrate = 0;
|
||||
media.person = new ArrayList<String>(2);
|
||||
media.person.add("Bill Gates");
|
||||
media.person.add("Steve Jobs");
|
||||
media.player = 0;
|
||||
media.height = 0;
|
||||
media.width = 0;
|
||||
media.size = 123L;
|
||||
media.copyright = "";
|
||||
|
||||
Image image1 = new Image();
|
||||
image1.uri = "http://javaone.com/keynote_large.jpg";
|
||||
image1.width = 0;
|
||||
image1.height = 0;
|
||||
image1.size = 2;
|
||||
image1.title = "Javaone Keynote";
|
||||
|
||||
Image image2 = new Image();
|
||||
image2.uri = "http://javaone.com/keynote_thumbnail.jpg";
|
||||
image2.width = 0;
|
||||
image2.height = 0;
|
||||
image2.size = 1;
|
||||
image2.title = "Javaone Keynote";
|
||||
|
||||
MediaContent content = new MediaContent();
|
||||
content.media = media;
|
||||
content.image = new ArrayList<Image>(2);
|
||||
content.image.add(image1);
|
||||
content.image.add(image2);
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
public byte[] serialize(MediaContent content) throws Exception {
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
Packer pk = new Packer(os);
|
||||
pk.pack(content);
|
||||
return os.toByteArray();
|
||||
}
|
||||
|
||||
public MediaContent deserialize(byte[] array) throws Exception {
|
||||
Unpacker pac = new Unpacker();
|
||||
pac.execute(array);
|
||||
Object obj = pac.getData();
|
||||
return (MediaContent)MediaContent.getSchema().convert(obj);
|
||||
}
|
||||
}
|
||||
|
@@ -1,66 +0,0 @@
|
||||
package serializers.msgpack;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import org.msgpack.*;
|
||||
import serializers.ObjectSerializer;
|
||||
|
||||
public class MessagePackSpecificSerializer implements ObjectSerializer<MediaContent>
|
||||
{
|
||||
public String getName() {
|
||||
return "msgpack-specific";
|
||||
}
|
||||
|
||||
public MediaContent create() throws Exception {
|
||||
Media media = new Media();
|
||||
media.uri = "http://javaone.com/keynote.mpg";
|
||||
media.format = "video/mpg4";
|
||||
media.title = "Javaone Keynote";
|
||||
media.duration = 1234567L;
|
||||
media.bitrate = 0;
|
||||
media.person = new ArrayList<String>(2);
|
||||
media.person.add("Bill Gates");
|
||||
media.person.add("Steve Jobs");
|
||||
media.player = 0;
|
||||
media.height = 0;
|
||||
media.width = 0;
|
||||
media.size = 123L;
|
||||
media.copyright = "";
|
||||
|
||||
Image image1 = new Image();
|
||||
image1.uri = "http://javaone.com/keynote_large.jpg";
|
||||
image1.width = 0;
|
||||
image1.height = 0;
|
||||
image1.size = 2;
|
||||
image1.title = "Javaone Keynote";
|
||||
|
||||
Image image2 = new Image();
|
||||
image2.uri = "http://javaone.com/keynote_thumbnail.jpg";
|
||||
image2.width = 0;
|
||||
image2.height = 0;
|
||||
image2.size = 1;
|
||||
image2.title = "Javaone Keynote";
|
||||
|
||||
MediaContent content = new MediaContent();
|
||||
content.media = media;
|
||||
content.image = new ArrayList<Image>(2);
|
||||
content.image.add(image1);
|
||||
content.image.add(image2);
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
public byte[] serialize(MediaContent content) throws Exception {
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
Packer pk = new Packer(os);
|
||||
pk.pack(content);
|
||||
return os.toByteArray();
|
||||
}
|
||||
|
||||
public MediaContent deserialize(byte[] array) throws Exception {
|
||||
Unpacker pac = new Unpacker().useSchema(MediaContent.getSchema());
|
||||
pac.execute(array);
|
||||
return (MediaContent)pac.getData();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user