Encode a blob for a given task category to a human-readable format by deserializing the blob into a proto message and then pretty-printing it using protojson.
(writer io.Writer, categoryID int, blob *commonpb.DataBlob)
| 87 | // Encode a blob for a given task category to a human-readable format by deserializing the blob into a proto message and |
| 88 | // then pretty-printing it using protojson. |
| 89 | func (e *ProtoTaskBlobEncoder) Encode(writer io.Writer, categoryID int, blob *commonpb.DataBlob) error { |
| 90 | message, err := e.deserializer.Deserialize(categoryID, blob) |
| 91 | if err != nil { |
| 92 | return fmt.Errorf("failed to deserialize task blob: %w", err) |
| 93 | } |
| 94 | bs, err := jsonpbMarshaler.Marshal(message) |
| 95 | if err != nil { |
| 96 | return fmt.Errorf("failed to marshal task blob: %w", err) |
| 97 | } |
| 98 | _, err = writer.Write(bs) |
| 99 | if err != nil { |
| 100 | return fmt.Errorf("failed to write marshalled task blob: %w", err) |
| 101 | } |
| 102 | return nil |
| 103 | } |
| 104 | |
| 105 | // Encode the task by calling the function. |
| 106 | func (e TaskBlobEncoderFn) Encode(writer io.Writer, taskCategoryID int, blob *commonpb.DataBlob) error { |