Wire 3: gRPC meets Kotlin

Wire is our open source implementation of Protocol Buffers. Today’s release supports Kotlin, gRPC, and Gradle.

Kotlin

In addition to Java, Wire now generates Kotlin:

class Dinosaur(
  /** Common name of this dinosaur, like "Stegosaurus". */
  val name: String? = null,

  /** URLs with images of this dinosaur. */
  val picture_urls: List<String> = emptyList(),

  val period: Period? = null,

  unknownFields: ByteString = ByteString.EMPTY
) : Message<Dinosaur, Nothing>(ADAPTER, unknownFields) {
  // equals(), hashCode(), toString(), and copy()
}

Wire generates concise, idiomatic Kotlin, though we don’t generate data classes for technical reasons. Wire can also generate Java-interoperable Kotlin for an easy upgrade from Java.

gRPC

gRPC is a widely-adopted spec for API calls over HTTP/2. The shared schemas make it safer and easier than REST for client/server communication. Streaming APIs introduce expressive new ways to communicate. Wire 3 generates ergonomic APIs for gRPC clients and includes a small runtime to support them.

val grpcClient = GrpcClient.Builder()
    .client(okHttpClient)
    .baseUrl(url)
    .build()
val routeGuideService =
    grpcClient.create(RouteGuideClient::class)
 
val (requestChannel, responseChannel) =
    routeGuideService.RouteChat().execute()
 
requestChannel.send(RouteNote(message = "marco"))
responseChannel.receive()
requestChannel.send(RouteNote(message = "rené"))
requestChannel.close()
responseChannel.receive()

Gradle

Our new Gradle plugin makes it easy to start using Wire and protocol buffers:

apply plugin: 'com.squareup.wire'
 
wire {
  // Keeps only 'Dinosaur#name' as the root of the object
  // graph
  roots 'squareup.dinosaurs.Dinosaur#name'
 
  // Keeps all fields, except 'name', in 'Dinosaur'
  prunes 'squareup.dinosaurs.Dinosaur#name'
 
  kotlin {
    javaInterop true
    out "${buildDir}/generated/custom"
  }
}

The plugin can generate both Java and Kotlin together. It can also prune your schema to keep your code small and your builds fast.

Get it

Today we are releasing Wire 3. Check out Wire on Github to get started.