-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
To keep track of field&assemblies order.
- Loading branch information
Showing
5 changed files
with
69 additions
and
34 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package parser | ||
|
||
import ( | ||
"encoding/xml" | ||
) | ||
|
||
type parentElement interface { | ||
RegisterChild(GoStructItem) | ||
} | ||
|
||
type contextParser []parentElement | ||
|
||
var context contextParser | ||
|
||
func (cp *contextParser) Push(p parentElement) { | ||
*cp = append(*cp, p) | ||
} | ||
|
||
func (cp *contextParser) Pop() { | ||
*cp = (*cp)[:len(*cp)-1] | ||
} | ||
|
||
func (cp *contextParser) RegisterChild(child GoStructItem) { | ||
(*cp)[len(*cp)-1].RegisterChild(child) | ||
} | ||
|
||
func (m *Model) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { | ||
type model Model | ||
context.Push(m) | ||
defer context.Pop() | ||
return d.DecodeElement((*model)(m), &start) | ||
} | ||
|
||
func (m *Model) RegisterChild(child GoStructItem) { | ||
m.sortedChilds = append(m.sortedChilds, child) | ||
} | ||
|
||
func (a *Assembly) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { | ||
type assembly Assembly | ||
err := d.DecodeElement((*assembly)(a), &start) | ||
context.RegisterChild(a) | ||
return err | ||
} | ||
|
||
func (f *Field) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { | ||
type field Field | ||
err := d.DecodeElement((*field)(f), &start) | ||
context.RegisterChild(f) | ||
return err | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.