public void testParseDelimitedTo() throws Exception { // Write normal Message. TestAllTypes normalMessage = TestUtil.getAllSet(); ByteArrayOutputStream output = new ByteArrayOutputStream(); normalMessage.writeDelimitedTo(output); // Write MessageLite with packed extension fields. TestPackedExtensionsLite packedMessage = TestUtil.getLitePackedExtensionsSet(); packedMessage.writeDelimitedTo(output); InputStream input = new ByteArrayInputStream(output.toByteArray()); assertMessageEquals( normalMessage, normalMessage.getParserForType().parseDelimitedFrom(input)); assertMessageEquals( packedMessage, packedMessage.getParserForType().parseDelimitedFrom( input, TestUtil.getExtensionRegistryLite())); }
public void testParseDelimitedToLite() throws Exception { // Write MessageLite with packed extension fields. TestPackedExtensionsLite packedMessage = TestUtilLite.getLitePackedExtensionsSet(); ByteArrayOutputStream output = new ByteArrayOutputStream(); packedMessage.writeDelimitedTo(output); packedMessage.writeDelimitedTo(output); InputStream input = new ByteArrayInputStream(output.toByteArray()); assertMessageEquals( packedMessage, packedMessage .getParserForType() .parseDelimitedFrom(input, TestUtilLite.getExtensionRegistryLite())); assertMessageEquals( packedMessage, packedMessage .getParserForType() .parseDelimitedFrom(input, TestUtilLite.getExtensionRegistryLite())); }
public void testSerializePackedExtensionsLite() throws Exception { // TestPackedTypes and TestPackedExtensions should have compatible wire // formats; check that they serialize to the same string. TestPackedExtensionsLite message = TestUtil.getLitePackedExtensionsSet(); ByteString rawBytes = message.toByteString(); TestPackedTypes message2 = TestUtil.getPackedSet(); ByteString rawBytes2 = message2.toByteString(); assertEquals(rawBytes, rawBytes2); }
public void testParsePackedExtensionsLite() throws Exception { // Ensure that packed extensions can be properly parsed. TestPackedExtensionsLite message = TestUtil.getLitePackedExtensionsSet(); ByteString rawBytes = message.toByteString(); ExtensionRegistryLite registry = TestUtil.getExtensionRegistryLite(); TestPackedExtensionsLite message2 = TestPackedExtensionsLite.parseFrom(rawBytes, registry); TestUtil.assertPackedExtensionsSet(message2); }
public static void setPackedExtensions(TestPackedExtensionsLite.Builder message) { message.addExtension(packedInt32ExtensionLite , 601); message.addExtension(packedInt64ExtensionLite , 602L); message.addExtension(packedUint32ExtensionLite , 603); message.addExtension(packedUint64ExtensionLite , 604L); message.addExtension(packedSint32ExtensionLite , 605); message.addExtension(packedSint64ExtensionLite , 606L); message.addExtension(packedFixed32ExtensionLite , 607); message.addExtension(packedFixed64ExtensionLite , 608L); message.addExtension(packedSfixed32ExtensionLite, 609); message.addExtension(packedSfixed64ExtensionLite, 610L); message.addExtension(packedFloatExtensionLite , 611F); message.addExtension(packedDoubleExtensionLite , 612D); message.addExtension(packedBoolExtensionLite , true); message.addExtension(packedEnumExtensionLite, ForeignEnumLite.FOREIGN_LITE_BAR); // Add a second one of each field. message.addExtension(packedInt32ExtensionLite , 701); message.addExtension(packedInt64ExtensionLite , 702L); message.addExtension(packedUint32ExtensionLite , 703); message.addExtension(packedUint64ExtensionLite , 704L); message.addExtension(packedSint32ExtensionLite , 705); message.addExtension(packedSint64ExtensionLite , 706L); message.addExtension(packedFixed32ExtensionLite , 707); message.addExtension(packedFixed64ExtensionLite , 708L); message.addExtension(packedSfixed32ExtensionLite, 709); message.addExtension(packedSfixed64ExtensionLite, 710L); message.addExtension(packedFloatExtensionLite , 711F); message.addExtension(packedDoubleExtensionLite , 712D); message.addExtension(packedBoolExtensionLite , false); message.addExtension(packedEnumExtensionLite, ForeignEnumLite.FOREIGN_LITE_BAZ); }
public void testSerializePackedExtensionsLite() throws Exception { // TestPackedTypes and TestPackedExtensions should have compatible wire // formats; check that they serialize to the same string. TestPackedExtensionsLite message = TestUtilLite.getLitePackedExtensionsSet(); ByteString rawBytes = message.toByteString(); TestPackedTypes message2 = TestUtil.getPackedSet(); ByteString rawBytes2 = message2.toByteString(); assertEquals(rawBytes, rawBytes2); }
public void testParsePackedExtensionsLite() throws Exception { // Ensure that packed extensions can be properly parsed. TestPackedExtensionsLite message = TestUtilLite.getLitePackedExtensionsSet(); ByteString rawBytes = message.toByteString(); ExtensionRegistryLite registry = TestUtilLite.getExtensionRegistryLite(); TestPackedExtensionsLite message2 = TestPackedExtensionsLite.parseFrom(rawBytes, registry); TestUtil.assertPackedExtensionsSet(message2); }
public static TestPackedExtensionsLite getLitePackedExtensionsSet() { TestPackedExtensionsLite.Builder builder = TestPackedExtensionsLite.newBuilder(); setPackedExtensions(builder); return builder.build(); }
public static void assertPackedExtensionsSet(TestPackedExtensionsLite message) { Assert.assertEquals(2, message.getExtensionCount(packedInt32ExtensionLite )); Assert.assertEquals(2, message.getExtensionCount(packedInt64ExtensionLite )); Assert.assertEquals(2, message.getExtensionCount(packedUint32ExtensionLite )); Assert.assertEquals(2, message.getExtensionCount(packedUint64ExtensionLite )); Assert.assertEquals(2, message.getExtensionCount(packedSint32ExtensionLite )); Assert.assertEquals(2, message.getExtensionCount(packedSint64ExtensionLite )); Assert.assertEquals(2, message.getExtensionCount(packedFixed32ExtensionLite )); Assert.assertEquals(2, message.getExtensionCount(packedFixed64ExtensionLite )); Assert.assertEquals(2, message.getExtensionCount(packedSfixed32ExtensionLite)); Assert.assertEquals(2, message.getExtensionCount(packedSfixed64ExtensionLite)); Assert.assertEquals(2, message.getExtensionCount(packedFloatExtensionLite )); Assert.assertEquals(2, message.getExtensionCount(packedDoubleExtensionLite )); Assert.assertEquals(2, message.getExtensionCount(packedBoolExtensionLite )); Assert.assertEquals(2, message.getExtensionCount(packedEnumExtensionLite)); assertEqualsExactType(601 , message.getExtension(packedInt32ExtensionLite , 0)); assertEqualsExactType(602L , message.getExtension(packedInt64ExtensionLite , 0)); assertEqualsExactType(603 , message.getExtension(packedUint32ExtensionLite , 0)); assertEqualsExactType(604L , message.getExtension(packedUint64ExtensionLite , 0)); assertEqualsExactType(605 , message.getExtension(packedSint32ExtensionLite , 0)); assertEqualsExactType(606L , message.getExtension(packedSint64ExtensionLite , 0)); assertEqualsExactType(607 , message.getExtension(packedFixed32ExtensionLite , 0)); assertEqualsExactType(608L , message.getExtension(packedFixed64ExtensionLite , 0)); assertEqualsExactType(609 , message.getExtension(packedSfixed32ExtensionLite, 0)); assertEqualsExactType(610L , message.getExtension(packedSfixed64ExtensionLite, 0)); assertEqualsExactType(611F , message.getExtension(packedFloatExtensionLite , 0)); assertEqualsExactType(612D , message.getExtension(packedDoubleExtensionLite , 0)); assertEqualsExactType(true , message.getExtension(packedBoolExtensionLite , 0)); assertEqualsExactType(ForeignEnumLite.FOREIGN_LITE_BAR, message.getExtension(packedEnumExtensionLite, 0)); assertEqualsExactType(701 , message.getExtension(packedInt32ExtensionLite , 1)); assertEqualsExactType(702L , message.getExtension(packedInt64ExtensionLite , 1)); assertEqualsExactType(703 , message.getExtension(packedUint32ExtensionLite , 1)); assertEqualsExactType(704L , message.getExtension(packedUint64ExtensionLite , 1)); assertEqualsExactType(705 , message.getExtension(packedSint32ExtensionLite , 1)); assertEqualsExactType(706L , message.getExtension(packedSint64ExtensionLite , 1)); assertEqualsExactType(707 , message.getExtension(packedFixed32ExtensionLite , 1)); assertEqualsExactType(708L , message.getExtension(packedFixed64ExtensionLite , 1)); assertEqualsExactType(709 , message.getExtension(packedSfixed32ExtensionLite, 1)); assertEqualsExactType(710L , message.getExtension(packedSfixed64ExtensionLite, 1)); assertEqualsExactType(711F , message.getExtension(packedFloatExtensionLite , 1)); assertEqualsExactType(712D , message.getExtension(packedDoubleExtensionLite , 1)); assertEqualsExactType(false, message.getExtension(packedBoolExtensionLite , 1)); assertEqualsExactType(ForeignEnumLite.FOREIGN_LITE_BAZ, message.getExtension(packedEnumExtensionLite, 1)); }