use of com.google.protobuf.ExtensionRegistry in project retrofit by square.
the class ProtoConverterFactoryTest method setUp.
@Before
public void setUp() {
Retrofit retrofit = new Retrofit.Builder().baseUrl(server.url("/")).addConverterFactory(ProtoConverterFactory.create()).build();
service = retrofit.create(Service.class);
ExtensionRegistry registry = ExtensionRegistry.newInstance();
PhoneProtos.registerAllExtensions(registry);
Retrofit retrofitWithRegistry = new Retrofit.Builder().baseUrl(server.url("/")).addConverterFactory(ProtoConverterFactory.createWithRegistry(registry)).build();
serviceWithRegistry = retrofitWithRegistry.create(ServiceWithRegistry.class);
}
use of com.google.protobuf.ExtensionRegistry in project jvm-serializers by eishay.
the class JsonFormat method mergeField.
/**
* Parse a single field from {@code tokenizer} and merge it into {@code builder}. If a ',' is
* detected after the field ends, the next field will be parsed automatically
*/
private static void mergeField(Tokenizer tokenizer, ExtensionRegistry extensionRegistry, Message.Builder builder) throws ParseException {
FieldDescriptor field;
Descriptor type = builder.getDescriptorForType();
ExtensionRegistry.ExtensionInfo extension = null;
if (tokenizer.tryConsume("[")) {
// An extension.
StringBuilder name = new StringBuilder(tokenizer.consumeIdentifier());
while (tokenizer.tryConsume(".")) {
name.append(".");
name.append(tokenizer.consumeIdentifier());
}
extension = extensionRegistry.findExtensionByName(name.toString());
if (extension == null) {
throw tokenizer.parseExceptionPreviousToken("Extension \"" + name + "\" not found in the ExtensionRegistry.");
} else if (extension.descriptor.getContainingType() != type) {
throw tokenizer.parseExceptionPreviousToken("Extension \"" + name + "\" does not extend message type \"" + type.getFullName() + "\".");
}
tokenizer.consume("]");
field = extension.descriptor;
} else {
String name = tokenizer.consumeIdentifier();
field = type.findFieldByName(name);
// names.
if (field == null) {
// Explicitly specify US locale so that this code does not break when
// executing in Turkey.
String lowerName = name.toLowerCase(Locale.US);
field = type.findFieldByName(lowerName);
// If the case-insensitive match worked but the field is NOT a group,
if ((field != null) && (field.getType() != FieldDescriptor.Type.GROUP)) {
field = null;
}
}
// Again, special-case group names as described above.
if ((field != null) && (field.getType() == FieldDescriptor.Type.GROUP) && !field.getMessageType().getName().equals(name)) {
field = null;
}
if (field == null) {
throw tokenizer.parseExceptionPreviousToken("Message type \"" + type.getFullName() + "\" has no field named \"" + name + "\".");
}
}
tokenizer.consume(":");
boolean array = tokenizer.tryConsume("[");
if (array) {
while (!tokenizer.tryConsume("]")) {
handleValue(tokenizer, extensionRegistry, builder, field, extension);
tokenizer.tryConsume(",");
}
} else {
handleValue(tokenizer, extensionRegistry, builder, field, extension);
}
if (tokenizer.tryConsume(",")) {
// Continue with the next field
mergeField(tokenizer, extensionRegistry, builder);
}
}
use of com.google.protobuf.ExtensionRegistry in project toolkit by googleapis.
the class GapicTestConfig method getDescriptor.
/**
* Returns the file descriptor set generated from the sources of this api.
*/
@Override
public FileDescriptorSet getDescriptor() throws IOException {
ExtensionRegistry registry = ExtensionRegistry.newInstance();
AnnotationsProto.registerAllExtensions(registry);
AuthProto.registerAllExtensions(registry);
return FileDescriptorSet.parseFrom(Files.newInputStream(getDescriptorFile()), registry);
}
use of com.google.protobuf.ExtensionRegistry in project drools by kiegroup.
the class PersisterHelper method buildRegistry.
public static ExtensionRegistry buildRegistry(MarshallerReaderContext context, ProcessMarshaller processMarshaller) {
ExtensionRegistry registry = ExtensionRegistry.newInstance();
if (processMarshaller != null) {
context.parameterObject = registry;
processMarshaller.init(context);
}
return registry;
}
use of com.google.protobuf.ExtensionRegistry in project jesos by groupon.
the class TestProtobufRegistry method testRoundtrip.
@Test
public void testRoundtrip() throws Exception {
ExtensionRegistry e = ProtobufRegistry.INSTANCE.mutableExtensionRegistry();
TestProtos.registerAllExtensions(e);
ExtBase extBase = ExtBase.newBuilder().setA("172.42.1.2").setB("br0").setD(24).setC("172.42.1.1").setE("00:11:22:33:44:55").build();
Base base = Base.newBuilder().setExtension(ExtBase.type, extBase).setType(Base.Type.EXT_BASE).build();
byte[] bytes = base.toByteArray();
Base generated = Base.parseFrom(new ByteArrayInputStream(bytes), e);
ExtBase extGenerated = generated.getExtension(ExtBase.type);
assertEquals(extBase.getA(), extGenerated.getA());
assertEquals(extBase.getB(), extGenerated.getB());
assertEquals(extBase.getC(), extGenerated.getC());
assertEquals(extBase.getD(), extGenerated.getD());
assertEquals(extBase.getE(), extGenerated.getE());
}
Aggregations