# MsgPack fails to unpack a basic structure

**URL:** <https://discourse.julialang.org/t/msgpack-fails-to-unpack-a-basic-structure/60182>\
**Category:** New to Julia\
**Tags:** question, package\
**Created:** [April 28, 2021, 4:37pm UTC](https://discourse.julialang.org/t/msgpack-fails-to-unpack-a-basic-structure/60182 "2021-04-28T16:37:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BambOoxX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bambooxx/32/22179_2.png) [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)\
**Post date:** [April 28, 2021, 4:37pm UTC](https://discourse.julialang.org/t/msgpack-fails-to-unpack-a-basic-structure/60182/1 "2021-04-28T16:37:07Z")

</div>

While trying out some MsgPack.jl functionnalities, I tested to pack/unpack a simple structure possessing two fields : one integer and one matrix. Following the documentation for this package, I obtained this code

```julia
using MsgPack

struct TestStruct
    x::Int64
    arr::Matrix{Float64}
end
MsgPack.msgpack_type(::Type{TestStruct}) = MsgPack.StructType()

test = TestStruct(3,rand(Float64,3,4))

test_packed = pack(test)
test2 = unpack(test_packed,strict=(TestStruct,))

```

Which returns

```julia
julia> test2 = unpack(test_packed,strict=(TestStruct,))
Dict{Any,Any} with 2 entries:
  "arr" => Any[0.198004, 0.870654, 0.0119973, 0.979071, 0.670376, 0.977469, 0.373035, 0.635284, 0.457175, 0.461499, 0.0531387, 0.307494]
  "x" => 0x03

```

So basically my array field is returned as a vector and my integer is not correctly decoded. Not to mention that my structure is returned as a Dict.

What am I missing here ?

---

<div class="post-metadata">

**Author:** ![tisztamo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tisztamo/32/16200_2.png) [@tisztamo](https://discourse.julialang.org/u/tisztamo)\
**Post date:** [April 28, 2021, 7:10pm UTC](https://discourse.julialang.org/t/msgpack-fails-to-unpack-a-basic-structure/60182/2 "2021-04-28T19:10:03Z")

</div>

I guess there is two different problems here:

First, you need to provide the outermost type, the strict param is only for performance. e.g:

```julia
test2 = unpack(test_packed, TestStruct)

```

works when I use Vector instead of Matrix, but for your original example it throws

```julia
MethodError: no method matching Matrix{Float64}(::Vector{Float64})
...

```

Suggesting that Matrix is not supported (just a guess, I am not an expert).

Note: I wrote [TypeParsers.jl](https://github.com/Circo-dev/TypeParsers.jl) to securely parse types from strings. I needed it to deserialize the outermost type (“TestStruct”, sent as a string prefix to the MsgPack data).

---

<div class="post-metadata">

**Author:** ![BambOoxX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bambooxx/32/22179_2.png) [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)\
**Post date:** [April 29, 2021, 11:36am UTC](https://discourse.julialang.org/t/msgpack-fails-to-unpack-a-basic-structure/60182/3 "2021-04-29T11:36:01Z")

</div>

Thanks, that is the behavior I observed too, I am quite surprised that such transfer protocols do not handle matrix object, but I guess that is because I am too much used to scientific programming and not general programming…

---

<div class="post-metadata">

**Author:** ![BambOoxX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bambooxx/32/22179_2.png) [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)\
**Post date:** [May 9, 2021, 2:28pm UTC](https://discourse.julialang.org/t/msgpack-fails-to-unpack-a-basic-structure/60182/4 "2021-05-09T14:28:07Z")

</div>

> [@tisztamo](#):
>
> Note: I wrote [TypeParsers.jl](https://github.com/Circo-dev/TypeParsers.jl) to securely parse types from strings. I needed it to deserialize the outermost type (“TestStruct”, sent as a string prefix to the MsgPack data).

Actually, I tested this communication process with [MessagePack-CSharp](https://github.com/neuecc/MessagePack-CSharp) where using the `Typeless` version of the serialization commands, the type is also passed direclty inside the message. So no need to send another message before that in this case.  
After that, I just compare the type of the message with the list of types exported by my package.  
If I switch to another solution, I will check TypeParsers more thoroughly.

As for Matrices, there is no support for complex numbers at the moment, which is a bit of a bummer for me but maybe somone will have an idea to support this via extension types, who knows…
