diff options
Diffstat (limited to 'java')
-rw-r--r-- | java/src/main/java/com/google/protobuf/nano/MessageNano.java | 6 | ||||
-rw-r--r-- | java/src/test/java/com/google/protobuf/NanoTest.java | 9 |
2 files changed, 12 insertions, 3 deletions
diff --git a/java/src/main/java/com/google/protobuf/nano/MessageNano.java b/java/src/main/java/com/google/protobuf/nano/MessageNano.java index 5c1eb2ff..8d4ec39e 100644 --- a/java/src/main/java/com/google/protobuf/nano/MessageNano.java +++ b/java/src/main/java/com/google/protobuf/nano/MessageNano.java @@ -101,7 +101,7 @@ public abstract class MessageNano { * Parse {@code data} as a message of this type and merge it with the * message being built. */ - public static final MessageNano mergeFrom(MessageNano msg, final byte[] data) + public static final <T extends MessageNano> T mergeFrom(T msg, final byte[] data) throws InvalidProtocolBufferNanoException { return mergeFrom(msg, data, 0, data.length); } @@ -110,8 +110,8 @@ public abstract class MessageNano { * Parse {@code data} as a message of this type and merge it with the * message being built. */ - public static final MessageNano mergeFrom(MessageNano msg, final byte[] data, final int off, - final int len) throws InvalidProtocolBufferNanoException { + public static final <T extends MessageNano> T mergeFrom(T msg, final byte[] data, + final int off, final int len) throws InvalidProtocolBufferNanoException { try { final CodedInputByteBufferNano input = CodedInputByteBufferNano.newInstance(data, off, len); diff --git a/java/src/test/java/com/google/protobuf/NanoTest.java b/java/src/test/java/com/google/protobuf/NanoTest.java index 38fafb9e..19f39575 100644 --- a/java/src/test/java/com/google/protobuf/NanoTest.java +++ b/java/src/test/java/com/google/protobuf/NanoTest.java @@ -2241,6 +2241,15 @@ public class NanoTest extends TestCase { assertEquals(0, MessageNano.toByteArray(deserialized).length); } + public void testMergeFrom() throws Exception { + SimpleMessageNano message = new SimpleMessageNano(); + message.d = 123; + byte[] bytes = MessageNano.toByteArray(message); + + SimpleMessageNano newMessage = MessageNano.mergeFrom(new SimpleMessageNano(), bytes); + assertEquals(message.d, newMessage.d); + } + private <T> List<T> list(T first, T... remaining) { List<T> list = new ArrayList<T>(); list.add(first); |