streem / pbandk

Kotlin Code Generator and Runtime for Protocol Buffers
MIT License
271 stars 37 forks source link

Retrofit Converter #14

Open aminghadersohi opened 4 years ago

aminghadersohi commented 4 years ago

Is there a recommended Convertor for Retrofit for the generated Kotlin code?

garyp commented 4 years ago

@aminghadersohi We have one written internally. I'll work on getting it published as a library. It's so small that in the meantime I've put it into this gist if you want to copy it: https://gist.github.com/garyp/fe4dc73058f84245830fbae024d0ca6e.

aminghadersohi commented 4 years ago

Thanks so much!

Morteza-Rastgoo commented 4 years ago
Screen Shot 1398-12-27 at 1 01 59 PM
Morteza-Rastgoo commented 4 years ago

Ok, That was because i was using okhttp 3 instead of 4.4.0

Morteza-Rastgoo commented 4 years ago

New error: pbandk can't handle response body with content type application/x-protobuf

Morteza-Rastgoo commented 4 years ago

I added this: private const val protobufxMediaType = "application/x-protobuf"

protobufMediaType, protobufxMediaType -> value.byteStream().use {
                val value =
                    messageCompanion.protoUnmarshal(Unmarshaller(CodedInputStream.newInstance(it)))
                if (BuildConfig.DEBUG) {
                    Log.d("ProtoConverter", value.toString())
                }
                value
            }

Also I want to log the request and response body, so I use value.tostring() there.

Morteza-Rastgoo commented 4 years ago

Is it ok if i make it a library?