/krpc

A KMP RPC support wire custom handler plugin

Primary LanguageKotlinApache License 2.0Apache-2.0

krpc-plugin

Generate kotlin multiplatform RPC code from .proto files.

Krpc base on wire.

Usage

Use plugin

// build.gradle.kts
plugins {
    id("cn.szkug.krpc") version "<version>"
}

wire {
    // wire configuration
}

Import Schema Handler

buildscript {
  repositories {
    mavenCentral()
  }
  dependencies {
    classpath("org.szkug.krpc:schema:<version>")
  }
}

Then configuration WireExtension schema handler with custom.

// build.gradle.kts
wire {
    custom {
        schemaHandlerFactory = KrpcSchemaHandlerFactory.client()
        out = "${layout.buildDirectory.asFile.get()}/generated"
    }
    // wire configuration
}

// must import runtime without plugin
dependencies {
    implementation("org.szkug.krpc:runtime:<version>")
}

Sample

message ActiveReq {
  string os = 1; // System
  string brd = 2; // Device
  string ver = 3; // App Version
  optional int64 uid = 4; // User id if logged in
}

message ActiveResp {}

service ActiveService {

  rpc report(ActiveReq) returns (ActiveResp);

}

This proto file will generate kotlin code like:

interface KrpcActiveService {
    fun report(req: ActiveReq): ActiveResp
}