Anki/proto/anki/ankidroid.proto
Damien Elmes 553303fc12
Refactor service generation (#2552)
* Automatically elide empty inputs and outputs to backend methods

* Refactor service generation

Despite the fact that the majority of our Protobuf service methods require
an open collection, they were not accessible with just a Collection
object. To access the methods (e.g. because we haven't gotten around to
exposing the correct API in Collection yet), you had to wrap the collection
in a Backend object, and pay a mutex-acquisition cost for each call, even
if you have exclusive access to the object.

This commit migrates the majority of service methods to the Collection, so
they can now be used directly, and improves the ergonomics a bit at the
same time.

The approach taken:

- The service generation now happens in rslib instead of anki_proto, which
avoids the need for trait constraints and associated types.
- Service methods are assumed to be collection-based by default. Instead of
implementing the service on Backend, we now implement it on Collection, which
means our methods no longer need to use self.with_col(...).
- We automatically generate methods in Backend which use self.with_col() to
delegate to the Collection method.
- For methods that are only appropriate for the backend, we add a flag in
the .proto file. The codegen uses this flag to write the method into a
BackendFooService instead of FooService, which the backend implements.
- The flag can also allows us to define separate implementations for collection
and backend, so we can e.g. skip the collection mutex in the i18n service
while also providing the service on a collection.
2023-06-19 15:33:40 +10:00

83 lines
No EOL
2.3 KiB
Protocol Buffer

syntax = "proto3";
option java_multiple_files = true;
import "anki/generic.proto";
import "anki/scheduler.proto";
import "anki/codegen.proto";
package anki.ankidroid;
service AnkidroidService {
rpc SchedTimingTodayLegacy(SchedTimingTodayLegacyRequest)
returns (scheduler.SchedTimingTodayResponse) {
option (codegen.rust_methods) = RUST_METHODS_BACKEND_ONLY;
}
rpc LocalMinutesWestLegacy(generic.Int64) returns (generic.Int32) {
option (codegen.rust_methods) = RUST_METHODS_BACKEND_ONLY;
}
rpc RunDbCommand(generic.Json) returns (generic.Json);
rpc RunDbCommandProto(generic.Json) returns (DbResponse);
rpc InsertForId(generic.Json) returns (generic.Int64);
rpc RunDbCommandForRowCount(generic.Json) returns (generic.Int64);
rpc FlushAllQueries(generic.Empty) returns (generic.Empty);
rpc FlushQuery(generic.Int32) returns (generic.Empty);
rpc GetNextResultPage(GetNextResultPageRequest) returns (DbResponse);
rpc SetPageSize(generic.Int64) returns (generic.Empty) {
option (codegen.rust_methods) = RUST_METHODS_BACKEND_ONLY;
}
rpc GetColumnNamesFromQuery(generic.String) returns (generic.StringList);
rpc GetActiveSequenceNumbers(generic.Empty)
returns (GetActiveSequenceNumbersResponse);
rpc DebugProduceError(generic.String) returns (generic.Empty) {
option (codegen.rust_methods) = RUST_METHODS_BACKEND_ONLY;
}
}
message DebugActiveDatabaseSequenceNumbersResponse {
repeated int32 sequence_numbers = 1;
}
message SchedTimingTodayLegacyRequest {
int64 created_secs = 1;
optional sint32 created_mins_west = 2;
int64 now_secs = 3;
sint32 now_mins_west = 4;
sint32 rollover_hour = 5;
}
// We expect in Java: Null, String, Short, Int, Long, Float, Double, Boolean,
// Blob (unused) We get: DbResult (Null, String, i64, f64, Vec<u8>), which
// matches SQLite documentation
message SqlValue {
oneof Data {
string stringValue = 1;
int64 longValue = 2;
double doubleValue = 3;
bytes blobValue = 4;
}
}
message Row {
repeated SqlValue fields = 1;
}
message DbResult {
repeated Row rows = 1;
}
message DbResponse {
DbResult result = 1;
int32 sequenceNumber = 2;
int32 rowCount = 3;
int64 startIndex = 4;
}
message GetNextResultPageRequest {
int32 sequence = 1;
int64 index = 2;
}
message GetActiveSequenceNumbersResponse {
repeated int32 numbers = 1;
}