Protobuf data structin Rust, for example, the
TextBlockEventdefined in event_map.rs and
ExportDatadefined in entities.rs.
#[event(input = Input struct, output = Output struct)]is used to generate the dart function.
Input structmean the function receive the input parameter's type.
Output structmean the function's return value's type
PBkeyword appended to every struct. We use the
PBkeyword to identify this struct is in protobuf format.
ProtoBuf, is used to mark this struct is going to generate the protobuf struct.
code genprocess will parse the proto_input in order to generate the struct/enum.
code genprocess will parse the file in order to generate the dart event class.
code genprocess 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=PATHto 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.
Part One. The function
export_handlerwill get called when the
ExportDocumentevent happened. The calling route as the picture shown below.
TextBlockEventExportDocumentclass, and call
ExportPayloadPBto the module that registers as the event handler.
ExportPayloadPBwill try to parse into
ExportParams. It will return an error if there are illegal fields in it.
view_idfield in the
ExportPayloadPBshould not be empty.
export_handlerfunction gets called with the event and data.
export_handlerwill return 'ExportDataPB', which will be post to the frontend.