Skip to content

Can't get UUID with Scan() #3139

Open
Open
@lordspinach

Description

@lordspinach

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions