Here is the proto message that we trying to send.
message Cta {
string title = 1;
string pid = 2;
google.protobuf.Struct params = 3;
}
Does
protobuf-litelibrary which is recommended for android supportgoogle.protobuf.Struct?Where can we find the list of known proto types that are supported by the javalite runtime for protobuf?
If in case Struct / Vaule is not supported by the java-lite then what is recommended proto type for
HashMap<String, Object>?
Gradle that we using to generate the java code from proto.
plugins {
id 'com.android.library'
id 'kotlin-android'
id 'com.google.protobuf'
id 'org.jetbrains.kotlin.android'
}
java {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
}
android {
compileSdkVersion 33
buildToolsVersion "30.0.3"
namespace 'com.boom.protobuf'
}
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.20.1"
}
generateProtoTasks {
all().each { task ->
task.builtins {
java {
option 'lite'
}
kotlin {
option 'lite'
}
}
}
}
}
dependencies {
api 'com.google.protobuf:protobuf-kotlin-lite:3.23.0'
api 'com.google.protobuf:protobuf-javalite:3.23.0'
}
Going after the documentation of the Protobuf Java Lite runtime, I found some answers for your first and second topics. What you want is in the MessageLite interface.
Yes. You can see from the "All Known Implementing Classes" that
StructandValueimplement theMessageLiteinterface. Meaning that they're available in that runtime level.That list of "All Known Implementing Classes" is the closest thing I found for you.
The thing is that this might not solve your problem. Protobuf requires you to define the structure you want to serialize. That being said, if you don't want to define it beforehand, you'll need to handle it yourself. One option is to use JSON (or any other serialization format) to serialize the Object and inject it into your message as a raw value.