@@ -29,6 +29,7 @@ use nativelink_proto::google::rpc::Status;
29
29
use prost:: bytes:: Bytes ;
30
30
use prost:: Message ;
31
31
use prost_types:: Any ;
32
+ use serde:: ser:: Error as SerdeError ;
32
33
use serde:: { Deserialize , Serialize } ;
33
34
use uuid:: Uuid ;
34
35
@@ -746,7 +747,7 @@ impl Default for ActionResult {
746
747
// TODO(allada) Remove the need for clippy argument by making the ActionResult and ProtoActionResult
747
748
// a Box.
748
749
/// The execution status/stage. This should match `ExecutionStage::Value` in `remote_execution.proto`.
749
- #[ derive( PartialEq , Debug , Clone ) ]
750
+ #[ derive( PartialEq , Debug , Clone , Serialize , Deserialize ) ]
750
751
#[ allow( clippy:: large_enum_variant) ]
751
752
pub enum ActionStage {
752
753
/// Stage is unknown.
@@ -762,9 +763,22 @@ pub enum ActionStage {
762
763
/// Worker completed the work with result.
763
764
Completed ( ActionResult ) ,
764
765
/// Result was found from cache, don't decode the proto just to re-encode it.
766
+ #[ serde( serialize_with = "serialize_proto_result" , skip_deserializing) ]
767
+ // The serialization step decodes this to an ActionResult which is serializable.
768
+ // Since it will always be serialized as an ActionResult, we do not need to support
769
+ // deserialization on this type at all.
770
+ // In theory, serializing this should never happen so performance shouldn't be affected.
765
771
CompletedFromCache ( ProtoActionResult ) ,
766
772
}
767
773
774
+ fn serialize_proto_result < S > ( v : & ProtoActionResult , serializer : S ) -> Result < S :: Ok , S :: Error >
775
+ where
776
+ S : serde:: Serializer ,
777
+ {
778
+ let s = ActionResult :: try_from ( v. clone ( ) ) . map_err ( S :: Error :: custom) ?;
779
+ s. serialize ( serializer)
780
+ }
781
+
768
782
impl ActionStage {
769
783
pub const fn has_action_result ( & self ) -> bool {
770
784
match self {
@@ -1075,7 +1089,7 @@ where
1075
1089
1076
1090
/// Current state of the action.
1077
1091
/// This must be 100% compatible with `Operation` in `google/longrunning/operations.proto`.
1078
- #[ derive( PartialEq , Debug , Clone ) ]
1092
+ #[ derive( PartialEq , Debug , Clone , Serialize , Deserialize ) ]
1079
1093
pub struct ActionState {
1080
1094
pub stage : ActionStage ,
1081
1095
pub id : OperationId ,
0 commit comments