本文整理了Java中io.protostuff.Schema.newMessage()
方法的一些代码示例,展示了Schema.newMessage()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Schema.newMessage()
方法的具体详情如下:
包路径:io.protostuff.Schema
类名称:Schema
方法名:newMessage
[英]Creates the message/object tied to this schema.
[中]创建绑定到此架构的消息/对象。
代码示例来源:origin: protostuff/protostuff
@Override
public T newMessage()
{
return schema.newMessage();
}
代码示例来源:origin: apache/incubator-dubbo
@SuppressWarnings("ResultOfMethodCallIgnored")
@Override
public Object readObject() throws IOException, ClassNotFoundException {
int classNameLength = dis.readInt();
int bytesLength = dis.readInt();
if (classNameLength < 0 || bytesLength < 0) {
throw new IOException();
}
byte[] classNameBytes = new byte[classNameLength];
dis.readFully(classNameBytes, 0, classNameLength);
byte[] bytes = new byte[bytesLength];
dis.readFully(bytes, 0, bytesLength);
String className = new String(classNameBytes);
Class clazz = Class.forName(className);
Object result;
if (WrapperUtils.needWrapper(clazz)) {
Schema<Wrapper> schema = RuntimeSchema.getSchema(Wrapper.class);
Wrapper wrapper = schema.newMessage();
GraphIOUtil.mergeFrom(bytes, wrapper, schema);
result = wrapper.getData();
} else {
Schema schema = RuntimeSchema.getSchema(clazz);
result = schema.newMessage();
GraphIOUtil.mergeFrom(bytes, result, schema);
}
return result;
}
代码示例来源:origin: apache/incubator-dubbo
@SuppressWarnings("ResultOfMethodCallIgnored")
@Override
public Object readObject() throws IOException, ClassNotFoundException {
int classNameLength = dis.readInt();
int bytesLength = dis.readInt();
if (classNameLength < 0 || bytesLength < 0) {
throw new IOException();
}
byte[] classNameBytes = new byte[classNameLength];
dis.readFully(classNameBytes, 0, classNameLength);
byte[] bytes = new byte[bytesLength];
dis.readFully(bytes, 0, bytesLength);
String className = new String(classNameBytes);
Class clazz = Class.forName(className);
Object result;
if (WrapperUtils.needWrapper(clazz)) {
Schema<Wrapper> schema = RuntimeSchema.getSchema(Wrapper.class);
Wrapper wrapper = schema.newMessage();
GraphIOUtil.mergeFrom(bytes, wrapper, schema);
result = wrapper.getData();
} else {
Schema schema = RuntimeSchema.getSchema(clazz);
result = schema.newMessage();
GraphIOUtil.mergeFrom(bytes, result, schema);
}
return result;
}
代码示例来源:origin: protostuff/protostuff
@Before
public void setUp() throws Exception
{
fixture = SCHEMA.newMessage();
fixture.field1 = 42;
fixture.field2 = "testValue";
fixtureExtended = EXTENDED_SCHEMA.newMessage();
fixtureExtended.field1 = 42;
fixtureExtended.field2 = "testValue";
fixtureExtended.field3 = "hello".getBytes();
}
代码示例来源:origin: protostuff/protostuff
@Before
public void setUp() throws Exception
{
instance = SCHEMA.newMessage();
}
代码示例来源:origin: protostuff/protostuff
private <T> T mergeObjectEncodedAsGroup(T value, final Schema<T> schema) throws IOException
{
if (value == null)
value = schema.newMessage();
schema.mergeFrom(this, value);
if (!schema.isInitialized(value))
throw new UninitializedMessageException(value, schema);
// handling is in #readFieldNumber
checkLastTagWas(0);
return value;
}
代码示例来源:origin: protostuff/protostuff
private <T> T mergeObjectEncodedAsGroup(T value, final Schema<T> schema) throws IOException
{
if (value == null)
value = schema.newMessage();
schema.mergeFrom(this, value);
if (!schema.isInitialized(value))
throw new UninitializedMessageException(value, schema);
// handling is in #readFieldNumber
checkLastTagWas(0);
return value;
}
代码示例来源:origin: fengjiachun/Jupiter
private <T> T mergeObjectEncodedAsGroup(T value, final Schema<T> schema) throws IOException {
if (value == null) {
value = schema.newMessage();
}
schema.mergeFrom(this, value);
if (!schema.isInitialized(value)) {
throw new UninitializedMessageException(value, schema);
}
// handling is in #readFieldNumber
checkLastTagWas(0);
return value;
}
代码示例来源:origin: fengjiachun/Jupiter
private <T> T mergeObjectEncodedAsGroup(T value, final Schema<T> schema) throws IOException {
if (value == null) {
value = schema.newMessage();
}
schema.mergeFrom(this, value);
if (!schema.isInitialized(value)) {
throw new UninitializedMessageException(value, schema);
}
// handling is in #readFieldNumber
checkLastTagWas(0);
return value;
}
代码示例来源:origin: fengjiachun/Jupiter
private <T> T mergeObjectEncodedAsGroup(T value, final Schema<T> schema) throws IOException {
if (value == null) {
value = schema.newMessage();
}
schema.mergeFrom(this, value);
if (!schema.isInitialized(value)) {
throw new UninitializedMessageException(value, schema);
}
// handling is in #readFieldNumber
checkLastTagWas(0);
return value;
}
代码示例来源:origin: protostuff/protostuff
private static <T> T deserializeGraph(byte[] bytes, Class<T> clz)
{
Schema<T> schema = RuntimeSchema.getSchema(clz);
T obj = schema.newMessage();
GraphIOUtil.mergeFrom(bytes, obj, schema);
return obj;
}
代码示例来源:origin: protostuff/protostuff
private static <T> T deserializeGraph(InputStream in, Class<T> clz) throws IOException
{
Schema<T> schema = RuntimeSchema.getSchema(clz);
T obj = schema.newMessage();
GraphIOUtil.mergeFrom(in, obj, schema);
return obj;
}
代码示例来源:origin: fengjiachun/Jupiter
@Override
public <T> T readObject(byte[] bytes, int offset, int length, Class<T> clazz) {
Schema<T> schema = RuntimeSchema.getSchema(clazz);
T msg = schema.newMessage();
Input input = Inputs.getInput(bytes, offset, length);
try {
schema.mergeFrom(input, msg);
Inputs.checkLastTagWas(input, 0);
} catch (IOException e) {
ThrowUtil.throwException(e);
}
return msg;
}
代码示例来源:origin: protostuff/protostuff
private void deserTest(Message origMsg,
Schema sch,
ByteBuffer buf) throws IOException
{
ByteBufferInput input = new ByteBufferInput(buf, true);
Object newM = sch.newMessage();
sch.mergeFrom(input, newM);
assertEquals(origMsg, newM);
}
代码示例来源:origin: protostuff/protostuff
private void deserTest(Message origMsg,
Schema sch,
ByteBuffer buf) throws IOException
{
ByteBufferInput input = new ByteBufferInput(buf, false);
Object newM = sch.newMessage();
sch.mergeFrom(input, newM);
assertEquals(origMsg, newM);
}
代码示例来源:origin: protostuff/protostuff
@Test
public void forceUseSunReflectionFactory() throws Exception {
System.setProperty("protostuff.runtime.always_use_sun_reflection_factory", "true");
Schema<MyClass> schema = RuntimeSchema.getSchema(MyClass.class);
ByteArrayOutputStream output = new ByteArrayOutputStream();
MyClass myClass = new MyClass(); // constructor initializes list with one element
ProtostuffIOUtil.writeTo(output, myClass, schema, LinkedBuffer.allocate());
byte[] bytes = output.toByteArray();
Assert.assertEquals(1, myClass.getList().size());
MyClass myClassNew = schema.newMessage(); // default constructor should not be used
ProtostuffIOUtil.mergeFrom(bytes, myClassNew, schema);
Assert.assertEquals(1, myClassNew.getList().size());
}
代码示例来源:origin: protostuff/protostuff
@Test
public void unknownField() throws Exception
{
byte[] extendedMessage = MsgpackIOUtil.toByteArray(fixtureExtended, EXTENDED_SCHEMA, numeric);
TestMessage instance = SCHEMA.newMessage();
// unknown field3
MsgpackIOUtil.mergeFrom(extendedMessage, instance, SCHEMA, numeric);
checkKnownFields(instance);
}
代码示例来源:origin: protostuff/protostuff
@Test
public void normalExtendedMessage() throws Exception
{
byte[] message = MsgpackIOUtil.toByteArray(fixtureExtended, EXTENDED_SCHEMA, numeric);
TestMessageExtended instance = EXTENDED_SCHEMA.newMessage();
MsgpackIOUtil.mergeFrom(message, instance, EXTENDED_SCHEMA, numeric);
checkKnownFields(instance);
}
代码示例来源:origin: protostuff/protostuff
@Test
public void normalMessage() throws Exception
{
byte[] message = MsgpackIOUtil.toByteArray(fixture, SCHEMA, numeric);
TestMessage instance = SCHEMA.newMessage();
MsgpackIOUtil.mergeFrom(message, instance, SCHEMA, numeric);
checkKnownFields(instance);
}
代码示例来源:origin: protostuff/protostuff
@Test
public void missingField() throws Exception
{
byte[] message = MsgpackIOUtil.toByteArray(fixture, SCHEMA, numeric);
TestMessageExtended instance = EXTENDED_SCHEMA.newMessage();
// missing field3
MsgpackIOUtil.mergeFrom(message, instance, EXTENDED_SCHEMA, numeric);
Assert.assertEquals(fixtureExtended.field1, instance.field1);
Assert.assertEquals(fixtureExtended.field2, instance.field2);
Assert.assertNull(instance.field3);
}
内容来源于网络,如有侵权,请联系作者删除!