Skip to content

Commit 6fcd72a

Browse files
committed
feat(bigtable): add "TypeUnspecified" to represent an unspecified type
1 parent da8737e commit 6fcd72a

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

bigtable/type.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ func Equal(a, b Type) bool {
5656
return proto.Equal(a.proto(), b.proto())
5757
}
5858

59+
// TypeUnspecified represents the absence of a type.
60+
type TypeUnspecified struct{}
61+
62+
func (n TypeUnspecified) proto() *btapb.Type {
63+
return &btapb.Type{}
64+
}
65+
5966
type unknown[T interface{}] struct {
6067
wrapped *T
6168
}
@@ -231,7 +238,9 @@ func ProtoToType(pb *btapb.Type) Type {
231238
if pb == nil {
232239
return unknown[btapb.Type]{wrapped: nil}
233240
}
234-
241+
if pb.Kind == nil {
242+
return TypeUnspecified{}
243+
}
235244
switch t := pb.Kind.(type) {
236245
case *btapb.Type_Int64Type:
237246
return int64ProtoToType(t.Int64Type)

bigtable/type_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,13 @@ func TestNilChecks(t *testing.T) {
221221
t.Errorf("got: %T, wanted unknown[btapb.Type]", val)
222222
}
223223
}
224+
225+
func TestTypeUnspecified(t *testing.T) {
226+
pb := &btapb.Type{}
227+
tpe := ProtoToType(pb)
228+
assertType(t, tpe, &btapb.Type{})
229+
expect := TypeUnspecified{}
230+
if tpe != expect {
231+
t.Errorf("got: %v, wanted: %v", tpe, expect)
232+
}
233+
}

0 commit comments

Comments
 (0)