Skip to content

Use CBOR tags to disambiguate which struct to fill an interface field with #8

@rayhaanj

Description

@rayhaanj

If a struct like the following is passed to the Unmarshaler, then it is unclear as to how the unmarshaler would know which concrete type to fill into the struct field:

type ConvolutedIndirectable interface {
  ConvolutedIndirection() int
}

type Indirector struct {
  I int
}

func (i *Indirector) ConvolutedIndirection() int {
  return i.I
}

type One struct {
  A ConvolutedIndirectable
}

func main() {
  reader := ...
  var o One
  if err := reader.Unmarshal(&o); err != nil {
    ...
  }
}

When the struct is marshaled the information about what struct was actually in the interface is lost, only an un-type-annotated map is transferred via CBOR, so it does not seem possible to work out what type to create to put in this field when unmarshaling.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions