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

V1 XMLCodec supports encoding + scanning XML column type #2083

Merged
merged 3 commits into from
Jul 12, 2024

Conversation

nickcruess-soda
Copy link
Contributor

@nickcruess-soda nickcruess-soda commented Jul 11, 2024

We have a need for the XML column type but observed that it isn't currently supported. I've taken the JSONCodec as a starting point and adapted it for XML. They turned out to be quite similar. I left in some of the issue-referencing comments from the JSONCodec which seemed relevant here as well, such as the one explaining the driver.Valuer vs xml.Marshaler ordering in PlanEncode.

While I was at it I also noticed some unused code related to the JSONCodec (scanPlanJSONToBytesScanner), which I removed in the second commit. Happy to drop that if this isn't the place/time for it.

@jackc
Copy link
Owner

jackc commented Jul 12, 2024

It looks like the tests will need to skip CockroachDB.

@jackc jackc merged commit 9530aea into jackc:master Jul 12, 2024
14 checks passed
}

var dst any
err := c.Unmarshal(src, &dst)
Copy link

Choose a reason for hiding this comment

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

@nickcruess-soda @jackc I seem to be late to the game but this will always return nil, since Unmarshal(..) expects the variable to be of slice, struct or string. https://pkg.go.dev/encoding/xml#Unmarshal

Unmarshal parses the XML-encoded data and stores the result in the value pointed to by v, 
which must be an arbitrary struct, slice, or string. 
Well-formed data that does not fit into v is discarded.

https://go.dev/play/p/yLdFqZPaoUo

Returning the bytes seem to be the better choice.

Am I missing something?

Copy link
Owner

Choose a reason for hiding this comment

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

@lyuboxa I think you're right.

@nickcruess-soda What do you think?

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.

3 participants