Skip to content

Commit

Permalink
SDK update
Browse files Browse the repository at this point in the history
GitOrigin-RevId: b803f0c857352d4035b8595b881933a727604adf
  • Loading branch information
copybara-github authored and insrc-copybara[bot] committed Aug 2, 2024
1 parent 4999a44 commit b19b79e
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions intrinsic/assets/typeutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,38 @@ var (
regexEnumNameAssetTypeIdx = slices.Index(regexEnumNameGroups, "asset_type")
)

// AllAssetTypes returns all asset types.
func AllAssetTypes() []atypepb.AssetType {
var assetTypes []atypepb.AssetType
for _, i := range atypepb.AssetType_value {
assetType := atypepb.AssetType(i)
if assetType == atypepb.AssetType_ASSET_TYPE_UNSPECIFIED {
continue
}
assetTypes = append(assetTypes, assetType)
}
return assetTypes
}

// UniqueAssetTypes returns the unique asset types from a list.
//
// Order is arbitrary, and the unspecified asset type is ignored.
func UniqueAssetTypes(assetTypes []atypepb.AssetType) []atypepb.AssetType {
assetTypesMap := make(map[atypepb.AssetType]bool)
for _, assetType := range assetTypes {
if assetType != atypepb.AssetType_ASSET_TYPE_UNSPECIFIED {
assetTypesMap[assetType] = true
}
}
uniqueAssetTypes := make([]atypepb.AssetType, len(assetTypesMap))
i := 0
for assetType := range assetTypesMap {
uniqueAssetTypes[i] = assetType
i++
}
return uniqueAssetTypes
}

// NameFromAssetType returns the name of an asset type.
func NameFromAssetType(a atypepb.AssetType) string {
if name, ok := customAssetTypeToName[a]; ok {
Expand Down

0 comments on commit b19b79e

Please sign in to comment.