You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Facing an issue while using the plugin to marshal / unmarshal a non initialized empty struct (only declared)
Below code shows multiple type of objects getting marshalled / unmarshalled using the library.
We have been trying to use the test2 function approach and getting the following panic:
panic: reflect: reflect.Value.SetString using unaddressable value
Can someone please confirm on the following:
Is it expected to break (if yes why) or is it a bug which we are planning to fix/handle in the near future?
If its expected to break then anyway we can handle and make it work at our end?
Can some conceptual understanding be provided on why is the plugin written in a way that it works for all the other cases but not only for test2.
package main
import (
"fmt"
"github.com/vmihailenco/msgpack/v5"
)
type ABC struct {
SampleInt int `msgpack:"Abc"`
SampleBool bool `msgpack:"Xyz"`
SampleString string `msgpack:"Efg"`
}
func main() {
//test1() //works
test2() //doesn't work
//test3() //works
//test4() //works
}
func test1() {
var test ABC
var test2 ABC
max := marshal(&test, &test2)
var test5 ABC
var test6 ABC
unmarshal(max, &test5, &test6)
fmt.Println(test5, test6)
}
func test2() {
var test []ABC
var test2 []ABC
max := marshal(&test, &test2)
var test5 []ABC
var test6 []ABC
unmarshal(max, &test5, &test6)
fmt.Println(test5, test6)
}
func test3() {
test := []ABC{}
test2 := []ABC{}
max := marshal(&test, &test2)
test5 := []ABC{}
test6 := []ABC{}
unmarshal(max, &test5, &test6)
fmt.Println(test5, test6)
}
func test4() {
abc1 := ABC{100, false, "Full-Stack Developer"}
abc2 := ABC{100, false, "Full-Stack Developer"}
test := []ABC{abc1, abc2}
test2 := []ABC{abc1, abc2}
max := marshal(&test, &test2)
test5 := []ABC{}
test6 := []ABC{}
unmarshal(max, &test5, &test6)
fmt.Println(test5, test6)
}
func marshal(test ...interface{}) string {
a, _ := msgpack.Marshal(test)
return string(a)
}
func unmarshal(marsh string, dest ...interface{}) {
if dest != nil {
err := msgpack.Unmarshal([]byte(marsh), &dest)
fmt.Println(err)
}
}
Hoping to hear from you soon.
Thanks in advance.
The text was updated successfully, but these errors were encountered:
HI,
Facing an issue while using the plugin to marshal / unmarshal a non initialized empty struct (only declared)
Below code shows multiple type of objects getting marshalled / unmarshalled using the library.
We have been trying to use the test2 function approach and getting the following panic:
panic: reflect: reflect.Value.SetString using unaddressable value
Can someone please confirm on the following:
Hoping to hear from you soon.
Thanks in advance.
The text was updated successfully, but these errors were encountered: