MCPcopy Create free account
hub / github.com/temporalio/temporal / ExampleTaskBlobEncoder

Function ExampleTaskBlobEncoder

tools/tdbg/task_encoder_test.go:39–83  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

37)
38
39func ExampleTaskBlobEncoder() {
40 var output bytes.Buffer
41 app := tdbg.NewCliApp(func(params *tdbg.Params) {
42 params.Writer = &output
43 stockEncoder := params.TaskBlobEncoder
44 params.TaskBlobEncoder = tdbg.TaskBlobEncoderFn(func(
45 writer io.Writer,
46 taskCategoryID int,
47 blob *commonpb.DataBlob,
48 ) error {
49 if taskCategoryID == customCategory.ID() {
50 _, err := writer.Write(append([]byte("hello, "), blob.Data...))
51 return err
52 }
53 return stockEncoder.Encode(writer, taskCategoryID, blob)
54 })
55 })
56 file, err := os.CreateTemp("", "*")
57 if err != nil {
58 panic(err)
59 }
60 defer func() {
61 if err := os.Remove(file.Name()); err != nil {
62 panic(err)
63 }
64 }()
65 _, err = file.Write([]byte("\"world\""))
66 if err != nil {
67 panic(err)
68 }
69 err = app.Run([]string{
70 "tdbg", "decode", "task",
71 "--" + tdbg.FlagEncoding, enumspb.ENCODING_TYPE_JSON.String(),
72 "--" + tdbg.FlagTaskCategoryID, strconv.Itoa(customCategory.ID()),
73 "--" + tdbg.FlagBinaryFile, file.Name(),
74 })
75 if err != nil {
76 panic(err)
77 }
78
79 fmt.Println(output.String())
80
81 // Output:
82 // hello, "world"
83}
84
85// Tests the [tdbg.NewPredefinedTaskBlobDeserializer] function.
86func TestPredefinedTasks(t *testing.T) {

Callers

nothing calls this directly

Calls 9

NewCliAppFunction · 0.92
TaskBlobEncoderFnFuncType · 0.92
IDMethod · 0.65
WriteMethod · 0.65
EncodeMethod · 0.65
RemoveMethod · 0.65
NameMethod · 0.65
RunMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected