Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Protobuf in Kotlin

TakuSemba
March 27, 2019

Protobuf in Kotlin

TakuSemba

March 27, 2019
Tweet

More Decks by TakuSemba

Other Decks in Technology

Transcript

  1. syntax = "proto3"; package com.takusemba; option java_package = "com.takusemba.proto"; enum

    Size { SMALL = 0; MEDIUM = 1; LARGE = 2; } message Coffee { string name = 1; // espresso double price = 2; // 340 Size size = 3; // small / medium / large bool isAvailable = 4; // true / false }
  2. data class Coffee( /** * ex) espresso */ @field:WireField(tag =

    1, adapter = "com.squareup.wire.ProtoAdapter#STRING") val name: String? = null, /** * ex) 340 */ @field:WireField(tag = 2, adapter = "com.squareup.wire.ProtoAdapter#DOUBLE") val price: Double? = null, /** * ex) small / medium / large */ @field:WireField(tag = 3, adapter = "com.takusemba.proto.Size#ADAPTER") val size: Size? = null, /** * ex) true / false */ @field:WireField(tag = 4, adapter = "com.squareup.wire.ProtoAdapter#BOOL") val isAvailable: Boolean? = null, val unknownFields: ByteString = ByteString.EMPTY ) : Message<Coffee, Coffee.Builder>(ADAPTER, unknownFields) { … }
  3. data class Coffee( /** * ex) espresso */ @field:WireField(tag =

    1, adapter = "com.squareup.wire.ProtoAdapter#STRING") val name: String? = null, /** * ex) 340 */ @field:WireField(tag = 2, adapter = "com.squareup.wire.ProtoAdapter#DOUBLE") val price: Double? = null, /** * ex) small / medium / large */ @field:WireField(tag = 3, adapter = "com.takusemba.proto.Size#ADAPTER") val size: Size? = null, /** * ex) true / false */ @field:WireField(tag = 4, adapter = "com.squareup.wire.ProtoAdapter#BOOL") val isAvailable: Boolean? = null, val unknownFields: ByteString = ByteString.EMPTY ) : Message<Coffee, Coffee.Builder>(ADAPTER, unknownFields) { … } val name: String? = null, val price: Double? = null, val size: Size? = null, val isAvailable: Boolean? = null,
  4. data class Coffee( /** * ex) espresso */ @field:WireField(tag =

    1, adapter = "com.squareup.wire.ProtoAdapter#STRING") val name: String? = null, /** * ex) 340 */ @field:WireField(tag = 2, adapter = "com.squareup.wire.ProtoAdapter#DOUBLE") val price: Double? = null, /** * ex) small / medium / large */ @field:WireField(tag = 3, adapter = "com.takusemba.proto.Size#ADAPTER") val size: Size? = null, /** * ex) true / false */ @field:WireField(tag = 4, adapter = "com.squareup.wire.ProtoAdapter#BOOL") val isAvailable: Boolean? = null, val unknownFields: ByteString = ByteString.EMPTY ) : Message<Coffee, Coffee.Builder>(ADAPTER, unknownFields) { … } data class Coffee(
  5. --java_interop val coffee = Coffee( name = "espresso", price =

    310.0, size = Size.SMALL, isAvailable = true )
  6. --java_interop val coffee = Coffee( name = "espresso", price =

    310.0, size = Size.SMALL, isAvailable = true ) val coffee = Coffee.Builder() .name("espresso") .price(310.0) .size(Size.SMALL) .isAvailable(true) .build()
  7. --java_interop val coffee = Coffee( name = "espresso", price =

    310.0, size = Size.SMALL, isAvailable = true ) val coffee = Coffee.Builder() .name("espresso") .price(310.0) .size(Size.SMALL) .isAvailable(true) .build() val name: String
  8. --java_interop val coffee = Coffee( name = "espresso", price =

    310.0, size = Size.SMALL, isAvailable = true ) val coffee = Coffee.Builder() .name("espresso") .price(310.0) .size(Size.SMALL) .isAvailable(true) .build() val name: String @JvmField val name: String
  9. kotlin nullability syntax = "proto3"; package com.takusemba; option java_package =

    "com.takusemba.proto"; enum Size { SMALL = 0; MEDIUM = 1; LARGE = 2; } message Coffee { string name = 1; // espresso double price = 2; // 340 Size size = 3; // small / medium / large bool isAvailable = 4; // true / false }
  10. kotlin nullability syntax = "proto3"; package com.takusemba; option java_package =

    "com.takusemba.proto"; enum Size { SMALL = 0; MEDIUM = 1; LARGE = 2; } message Coffee { string name = 1; // espresso double price = 2; // 340 Size size = 3; // small / medium / large bool isAvailable = 4; // true / false } syntax = "proto3";
  11. kotlin nullability syntax = “proto2"; package com.takusemba; option java_package =

    "com.takusemba.proto"; enum Size { SMALL = 0; MEDIUM = 1; LARGE = 2; } message Coffee { string name = 1; // espresso double price = 2; // 340 Size size = 3; // small / medium / large bool isAvailable = 4; // true / false } syntax = “proto2";
  12. kotlin nullability syntax = “proto2"; package com.takusemba; option java_package =

    "com.takusemba.proto"; enum Size { SMALL = 0; MEDIUM = 1; LARGE = 2; } message Coffee { string name = 1; // espresso double price = 2; // 340 Size size = 3; // small / medium / large bool isAvailable = 4; // true / false } message Coffee { string name = 1; // espresso double price = 2; // 340 Size size = 3; // small / medium / large bool isAvailable = 4; // true / false }
  13. kotlin nullability syntax = "proto2"; package com.takusemba; option java_package =

    "com.takusemba.proto"; enum Size { SMALL = 0; MEDIUM = 1; LARGE = 2; } message Coffee { required string name = 1; // espresso required double price = 2; // 340 required Size size = 3; // small / medium / large optional bool isAvailable = 4; // true / false } message Coffee { required string name = 1; // espresso required double price = 2; // 340 required Size size = 3; // small / medium / large optional bool isAvailable = 4; // true / false }
  14. kotlin nullability syntax = "proto2"; package com.takusemba; option java_package =

    "com.takusemba.proto"; enum Size { SMALL = 0; MEDIUM = 1; LARGE = 2; } message Coffee { required string name = 1; // espresso required double price = 2; // 340 required Size size = 3; // small / medium / large optional bool isAvailable = 4; // true / false }
  15. data class Coffee( /** * ex) espresso */ @field:WireField(tag =

    1, adapter = "com.squareup.wire.ProtoAdapter#STRING") val name: String, /** * ex) 340 */ @field:WireField(tag = 2, adapter = "com.squareup.wire.ProtoAdapter#DOUBLE") val price: Double, /** * ex) small / medium / large */ @field:WireField(tag = 3, adapter = "com.takusemba.proto.Size#ADAPTER") val size: Size, /** * ex) true / false */ @field:WireField(tag = 4, adapter = "com.squareup.wire.ProtoAdapter#BOOL") val isAvailable: Boolean? = null, val unknownFields: ByteString = ByteString.EMPTY ) : Message<Coffee, Coffee.Builder>(ADAPTER, unknownFields) { … }
  16. data class Coffee( /** * ex) espresso */ @field:WireField(tag =

    1, adapter = "com.squareup.wire.ProtoAdapter#STRING") val name: String, /** * ex) 340 */ @field:WireField(tag = 2, adapter = "com.squareup.wire.ProtoAdapter#DOUBLE") val price: Double, /** * ex) small / medium / large */ @field:WireField(tag = 3, adapter = "com.takusemba.proto.Size#ADAPTER") val size: Size, /** * ex) true / false */ @field:WireField(tag = 4, adapter = "com.squareup.wire.ProtoAdapter#BOOL") val isAvailable: Boolean? = null, val unknownFields: ByteString = ByteString.EMPTY ) : Message<Coffee, Coffee.Builder>(ADAPTER, unknownFields) { … } val name: String, // required val price: Double, // required val size: Size, // required val isAvailable: Boolean? = null, // optional