getEmptyProtoValueForType returns an empty protobuf value of the specified type. It takes a base.AttributeType as input and generates an empty protobuf Any message containing a default value for that type.
(typ base.AttributeType)
| 151 | // It takes a base.AttributeType as input and generates an empty protobuf Any message |
| 152 | // containing a default value for that type. |
| 153 | func getEmptyProtoValueForType(typ base.AttributeType) (*anypb.Any, error) { |
| 154 | switch typ { |
| 155 | case base.AttributeType_ATTRIBUTE_TYPE_STRING: |
| 156 | // Create an empty protobuf String message |
| 157 | value, err := anypb.New(&base.StringValue{Data: ""}) |
| 158 | if err != nil { |
| 159 | return nil, err |
| 160 | } |
| 161 | return value, nil |
| 162 | |
| 163 | case base.AttributeType_ATTRIBUTE_TYPE_STRING_ARRAY: |
| 164 | // Create an empty protobuf StringArray message |
| 165 | value, err := anypb.New(&base.StringArrayValue{Data: []string{}}) |
| 166 | if err != nil { |
| 167 | return nil, err |
| 168 | } |
| 169 | return value, nil |
| 170 | |
| 171 | case base.AttributeType_ATTRIBUTE_TYPE_INTEGER: |
| 172 | // Create an empty protobuf Integer message |
| 173 | value, err := anypb.New(&base.IntegerValue{Data: 0}) |
| 174 | if err != nil { |
| 175 | return nil, err |
| 176 | } |
| 177 | return value, nil |
| 178 | |
| 179 | case base.AttributeType_ATTRIBUTE_TYPE_INTEGER_ARRAY: |
| 180 | // Create an empty protobuf IntegerArray message |
| 181 | value, err := anypb.New(&base.IntegerArrayValue{Data: []int32{}}) |
| 182 | if err != nil { |
| 183 | return nil, err |
| 184 | } |
| 185 | return value, nil |
| 186 | |
| 187 | case base.AttributeType_ATTRIBUTE_TYPE_DOUBLE: |
| 188 | // Create an empty protobuf Double message |
| 189 | value, err := anypb.New(&base.DoubleValue{Data: 0.0}) |
| 190 | if err != nil { |
| 191 | return nil, err |
| 192 | } |
| 193 | return value, nil |
| 194 | |
| 195 | case base.AttributeType_ATTRIBUTE_TYPE_DOUBLE_ARRAY: |
| 196 | // Create an empty protobuf DoubleArray message |
| 197 | value, err := anypb.New(&base.DoubleArrayValue{Data: []float64{}}) |
| 198 | if err != nil { |
| 199 | return nil, err |
| 200 | } |
| 201 | return value, nil |
| 202 | |
| 203 | case base.AttributeType_ATTRIBUTE_TYPE_BOOLEAN: |
| 204 | // Create an empty protobuf Boolean message with a default value of false |
| 205 | value, err := anypb.New(&base.BooleanValue{Data: false}) |
| 206 | if err != nil { |
| 207 | return nil, err |
| 208 | } |
| 209 | return value, nil |
| 210 |
no outgoing calls
no test coverage detected