![JAR search and dependency download from the Maven repository](/logo.png)
com.firefly.net.tcp.codec.flex.encode.DefaultMetaInfoGenerator Maven / Gradle / Ivy
package com.firefly.net.tcp.codec.flex.encode;
import com.firefly.net.tcp.codec.flex.model.Request;
import com.firefly.net.tcp.codec.flex.model.Response;
import io.protostuff.LinkedBuffer;
import io.protostuff.ProtostuffIOUtil;
import io.protostuff.Schema;
import io.protostuff.runtime.RuntimeSchema;
/**
* @author Pengtao Qiu
*/
public class DefaultMetaInfoGenerator implements MetaInfoGenerator {
public static final Schema requestSchema = RuntimeSchema.getSchema(Request.class);
public static final Schema responseSchema = RuntimeSchema.getSchema(Response.class);
@Override
public byte[] generate(Object object) {
byte[] data;
if (object instanceof Request) {
LinkedBuffer buffer = LinkedBuffer.allocate();
try {
data = ProtostuffIOUtil.toByteArray((Request) object, requestSchema, buffer);
} finally {
buffer.clear();
}
} else if (object instanceof Response) {
LinkedBuffer buffer = LinkedBuffer.allocate();
try {
data = ProtostuffIOUtil.toByteArray((Response) object, responseSchema, buffer);
} finally {
buffer.clear();
}
} else {
throw new IllegalArgumentException("The meta info type must be Request or Response");
}
return data;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy