Event
and the Protobuf data struct
in Rust, for example, the TextBlockEvent
defined in event_map.rs and ExportData
defined in entities.rs.#[event(input = Input struct, output = Output struct)]
is used to generate the dart function.Input struct
mean the function receive the input parameter's type.Output struct
mean the function's return value's typePB
keyword appended to every struct. We use the PB
keyword to identify this struct is in protobuf format.ProtoBuf
, is used to mark this struct is going to generate the protobuf struct.We use the syn to collect the AST information that will be used to generate theproto file
. If you interest in how to collect the information in details, you should check out the Procedural Macros.
code gen
process will parse the proto_input in order to generate the struct/enum.code gen
process will parse the file in order to generate the dart event class.code gen
process is embedded in the AppFlowy build process. But you can run the build process manually. Just go to the corresponding crate directory(For example, frontend/flowy-text-block), and run:cargo buil --features=dart
cargo buil -vv --features=dart
cargo:rerun-if-changed=PATH
to enable the build.rs will only run if the files were changed.The rerun-if-changed instruction tells Cargo to re-run the build script if the file at the given path has changed. Currently, Cargo only uses the filesystem last-modified timestamp to determine if the file has changed. It compares against an internal cached timestamp of when the build script last ran.
share.pb.dart
event_map.pb.dart
packages/flowy_sdk/lib/protobuf/
".share.rs
event_map.rs
xxx-crate/src/protobuf
".Part One
. The function export_handler
will get called when the ExportDocument
event happened. The calling route as the picture shown below.TextBlockEventExportDocument
class, and call send()
function.ExportPayloadPB
to bytes.event
and ExportPayloadPB
.ExportPayloadPB
to the module that registers as the event handler.ExportPayloadPB
will try to parse into ExportParams
. It will return an error if there are illegal fields in it.view_id
field in the ExportPayloadPB
should not be empty.export_handler
function gets called with the event and data.export_handler
will return 'ExportDataPB', which will be post to the frontend.