Skip to content

methanol-protobuf

Adapters for Google's Protocol Buffers.

Encoding & Decoding

Any subtype of MessageLite is supported by encoders & decoders. Decoders can optionally have an ExtensionRegistryLite or an ExtensionRegistry to enable message extensions.

Installation

Gradle

implementation("com.github.mizosoft.methanol:methanol-protobuf:1.7.0")

Maven

<dependency>
  <groupId>com.github.mizosoft.methanol</groupId>
   <artifactId>methanol-protobuf</artifactId>
   <version>1.7.0</version>
</dependency>

Usage

var adapterCodec =
    AdapterCodec.newBuilder()
        .encoder(ProtobufAdapterFactory.createEncoder())
        .decoder(ProtobufAdapterFactory.createDecoder())
        .build();
var client =
    Methanol.newBuilder()
        .adapterCodec(adapterCodec)
        .build();

var bruceLee = Person.newBuilder().setName("Bruce Lee").build();
var response = client.send(
    MutableRequest.POST(".../echo", bruceLee, MediaType.APPLICATION_XML),
    MyMessage.class);
assertThat(response.body()).isEqualTo(bruceLee);