grpc / grpc-dart

The Dart language implementation of gRPC.
https://pub.dev/packages/grpc
Apache License 2.0
860 stars 271 forks source link

Converting embedded messages that are encoded as Structs. #579

Closed tobytraylor closed 2 years ago

tobytraylor commented 2 years ago

The proto model for log entry data within the google.events.cloud.audit event contains other models without referencing the message definitions. In this case it references a CreateDocumentRequest from google.firestore but it encodes it as a struct. Is there anything that can be done to keep from having to do a json roundtrip to convert the Struct to the CreateDocumentRequest. Or is there a way to configure the cloud event to initially decode into the message being used so it never becomes a struct. Feels like i must be missing something here if all google audit events have to be manually decoded into the correct message.

final logEntryData = LogEntryData.create()..mergeFromProto3Json(json.decode(message));
final payload = logEntryData.protoPayload;
final requestAsStruct = payload.request;

final requestAsMessage = CreateDocumentRequest.create()
      ..mergeFromProto3Json(requestAsStruct.toProto3Json(), ignoreUnknownFields: true);
mraleph commented 2 years ago

This question has nothing to do with grpc-dart library.

That being said - it's represented as a Struct because it is a sanitised version of the original request (e.g. some fields which are otherwise required might be omitted for various reasons).