Commit 302da4f4 authored by Eric Myhre's avatar Eric Myhre

s/Object/Struct/g

ISTM that since we're talking about raw data more so than "objects" in
any kind of Alan-Kay/sending-messages/OOP sort of way, calling it
"struct" is more accurate communication.

(It's also a lot less likely to be confusing when mentioned in the same
context as javascript, since "object" and "map" tend to be collisiony
terms there; whereas "struct" just doensn't really have any prior
associations in that community as far as I know.)
Signed-off-by: default avatarEric Myhre <hash@exultant.us>
parent b066cf1b
......@@ -20,7 +20,7 @@ type TypeName string
// TypeList
// TypeLink
// TypeUnion
// TypeObject
// TypeStruct
// TypeEnum
//
// are all of the kinds of Type.
......@@ -58,7 +58,7 @@ var (
_ Type = TypeList{}
_ Type = TypeLink{}
_ Type = TypeUnion{}
_ Type = TypeObject{}
_ Type = TypeStruct{}
_ Type = TypeEnum{}
)
......@@ -120,13 +120,13 @@ var (
UnionStyle_Inline = UnionStyle{"inline"}
)
type TypeObject struct {
type TypeStruct struct {
Name TypeName
TupleStyle bool // if true, ReprKind=Array instead of map (and optional fields are invalid!)
Fields []ObjectField
Fields []StructField
}
type ObjectField struct {
type StructField struct {
Name string
Type TypeName
Optional bool
......@@ -147,5 +147,5 @@ func (TypeMap) _Type() {}
func (TypeList) _Type() {}
func (TypeLink) _Type() {}
func (TypeUnion) _Type() {}
func (TypeObject) _Type() {}
func (TypeStruct) _Type() {}
func (TypeEnum) _Type() {}
......@@ -41,7 +41,7 @@ func (t TypeUnion) ReprKind() ipld.ReprKind {
return ipld.ReprKind_Map
}
}
func (t TypeObject) ReprKind() ipld.ReprKind {
func (t TypeStruct) ReprKind() ipld.ReprKind {
if t.tupleStyle {
return ipld.ReprKind_List
} else {
......@@ -115,8 +115,8 @@ func (t TypeUnion) UnionMembers() map[Type]struct{} {
}
// Fields returns a slice of descriptions of the object's fields.
func (t TypeObject) Fields() []ObjectField {
a := make([]ObjectField, len(t.fields))
func (t TypeStruct) Fields() []StructField {
a := make([]StructField, len(t.fields))
for i := range t.fields {
a[i] = t.fields[i]
}
......@@ -126,11 +126,11 @@ func (t TypeObject) Fields() []ObjectField {
// Name returns the string name of this field. The name is the string that
// will be used as a map key if the structure this field is a member of is
// serialized as a map representation.
func (f ObjectField) Name() string { return f.name }
func (f StructField) Name() string { return f.name }
// Type returns the Type of this field's value. Note the field may
// also be unset if it is either Optional or Nullable.
func (f ObjectField) Type() Type { return f.typ }
func (f StructField) Type() Type { return f.typ }
// IsOptional returns true if the field is allowed to be absent from the object.
// If IsOptional is false, the field may be absent from the serial representation
......@@ -138,7 +138,7 @@ func (f ObjectField) Type() Type { return f.typ }
//
// Note being optional is different than saying the value is permitted to be null!
// A field may be both nullable and optional simultaneously, or either, or neither.
func (f ObjectField) IsOptional() bool { return f.optional }
func (f StructField) IsOptional() bool { return f.optional }
// IsNullable returns true if the field value is allowed to be null.
//
......@@ -148,7 +148,7 @@ func (f ObjectField) IsOptional() bool { return f.optional }
//
// Note that a field may be both nullable and optional simultaneously,
// or either, or neither.
func (f ObjectField) IsNullable() bool { return f.nullable }
func (f StructField) IsNullable() bool { return f.nullable }
// Members returns a slice the strings which are valid inhabitants of this enum.
func (t TypeEnum) Members() []string {
......
......@@ -20,7 +20,7 @@ type TypeName string
// TypeList
// TypeLink
// TypeUnion
// TypeObject
// TypeStruct
// TypeEnum
//
// are all of the kinds of Type.
......@@ -72,7 +72,7 @@ var (
_ Type = TypeList{}
_ Type = TypeLink{}
_ Type = TypeUnion{}
_ Type = TypeObject{}
_ Type = TypeStruct{}
_ Type = TypeEnum{}
)
......@@ -139,12 +139,12 @@ var (
UnionStyle_Inline = UnionStyle{"inline"}
)
type TypeObject struct {
type TypeStruct struct {
anyType
tupleStyle bool // if true, ReprKind=Array instead of map (and optional fields are invalid!)
fields []ObjectField
fields []StructField
}
type ObjectField struct {
type StructField struct {
name string
typ Type
optional bool
......
......@@ -62,7 +62,7 @@ func validate(ts Universe, t Type, node ipld.Node, pth string) []error {
// TODO interesting case: would need resolver to keep checking.
case TypeUnion:
// TODO *several* interesting errors
case TypeObject:
case TypeStruct:
switch t2.tupleStyle {
case false: // as map!
if node.Kind() != ipld.ReprKind_Map {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment