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

Can't get UUID with Scan() #3139

Open
lordspinach opened this issue Oct 1, 2024 · 1 comment
Open

Can't get UUID with Scan() #3139

lordspinach opened this issue Oct 1, 2024 · 1 comment

Comments

@lordspinach
Copy link

lordspinach commented Oct 1, 2024

Expected Behavior

Can use UUID type for storing structs in hash tables

Current Behavior

Got invalid UUID length: 16 error from (uuid *UUID) UnmarshalText

Possible Solution

Add encoding.BinaryUnmarshaler to switch case at /internal/hscan/structmap.go:107

Steps to Reproduce

  1. Create structure with UUID field
  2. Set it to hash table with HSet()
  3. Get it back with HGetAll()
  4. Try to write given map[string]string to structure with Scan()

Detailed Description

I am facing a problem related to hash tables. I want to store objects in it, so I use HSet. Then encoding.BinaryMarshaler is used to marshal the UUID, but when I try to get the object back using Scan(), encoding.TextUnmarshaler is used instead of encoding.BinaryUnmarshaler to unmarshal it.
This is a incorrect use of these interfaces. As it is written in the description of these interfaces

UnmarshalBinary must be able to decode the form generated by MarshalBinary

And

UnmarshalText must be able to decode the form generated by MarshalText

They are not interchangeable and Binary should be used with Binary and Text with Text

@zeze1004
Copy link

zeze1004 commented Oct 3, 2024

Can I contribute to this by adding support for encoding.BinaryUnmarshaler in the Scan function?

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

No branches or pull requests

2 participants