Skip to content
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

Tree.Marshal returns the TOML encoding of Tree #306

Merged
merged 1 commit into from
Sep 26, 2019

Conversation

mbialon
Copy link
Contributor

@mbialon mbialon commented Sep 25, 2019

Issue: #295

The Tree.Marshal method tried to marshal the Tree struct itself rather than the nodes being part of the tree. The Tree struct doesn't export any fields so the result was empty. Regardless, the output would not represent the TOML structure inside the tree.

@@ -445,8 +445,11 @@ func (t *Tree) Unmarshal(v interface{}) error {
// See Marshal() documentation for types mapping table.
func (t *Tree) Marshal() ([]byte, error) {
var buf bytes.Buffer
err := NewEncoder(&buf).Encode(t)
return buf.Bytes(), err
_, err := t.WriteTo(&buf)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this is now basically the same code as ToTomlString(), mind replacing it with something like

func (t *Tree) ToTomlString() (string, error) {
	b, err := t.Marshal()
	if err != nil {
		return "", err
	}
	return string(b), nil
}

to avoid duplication, please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

The Tree.Marshal tried to marshal the Tree struct itself rather than the nodes being part of the tree.

Fixes pelletier#295
Copy link
Owner

@pelletier pelletier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thank you for tackling that.

@pelletier pelletier merged commit 75654e6 into pelletier:master Sep 26, 2019
@mbialon mbialon deleted the fix-tree-marshal branch October 1, 2019 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants