def bufferize(worker: AbstractWorker, placeholder: "PlaceHolder") -> PlaceholderPB: """Takes the attributes of a PlaceHolder and saves them in a Protobuf message. Args: worker: the worker doing the serialization placeholder: a PlaceHolder. Returns: PlaceholderPB: a Protobuf message holding the unique attributes of the PlaceHolder. """ protobuf_placeholder = PlaceholderPB() syft.serde.protobuf.proto.set_protobuf_id(protobuf_placeholder.id, placeholder.id.value) protobuf_placeholder.tags.extend(placeholder.tags) if placeholder.description: protobuf_placeholder.description = placeholder.description if placeholder.expected_shape: protobuf_placeholder.expected_shape.dims.extend( placeholder.expected_shape) return protobuf_placeholder
def _object2proto(self) -> PlaceholderPB: """Returns a protobuf serialization of self. As a requirement of all objects which inherit from Serializable, this method transforms the current object into the corresponding Protobuf object so that it can be further serialized. :return: returns a protobuf object :rtype: ObjectWithID_PB .. note:: This method is purely an internal method. Please use object.serialize() or one of the other public serialization methods if you wish to serialize an object. """ protobuf_placeholder = PlaceholderPB() set_protobuf_id(protobuf_placeholder.id, self.id.value) protobuf_placeholder.tags.extend(self.tags) if self.description: protobuf_placeholder.description = self.description if self.expected_shape: protobuf_placeholder.expected_shape.dims.extend( self.expected_shape) return protobuf_placeholder
def bufferize(worker: AbstractWorker, tensor: "PlaceHolder") -> PlaceholderPB: """Takes the attributes of a PlaceHolder and saves them in a Protobuf message. Args: worker: the worker doing the serialization tensor: a PlaceHolder. Returns: PlaceholderPB: a Protobuf message holding the unique attributes of the PlaceHolder. """ protobuf_placeholder = PlaceholderPB() syft.serde.protobuf.proto.set_protobuf_id(protobuf_placeholder.id, tensor.id) protobuf_placeholder.tags.extend(tensor.tags) if tensor.description: protobuf_placeholder.description = tensor.description return protobuf_placeholder