Files
tasks/common/persistence/data_blob.go
David ReissandGitHub 33b2175acc Allow empty data in DataBlob (#8181)
## What changed?
Remove check for zero-length data in NewDataBlob.

## Why?
Zero-length data is a valid encoding for some encodings, e.g. proto3.
NewDataBlob should not have an opinion on the length of data.

## How did you test it?
- [ ] built
- [ ] run locally and tested manually
- [ ] covered by existing tests
- [ ] added new unit test(s)
- [ ] added new functional test(s)

## Potential risks
Some code may be making assumptions about this behavior.
2025-08-18 15:29:17 -07:00

22 lines
635 B
Go

package persistence
import (
commonpb "go.temporal.io/api/common/v1"
enumspb "go.temporal.io/api/enums/v1"
)
// NewDataBlob returns a new DataBlob.
// TODO: return an UnknowEncodingType error with the actual type string when encodingTypeStr is invalid
func NewDataBlob(data []byte, encodingTypeStr string) *commonpb.DataBlob {
encodingType, err := enumspb.EncodingTypeFromString(encodingTypeStr)
if err != nil {
// encodingTypeStr not valid, an error will be returned on deserialization
encodingType = enumspb.ENCODING_TYPE_UNSPECIFIED
}
return &commonpb.DataBlob{
Data: data,
EncodingType: encodingType,
}
}