Ошибка при использовании преобразователя Retrofit 2 ProtoBuf

#java #android #protocol-buffers #retrofit2

#java #Android #протокол-буферы #retrofit2

Вопрос:

я пытаюсь использовать ProtoConverterFactory. Файлы .proto, которые я использую, выглядят следующим образом:

Foo.proto

 syntax = "proto2";

import "bar.proto";

message CommonProtoMessage {
    required string messageName = 1;
    required bytes messageBody = 2;
}

message ResponseRequestMessage {

    optional Request1 request1 = 1;
    optional Response1 response1 = 2;
    optional Request2 request2 = 3;
    optional DoSomething dosomething = 4;
    optional GetResponseRequest getResponseRequest = 5;
    optional RequestCompletedNotification requestCompleted = 6;
}

message MessageWrapper {

    optional int64 requestId = 1;

    optional ResponseRequestMessage responseRequestMessage = 2;
    optional CommonProtoMessage commonMessage = 3;
}
 

Bar.proto

 syntax = "proto2";

message Request1 {
    required string username = 1;
    required string password = 2;
    required string workstation = 3;
}

message Response1 {
    required int64 id = 1;
}

message Request2 {
    required int64 id = 1;
}

message DoSomething {
    required int64 id = 1;
}

message GetResponseRequest {
    required int64 id1 = 1;
    required int64 id2 = 2;
}

message RequestCompletedNotification {
    required int64 id1 = 1;
    required int64 id2 = 2;
}
 

Я скомпилировал эти файлы, используя библиотеку wire, в несколько классов Java. После этого я попытался отправить запрос на сервер с помощью Retrofit.

Модифицированный конструктор:

 Retrofit.Builder()
            .baseUrl(baseUrl)
            .client(okHttpClient)
            .addConverterFactory(ProtoConverterFactory.create())
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .build();
 

Но мое приложение вылетает с ошибкой:

 java.lang.RuntimeException: Unable to start activity
ComponentInfo{**activity name**}: java.lang.IllegalArgumentException:
Unable     to     create @Body converter for class .proto.Foo 
(parameter #1)
Caused by: java.lang.IllegalArgumentException: Could not locate 
RequestBody converter for class 
proto.ngs.vms.messages.proto.MessageWrapper.

Tried:

* retrofit2.BuiltInConverters

* retrofit2.converter.protobuf.ProtoConverterFactory
 

Из этой ошибки я понял, что Retrofit не может использовать proto converter для моих скомпилированных классов

Я попытался найти некоторую информацию о Retrofit и Protobuf, но не нашел ничего полезного

Комментарии:

1. Нашел что-нибудь?