Extensions in the protocol buffer do not work, as you would expect, i.e. not consistent with Java inheritance mechanism.
For your problem, I created the following foobar.proto file:
package test; message Foo { optional int32 i = 1; extensions 10 to 99999; } message Bar { extend Foo { optional int32 j = 10001; } }
It creates Foobar.java containing the classes Foobar.Bar and Foobar.Foo .
And here is a simple JUnit test case, accessing Bar.j:
import static org.junit.Assert.assertEquals; import org.junit.Test; import test.Foobar.Bar; import test.Foobar.Foo; public class TestFooBar { @Test public void testFooBar() { Foo foo = Foo.newBuilder().setI(123).setExtension(Bar.j, 456).build(); assertEquals(Integer.valueOf(456), foo.getExtension(Bar.j)); } }
Hope that helps clarify your problem!
foch
source share