polydawn / refmt

Object mapping for golang.
MIT License
48 stars 14 forks source link

Can't round trip nil slice #40

Closed Stebalien closed 6 years ago

Stebalien commented 6 years ago
package main

import (
    "github.com/polydawn/refmt/cbor"
    "github.com/polydawn/refmt/obj/atlas"
)

type Thing struct {
    Array []byte
}

func main() {
    atlas := atlas.MustBuild(
        atlas.BuildEntry(Thing{}).StructMap().Autogenerate().Complete(),
    )

    b, err := cbor.MarshalAtlased(Thing{}, atlas)
    if err != nil {
        panic(err)
    }

    var t Thing
    err = cbor.UnmarshalAtlased(b, &t, atlas)
    if err != nil {
        panic(err) // fails here.
    }
}
Stebalien commented 6 years ago

Simpler repro:

package main

import (
    "github.com/polydawn/refmt"
    "github.com/polydawn/refmt/obj/atlas"
)

type Thing struct {
    Array []byte
}

func main() {
    atlas := atlas.MustBuild(
        atlas.BuildEntry(Thing{}).StructMap().Autogenerate().Complete(),
    )

    var a, b Thing
    err := refmt.CloneAtlased(&a, &b, atlas)
    if err != nil {
        panic(err)
    }
}