-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bindnode fixes continued #233
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ac67dd3
bindnode: finish adding details to many ErrWrongKind sites.
warpfork 9f6c999
bindnode: iterating representation level of maps must continue to yie…
warpfork a5c9d6e
bindnode: critical that union member setting happens before finisher …
warpfork 9d26d28
bindnode: mark todo about fragility around unions.
warpfork 575b958
bindnode: iterating representation level of lists must continue to yi…
warpfork 60ca8d9
facades: UnmarshalStreaming should stop massaging data after an error.
warpfork 5dcbc68
bindnode: asking a kinded union representation what its kind is shoul…
warpfork eba8e56
bindnode: don't go questing for a representation node just to switch …
warpfork File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,8 +53,8 @@ func (w *_nodeRepr) Kind() datamodel.Kind { | |
return datamodel.Kind_Map | ||
case schema.UnionRepresentation_Kinded: | ||
haveIdx, _ := unionMember(w.val) | ||
mtyp := w.schemaType.(*schema.TypeUnion).Members()[haveIdx] | ||
return mtyp.TypeKind().ActsLike() | ||
mtyp := w.schemaType.(*schema.TypeUnion).Members()[haveIdx] // TODO this is fragile: panics with index-out-of-range if the user has nil'd all fields. | ||
return mtyp.RepresentationBehavior() | ||
case schema.UnionRepresentation_Stringprefix: | ||
return datamodel.Kind_String | ||
case nil: | ||
|
@@ -183,9 +183,10 @@ func (w *_nodeRepr) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, | |
return w.LookupByIndex(idx) | ||
} | ||
return nil, datamodel.ErrWrongKind{ | ||
TypeName: w.schemaType.Name().String(), | ||
MethodName: "LookupBySegment", | ||
// TODO | ||
TypeName: w.schemaType.Name().String(), | ||
MethodName: "LookupBySegment", | ||
AppropriateKind: datamodel.KindSet_Recursive, | ||
ActualKind: w.Kind(), | ||
} | ||
} | ||
|
||
|
@@ -205,9 +206,10 @@ func (w *_nodeRepr) LookupByNode(key datamodel.Node) (datamodel.Node, error) { | |
return w.LookupByIndex(i) | ||
} | ||
return nil, datamodel.ErrWrongKind{ | ||
TypeName: w.schemaType.Name().String(), | ||
MethodName: "LookupByNode", | ||
// TODO | ||
TypeName: w.schemaType.Name().String(), | ||
MethodName: "LookupByNode", | ||
AppropriateKind: datamodel.KindSet_Recursive, | ||
ActualKind: w.Kind(), | ||
} | ||
} | ||
|
||
|
@@ -224,19 +226,57 @@ func (w *_nodeRepr) MapIterator() datamodel.MapIterator { | |
itr := (*_node)(w).MapIterator().(*_unionIterator) | ||
return (*_unionIteratorRepr)(itr) | ||
case nil: | ||
return (*_node)(w).MapIterator() | ||
switch st := (w.schemaType).(type) { | ||
case *schema.TypeMap: | ||
return &_mapIteratorRepr{ | ||
schemaType: st, | ||
keysVal: w.val.FieldByName("Keys"), | ||
valuesVal: w.val.FieldByName("Values"), | ||
} | ||
default: | ||
panic(fmt.Sprintf("TODO: mapitr.repr for typekind %s", w.schemaType.TypeKind())) | ||
} | ||
default: | ||
panic(fmt.Sprintf("TODO: %T", stg)) | ||
} | ||
} | ||
|
||
type _mapIteratorRepr _mapIterator | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comment to explain why this wrapping and not just calling w's MapIterator is needed would be helpful |
||
|
||
func (w *_mapIteratorRepr) Next() (key, value datamodel.Node, _ error) { | ||
k, v, err := (*_mapIterator)(w).Next() | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
return k.(schema.TypedNode).Representation(), v.(schema.TypedNode).Representation(), nil | ||
} | ||
|
||
func (w *_mapIteratorRepr) Done() bool { | ||
return w.nextIndex >= w.keysVal.Len() | ||
} | ||
|
||
func (w *_nodeRepr) ListIterator() datamodel.ListIterator { | ||
if reprStrategy(w.schemaType) == nil { | ||
return (*_node)(w).ListIterator() | ||
return (*_listIteratorRepr)((*_node)(w).ListIterator().(*_listIterator)) | ||
} | ||
// TODO this is probably failing silently for structs with tuple representation. | ||
return nil | ||
} | ||
|
||
type _listIteratorRepr _listIterator | ||
|
||
func (w *_listIteratorRepr) Next() (index int64, value datamodel.Node, _ error) { | ||
idx, v, err := (*_listIterator)(w).Next() | ||
if err != nil { | ||
return idx, nil, err | ||
} | ||
return idx, v.(schema.TypedNode).Representation(), nil | ||
} | ||
|
||
func (w *_listIteratorRepr) Done() bool { | ||
return w.nextIndex >= w.val.Len() | ||
} | ||
|
||
func (w *_nodeRepr) lengthMinusTrailingAbsents() int64 { | ||
fields := w.schemaType.(*schema.TypeStruct).Fields() | ||
for i := len(fields) - 1; i >= 0; i-- { | ||
|
@@ -291,7 +331,7 @@ func (w *_nodeRepr) AsBool() (bool, error) { | |
TypeName: w.schemaType.Name().String(), | ||
MethodName: "AsBool", | ||
AppropriateKind: datamodel.KindSet_JustBool, | ||
// TODO | ||
ActualKind: w.Kind(), | ||
} | ||
} | ||
|
||
|
@@ -303,7 +343,7 @@ func (w *_nodeRepr) AsInt() (int64, error) { | |
TypeName: w.schemaType.Name().String(), | ||
MethodName: "AsInt", | ||
AppropriateKind: datamodel.KindSet_JustInt, | ||
// TODO | ||
ActualKind: w.Kind(), | ||
} | ||
} | ||
|
||
|
@@ -315,7 +355,7 @@ func (w *_nodeRepr) AsFloat() (float64, error) { | |
TypeName: w.schemaType.Name().String(), | ||
MethodName: "AsFloat", | ||
AppropriateKind: datamodel.KindSet_JustFloat, | ||
// TODO | ||
ActualKind: w.Kind(), | ||
} | ||
} | ||
|
||
|
@@ -354,13 +394,15 @@ func (w *_nodeRepr) AsString() (string, error) { | |
name := stg.GetDiscriminant(mtyp) | ||
return name + stg.GetDelim() + s, nil | ||
case schema.UnionRepresentation_Kinded: | ||
w = w.asKinded(stg, datamodel.Kind_String) | ||
// continues below | ||
return w.asKinded(stg, datamodel.Kind_String).AsString() | ||
case nil: | ||
// continues below | ||
default: | ||
panic(fmt.Sprintf("TODO: %T", stg)) | ||
} | ||
// Things that have reached here, should be only those things that have string kind naturally, | ||
// and so using the same method as the type level is correct. | ||
// TODO is this applicable for anything other than... strings? | ||
return (*_node)(w).AsString() | ||
} | ||
|
||
|
@@ -372,7 +414,7 @@ func (w *_nodeRepr) AsBytes() ([]byte, error) { | |
TypeName: w.schemaType.Name().String(), | ||
MethodName: "AsBytes", | ||
AppropriateKind: datamodel.KindSet_JustBytes, | ||
// TODO | ||
ActualKind: w.Kind(), | ||
} | ||
} | ||
|
||
|
@@ -384,7 +426,7 @@ func (w *_nodeRepr) AsLink() (datamodel.Link, error) { | |
TypeName: w.schemaType.Name().String(), | ||
MethodName: "AsLink", | ||
AppropriateKind: datamodel.KindSet_JustLink, | ||
// TODO | ||
ActualKind: w.Kind(), | ||
} | ||
} | ||
|
||
|
@@ -439,12 +481,12 @@ func (w *_assemblerRepr) asKinded(stg schema.UnionRepresentation_Kinded, kind da | |
|
||
// Layer a new finish func on top, to set Index/Value. | ||
w2.finish = func() error { | ||
unionSetMember(w.val, idx, valPtr) | ||
if w.finish != nil { | ||
if err := w.finish(); err != nil { | ||
return err | ||
} | ||
} | ||
unionSetMember(w.val, idx, valPtr) | ||
return nil | ||
} | ||
return &w2 | ||
|
@@ -589,12 +631,12 @@ func (w *_assemblerRepr) AssignString(s string) error { | |
w2.val = valPtr.Elem() | ||
w2.schemaType = member | ||
w2.finish = func() error { | ||
unionSetMember(w.val, idx, valPtr) | ||
if w.finish != nil { | ||
if err := w.finish(); err != nil { | ||
return err | ||
} | ||
} | ||
unionSetMember(w.val, idx, valPtr) | ||
return nil | ||
} | ||
return w2.AssignString(remainder) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
put a
, ok
and an error for out-of-range rather than panic?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nontrivial. This method can't return errors. It's a core interface method, and a break-the-universe-badly one if we changed its return type.