all: rename Vector as List
The terminology Vector does not occur in protobuf documentation at all,
so we should rename the Go use of the term to something more recognizable.
As such, all instances that match the regexp "[Vv]ect(or)?" were replaced.
The C++ documentation uses the term "Repeated", which is a reasonable name.
However, the term became overloaded in 2014, when maps were added as a feature
and implementated under the hood as repeated fields. This is confusing as it
means "repeated" could either refer to repeated fields proper (i.e., explicitly
marked with the "repeated" label in the proto file) or map fields. In the case
of the C++ reflective API, this is not a problem since repeated fields proper
and map fields are interacted with through the same RepeatedField type.
In Go, we do not use a single type to handle both types of repeated fields:
1) We are coming up with the Go protobuf reflection API for the first time
and so do not need to piggy-back on the repeated fields API to remain backwards
compatible since no former usages of Go protobuf reflection exists.
2) Map fields are commonly represented in Go as the Go map type, which do not
preserve ordering information. As such it is fundamentally impossible to present
an unordered map as a consistently ordered list. Thus, Go needs two different
interfaces for lists and maps.
Given the above situation, "Repeated" is not a great term to use since it
refers to two different things (when we only want one of the meanings).
To distinguish between the two, we'll use the terms "List" and "Map" instead.
There is some precedence for the term "List" in the protobuf codebase
(e.g., "getRepeatedInt32List").
Change-Id: Iddcdb6b78e1e60c14fa4ca213c15f45e214b967b
Reviewed-on: https://go-review.googlesource.com/c/149657
Reviewed-by: Damien Neil <dneil@google.com>
diff --git a/internal/impl/legacy_extension.go b/internal/impl/legacy_extension.go
index cff89f7..ba3a614 100644
--- a/internal/impl/legacy_extension.go
+++ b/internal/impl/legacy_extension.go
@@ -47,7 +47,7 @@
}
t := legacyExtensionTypeOf(x.desc)
if t.Cardinality() == pref.Repeated {
- return legacyExtensionValueOf(x.val, t).Vector().Len() > 0
+ return legacyExtensionValueOf(x.val, t).List().Len() > 0
}
return true
}
@@ -60,7 +60,7 @@
t := legacyExtensionTypeOf(x.desc)
if x.val == nil {
if t.Cardinality() == pref.Repeated {
- // TODO: What is the zero value for Vectors?
+ // TODO: What is the zero value for Lists?
// TODO: This logic is racy.
v := t.ValueOf(t.New())
x.val = legacyExtensionInterfaceOf(v, t)
@@ -305,10 +305,10 @@
if reflect.TypeOf(v) != xt2.typ {
panic(fmt.Sprintf("invalid type: got %T, want %v", v, xt2.typ))
}
- return pref.ValueOf(pvalue.VectorOf(v, conv))
+ return pref.ValueOf(pvalue.ListOf(v, conv))
}
xt2.interfaceOf = func(pv pref.Value) interface{} {
- v := pv.Vector().(pvalue.Unwrapper).Unwrap()
+ v := pv.List().(pvalue.Unwrapper).Unwrap()
if reflect.TypeOf(v) != xt2.typ {
panic(fmt.Sprintf("invalid type: got %T, want %v", v, xt2.typ))
}
diff --git a/internal/impl/legacy_test.go b/internal/impl/legacy_test.go
index 9f8456e..7e95ec9 100644
--- a/internal/impl/legacy_test.go
+++ b/internal/impl/legacy_test.go
@@ -776,7 +776,7 @@
}
// Check that getting the zero value returns the default value for scalars,
- // nil for singular messages, and an empty vector for repeated fields.
+ // nil for singular messages, and an empty list for repeated fields.
defaultValues := []interface{}{
bool(true),
int32(-12345),
@@ -816,7 +816,7 @@
}
}
- // Set some values and append to values to the vectors.
+ // Set some values and append to values to the lists.
m1 := &proto2_20180125.Message_ChildMessage{F1: protoV1.String("m1")}
m2 := &proto2_20180125.Message_ChildMessage{F1: protoV1.String("m2")}
setValues := []interface{}{
@@ -842,7 +842,7 @@
}
for i, xt := range extensions[len(extensions)/2:] {
v := extensions[i].ValueOf(setValues[i])
- fs.Get(xt.Number()).Vector().Append(v)
+ fs.Get(xt.Number()).List().Append(v)
}
// Get the values and check for equality.
diff --git a/internal/impl/message.go b/internal/impl/message.go
index 57ca93a..4d96719 100644
--- a/internal/impl/message.go
+++ b/internal/impl/message.go
@@ -132,7 +132,7 @@
case fd.IsMap():
fi = fieldInfoForMap(fd, fs)
case fd.Cardinality() == pref.Repeated:
- fi = fieldInfoForVector(fd, fs)
+ fi = fieldInfoForList(fd, fs)
case fd.Kind() == pref.MessageKind || fd.Kind() == pref.GroupKind:
fi = fieldInfoForMessage(fd, fs)
default:
diff --git a/internal/impl/message_field.go b/internal/impl/message_field.go
index 7f8d49f..ea1c1eb 100644
--- a/internal/impl/message_field.go
+++ b/internal/impl/message_field.go
@@ -134,7 +134,7 @@
}
}
-func fieldInfoForVector(fd pref.FieldDescriptor, fs reflect.StructField) fieldInfo {
+func fieldInfoForList(fd pref.FieldDescriptor, fs reflect.StructField) fieldInfo {
ft := fs.Type
if ft.Kind() != reflect.Slice {
panic(fmt.Sprintf("invalid type: got %v, want slice kind", ft))
@@ -149,11 +149,11 @@
},
get: func(p pointer) pref.Value {
v := p.apply(fieldOffset).asType(fs.Type).Interface()
- return pref.ValueOf(pvalue.VectorOf(v, conv))
+ return pref.ValueOf(pvalue.ListOf(v, conv))
},
set: func(p pointer, v pref.Value) {
rv := p.apply(fieldOffset).asType(fs.Type).Elem()
- rv.Set(reflect.ValueOf(v.Vector().(pvalue.Unwrapper).Unwrap()).Elem())
+ rv.Set(reflect.ValueOf(v.List().(pvalue.Unwrapper).Unwrap()).Elem())
},
clear: func(p pointer) {
rv := p.apply(fieldOffset).asType(fs.Type).Elem()
@@ -161,7 +161,7 @@
},
mutable: func(p pointer) pref.Mutable {
v := p.apply(fieldOffset).asType(fs.Type).Interface()
- return pvalue.VectorOf(v, conv)
+ return pvalue.ListOf(v, conv)
},
}
}
diff --git a/internal/impl/message_test.go b/internal/impl/message_test.go
index 3f38671..69b5764 100644
--- a/internal/impl/message_test.go
+++ b/internal/impl/message_test.go
@@ -40,20 +40,20 @@
MyString string
MyBytes []byte
- VectorStrings []MyString
- VectorBytes []MyBytes
+ ListStrings []MyString
+ ListBytes []MyBytes
MapStrings map[MyString]MyString
MapBytes map[MyString]MyBytes
)
-// List of test operations to perform on messages, vectors, or maps.
+// List of test operations to perform on messages, lists, or maps.
type (
- messageOp interface{} // equalMessage | hasFields | getFields | setFields | clearFields | vectorFields | mapFields
+ messageOp interface{} // equalMessage | hasFields | getFields | setFields | clearFields | listFields | mapFields
messageOps []messageOp
- vectorOp interface{} // equalVector | lenVector | getVector | setVector | appendVector | truncVector
- vectorOps []vectorOp
+ listOp interface{} // equalList | lenList | getList | setList | appendList | truncList
+ listOps []listOp
mapOp interface{} // equalMap | lenMap | hasMap | getMap | setMap | clearMap | rangeMap
mapOps []mapOp
@@ -66,20 +66,20 @@
getFields map[pref.FieldNumber]pref.Value
setFields map[pref.FieldNumber]pref.Value
clearFields map[pref.FieldNumber]bool
- vectorFields map[pref.FieldNumber]vectorOps
+ listFields map[pref.FieldNumber]listOps
mapFields map[pref.FieldNumber]mapOps
messageFields map[pref.FieldNumber]messageOps
// TODO: Mutable, Range, ExtensionTypes
)
-// Test operations performed on a vector.
+// Test operations performed on a list.
type (
- equalVector pref.Vector
- lenVector int
- getVector map[int]pref.Value
- setVector map[int]pref.Value
- appendVector []pref.Value
- truncVector int
+ equalList pref.List
+ lenList int
+ getList map[int]pref.Value
+ setList map[int]pref.Value
+ appendList []pref.Value
+ truncList int
// TODO: Mutable, MutableAppend
)
@@ -318,10 +318,10 @@
MyBytes1 []MyBytes `protobuf:"14"`
MyBytes2 []MyString `protobuf:"15"`
- MyStrings3 VectorStrings `protobuf:"16"`
- MyStrings4 VectorBytes `protobuf:"17"`
- MyBytes3 VectorBytes `protobuf:"18"`
- MyBytes4 VectorStrings `protobuf:"19"`
+ MyStrings3 ListStrings `protobuf:"16"`
+ MyStrings4 ListBytes `protobuf:"17"`
+ MyBytes3 ListBytes `protobuf:"18"`
+ MyBytes4 ListStrings `protobuf:"19"`
}
var listScalarsType = MessageType{Type: ptype.GoMessage(
@@ -386,10 +386,10 @@
MyBytes1: []MyBytes{[]byte("14"), nil, []byte("fourteen")},
MyBytes2: []MyString{"15", "", "fifteen"},
- MyStrings3: VectorStrings{"16", "", "sixteen"},
- MyStrings4: VectorBytes{[]byte("17"), nil, []byte("seventeen")},
- MyBytes3: VectorBytes{[]byte("18"), nil, []byte("eighteen")},
- MyBytes4: VectorStrings{"19", "", "nineteen"},
+ MyStrings3: ListStrings{"16", "", "sixteen"},
+ MyStrings4: ListBytes{[]byte("17"), nil, []byte("seventeen")},
+ MyBytes3: ListBytes{[]byte("18"), nil, []byte("eighteen")},
+ MyBytes4: ListStrings{"19", "", "nineteen"},
}
wantFS := want.KnownFields()
@@ -397,53 +397,53 @@
hasFields{1: false, 2: false, 3: false, 4: false, 5: false, 6: false, 7: false, 8: false, 9: false, 10: false, 11: false, 12: false, 13: false, 14: false, 15: false, 16: false, 17: false, 18: false, 19: false},
getFields{1: emptyFS.Get(1), 3: emptyFS.Get(3), 5: emptyFS.Get(5), 7: emptyFS.Get(7), 9: emptyFS.Get(9), 11: emptyFS.Get(11), 13: emptyFS.Get(13), 15: emptyFS.Get(15), 17: emptyFS.Get(17), 19: emptyFS.Get(19)},
setFields{1: wantFS.Get(1), 3: wantFS.Get(3), 5: wantFS.Get(5), 7: wantFS.Get(7), 9: wantFS.Get(9), 11: wantFS.Get(11), 13: wantFS.Get(13), 15: wantFS.Get(15), 17: wantFS.Get(17), 19: wantFS.Get(19)},
- vectorFields{
+ listFields{
2: {
- lenVector(0),
- appendVector{V(int32(2)), V(int32(math.MinInt32)), V(int32(math.MaxInt32))},
- getVector{0: V(int32(2)), 1: V(int32(math.MinInt32)), 2: V(int32(math.MaxInt32))},
- equalVector(wantFS.Get(2).Vector()),
+ lenList(0),
+ appendList{V(int32(2)), V(int32(math.MinInt32)), V(int32(math.MaxInt32))},
+ getList{0: V(int32(2)), 1: V(int32(math.MinInt32)), 2: V(int32(math.MaxInt32))},
+ equalList(wantFS.Get(2).List()),
},
4: {
- appendVector{V(uint32(0)), V(uint32(0)), V(uint32(0))},
- setVector{0: V(uint32(4)), 1: V(uint32(math.MaxUint32 / 2)), 2: V(uint32(math.MaxUint32))},
- lenVector(3),
+ appendList{V(uint32(0)), V(uint32(0)), V(uint32(0))},
+ setList{0: V(uint32(4)), 1: V(uint32(math.MaxUint32 / 2)), 2: V(uint32(math.MaxUint32))},
+ lenList(3),
},
6: {
- appendVector{V(float32(6)), V(float32(math.SmallestNonzeroFloat32)), V(float32(math.NaN())), V(float32(math.MaxFloat32))},
- equalVector(wantFS.Get(6).Vector()),
+ appendList{V(float32(6)), V(float32(math.SmallestNonzeroFloat32)), V(float32(math.NaN())), V(float32(math.MaxFloat32))},
+ equalList(wantFS.Get(6).List()),
},
8: {
- appendVector{V(""), V(""), V(""), V(""), V(""), V("")},
- lenVector(6),
- setVector{0: V("8"), 2: V("eight")},
- truncVector(3),
- equalVector(wantFS.Get(8).Vector()),
+ appendList{V(""), V(""), V(""), V(""), V(""), V("")},
+ lenList(6),
+ setList{0: V("8"), 2: V("eight")},
+ truncList(3),
+ equalList(wantFS.Get(8).List()),
},
10: {
- appendVector{V([]byte(nil)), V([]byte(nil))},
- setVector{0: V([]byte("10"))},
- appendVector{V([]byte("wrong"))},
- setVector{2: V([]byte("ten"))},
- equalVector(wantFS.Get(10).Vector()),
+ appendList{V([]byte(nil)), V([]byte(nil))},
+ setList{0: V([]byte("10"))},
+ appendList{V([]byte("wrong"))},
+ setList{2: V([]byte("ten"))},
+ equalList(wantFS.Get(10).List()),
},
12: {
- appendVector{V("12"), V("wrong"), V("twelve")},
- setVector{1: V("")},
- equalVector(wantFS.Get(12).Vector()),
+ appendList{V("12"), V("wrong"), V("twelve")},
+ setList{1: V("")},
+ equalList(wantFS.Get(12).List()),
},
14: {
- appendVector{V([]byte("14")), V([]byte(nil)), V([]byte("fourteen"))},
- equalVector(wantFS.Get(14).Vector()),
+ appendList{V([]byte("14")), V([]byte(nil)), V([]byte("fourteen"))},
+ equalList(wantFS.Get(14).List()),
},
16: {
- appendVector{V("16"), V(""), V("sixteen"), V("extra")},
- truncVector(3),
- equalVector(wantFS.Get(16).Vector()),
+ appendList{V("16"), V(""), V("sixteen"), V("extra")},
+ truncList(3),
+ equalList(wantFS.Get(16).List()),
},
18: {
- appendVector{V([]byte("18")), V([]byte(nil)), V([]byte("eighteen"))},
- equalVector(wantFS.Get(18).Vector()),
+ appendList{V([]byte("18")), V([]byte(nil)), V([]byte("eighteen"))},
+ equalList(wantFS.Get(18).List()),
},
},
hasFields{1: true, 2: true, 3: true, 4: true, 5: true, 6: true, 7: true, 8: true, 9: true, 10: true, 11: true, 12: true, 13: true, 14: true, 15: true, 16: true, 17: true, 18: true, 19: true},
@@ -828,7 +828,7 @@
cmp.Transformer("UnwrapValue", func(v pref.Value) interface{} {
return v.Interface()
}),
- cmp.Transformer("UnwrapVector", func(v pref.Vector) interface{} {
+ cmp.Transformer("UnwrapList", func(v pref.List) interface{} {
return v.(interface{ Unwrap() interface{} }).Unwrap()
}),
cmp.Transformer("UnwrapMap", func(m pref.Map) interface{} {
@@ -874,10 +874,10 @@
fs.Clear(n)
}
}
- case vectorFields:
+ case listFields:
for n, tt := range op {
p.Push(int(n))
- testVectors(t, p, fs.Mutable(n).(pref.Vector), tt)
+ testLists(t, p, fs.Mutable(n).(pref.List), tt)
p.Pop()
}
case mapFields:
@@ -893,36 +893,36 @@
}
}
-func testVectors(t *testing.T, p path, v pref.Vector, tt vectorOps) {
+func testLists(t *testing.T, p path, v pref.List, tt listOps) {
for i, op := range tt {
p.Push(i)
switch op := op.(type) {
- case equalVector:
+ case equalList:
if diff := cmp.Diff(op, v, cmpOpts); diff != "" {
- t.Errorf("operation %v, vector mismatch (-want, +got):\n%s", p, diff)
+ t.Errorf("operation %v, list mismatch (-want, +got):\n%s", p, diff)
}
- case lenVector:
+ case lenList:
if got, want := v.Len(), int(op); got != want {
- t.Errorf("operation %v, Vector.Len = %d, want %d", p, got, want)
+ t.Errorf("operation %v, List.Len = %d, want %d", p, got, want)
}
- case getVector:
+ case getList:
got := map[int]pref.Value{}
want := map[int]pref.Value(op)
for n := range want {
got[n] = v.Get(n)
}
if diff := cmp.Diff(want, got, cmpOpts); diff != "" {
- t.Errorf("operation %v, Vector.Get mismatch (-want, +got):\n%s", p, diff)
+ t.Errorf("operation %v, List.Get mismatch (-want, +got):\n%s", p, diff)
}
- case setVector:
+ case setList:
for n, e := range op {
v.Set(n, e)
}
- case appendVector:
+ case appendList:
for _, e := range op {
v.Append(e)
}
- case truncVector:
+ case truncList:
v.Truncate(int(op))
default:
t.Fatalf("operation %v, invalid operation: %T", p, op)