# How to serialize an object on a x64 system so it'll work on a 32-bit system?

**URL:** <https://discourse.julialang.org/t/how-to-serialize-an-object-on-a-x64-system-so-itll-work-on-a-32-bit-system/49188>\
**Category:** General Usage\
**Tags:** question\
**Created:** [October 28, 2020, 4:42pm UTC](https://discourse.julialang.org/t/how-to-serialize-an-object-on-a-x64-system-so-itll-work-on-a-32-bit-system/49188 "2020-10-28T16:42:34Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [October 28, 2020, 4:42pm UTC](https://discourse.julialang.org/t/how-to-serialize-an-object-on-a-x64-system-so-itll-work-on-a-32-bit-system/49188/1 "2020-10-28T16:42:34Z")

</div>

I need to run some processes on a x64 system (like most modern computers), save the results (e.g. by serializing them to a file), and then load and use the results on a Raspberry Pi (which is a x86 system). The object in question is a `Interpolations.jl` object.

Is there any way to accomplish this?

Right now, I understandably get this error when trying to deserialize the object on the Pi:

```julia
julia> c = deserialize("tmp")
ERROR: TypeError: in Vararg, in count, expected Int32, got a value of type Int64
Stacktrace:
 [1] deserialize_datatype(::Serializer{IOStream}, ::Bool) at /home/pi/work/build/usr/share/julia/stdlib/v1.5/Serialization/src/Serialization.jl:1276
 [2] handle_deserialize(::Serializer{IOStream}, ::Int32) at /home/pi/work/build/usr/share/julia/stdlib/v1.5/Serialization/src/Serialization.jl:826
 [3] deserialize(::Serializer{IOStream}) at /home/pi/work/build/usr/share/julia/stdlib/v1.5/Serialization/src/Serialization.jl:773
 [4] deserialize_datatype(::Serializer{IOStream}, ::Bool) at /home/pi/work/build/usr/share/julia/stdlib/v1.5/Serialization/src/Serialization.jl:1276
 [5] handle_deserialize(::Serializer{IOStream}, ::Int32) at /home/pi/work/build/usr/share/julia/stdlib/v1.5/Serialization/src/Serialization.jl:826
 [6] deserialize(::Serializer{IOStream}) at /home/pi/work/build/usr/share/julia/stdlib/v1.5/Serialization/src/Serialization.jl:773
 [7] deserialize_datatype(::Serializer{IOStream}, ::Bool) at /home/pi/work/build/usr/share/julia/stdlib/v1.5/Serialization/src/Serialization.jl:1276
 [8] handle_deserialize(::Serializer{IOStream}, ::Int32) at /home/pi/work/build/usr/share/julia/stdlib/v1.5/Serialization/src/Serialization.jl:826
 [9] deserialize(::Serializer{IOStream}) at /home/pi/work/build/usr/share/julia/stdlib/v1.5/Serialization/src/Serialization.jl:773
 [10] deserialize_datatype(::Serializer{IOStream}, ::Bool) at /home/pi/work/build/usr/share/julia/stdlib/v1.5/Serialization/src/Serialization.jl:1276
 [11] handle_deserialize(::Serializer{IOStream}, ::Int32) at /home/pi/work/build/usr/share/julia/stdlib/v1.5/Serialization/src/Serialization.jl:826
 [12] deserialize(::Serializer{IOStream}) at /home/pi/work/build/usr/share/julia/stdlib/v1.5/Serialization/src/Serialization.jl:773
 [13] deserialize_datatype(::Serializer{IOStream}, ::Bool) at /home/pi/work/build/usr/share/julia/stdlib/v1.5/Serialization/src/Serialization.jl:1267
 [14] handle_deserialize(::Serializer{IOStream}, ::Int32) at /home/pi/work/build/usr/share/julia/stdlib/v1.5/Serialization/src/Serialization.jl:826
 [15] deserialize(::Serializer{IOStream}) at /home/pi/work/build/usr/share/julia/stdlib/v1.5/Serialization/src/Serialization.jl:773
 [16] deserialize_datatype(::Serializer{IOStream}, ::Bool) at /home/pi/work/build/usr/share/julia/stdlib/v1.5/Serialization/src/Serialization.jl:1276
 [17] handle_deserialize(::Serializer{IOStream}, ::Int32) at /home/pi/work/build/usr/share/julia/stdlib/v1.5/Serialization/src/Serialization.jl:826
 [18] deserialize(::Serializer{IOStream}) at /home/pi/work/build/usr/share/julia/stdlib/v1.5/Serialization/src/Serialization.jl:773
 [19] handle_deserialize(::Serializer{IOStream}, ::Int32) at /home/pi/work/build/usr/share/julia/stdlib/v1.5/Serialization/src/Serialization.jl:833
 [20] deserialize(::Serializer{IOStream}) at /home/pi/work/build/usr/share/julia/stdlib/v1.5/Serialization/src/Serialization.jl:773
 [21] handle_deserialize(::Serializer{IOStream}, ::Int32) at /home/pi/work/build/usr/share/julia/stdlib/v1.5/Serialization/src/Serialization.jl:879
 [22] deserialize(::Serializer{IOStream}) at /home/pi/work/build/usr/share/julia/stdlib/v1.5/Serialization/src/Serialization.jl:773
 [23] deserialize at /home/pi/work/build/usr/share/julia/stdlib/v1.5/Serialization/src/Serialization.jl:760 [inlined]
 [24] open(::typeof(deserialize), ::String; kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at ./io.jl:325
 [25] open at ./io.jl:323 [inlined]
 [26] deserialize(::String) at /home/pi/work/build/usr/share/julia/stdlib/v1.5/Serialization/src/Serialization.jl:770
 [27] top-level scope at REPL[4]:1

```

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [October 28, 2020, 5:04pm UTC](https://discourse.julialang.org/t/how-to-serialize-an-object-on-a-x64-system-so-itll-work-on-a-32-bit-system/49188/2 "2020-10-28T17:04:53Z")

</div>

From the docstring of [`serialize`](https://docs.julialang.org/en/v1/stdlib/Serialization/#Serialization.serialize):

> ```
> serialize(stream::IO, value)
> 
> ```
> 
> Write an arbitrary value to a stream in an opaque format, such that it can be read back by deserialize. The read-back value  
> will be as identical as possible to the original. In general, this process will not work if the reading and writing are done  
> by different versions of Julia, or _ **an instance of Julia with a different system image** _

Emphasis is mine. You need to use a different way to store the object.

---

<div class="post-metadata">

**Author:** ![dilumaluthge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dilumaluthge/32/29283_2.png) [@dilumaluthge](https://discourse.julialang.org/u/dilumaluthge)\
**Post date:** [October 28, 2020, 5:28pm UTC](https://discourse.julialang.org/t/how-to-serialize-an-object-on-a-x64-system-so-itll-work-on-a-32-bit-system/49188/3 "2020-10-28T17:28:51Z")

</div>

You might consider using JLD2.jl, BSON.jl, or a similar package.

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [October 28, 2020, 5:48pm UTC](https://discourse.julialang.org/t/how-to-serialize-an-object-on-a-x64-system-so-itll-work-on-a-32-bit-system/49188/4 "2020-10-28T17:48:10Z")

</div>

Oh would that work? I’ll try tomorrow!

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [October 29, 2020, 9:36am UTC](https://discourse.julialang.org/t/how-to-serialize-an-object-on-a-x64-system-so-itll-work-on-a-32-bit-system/49188/5 "2020-10-29T09:36:39Z")

</div>

> [@dilumaluthge](#):
>
> using JLD2.jl, BSON.jl

didn’t work.

Working on the JLD2 attempt in [this](https://github.com/JuliaIO/JLD2.jl/issues/255) issue. Thanks for the suggestions!

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [October 29, 2020, 2:57pm UTC](https://discourse.julialang.org/t/how-to-serialize-an-object-on-a-x64-system-so-itll-work-on-a-32-bit-system/49188/6 "2020-10-29T14:57:25Z")

</div>

Plain HDF5?

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [October 29, 2020, 3:15pm UTC](https://discourse.julialang.org/t/how-to-serialize-an-object-on-a-x64-system-so-itll-work-on-a-32-bit-system/49188/7 "2020-10-29T15:15:53Z")

</div>

Well, the goal is to save an object, not just matrices/floats/etc.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [October 29, 2020, 3:26pm UTC](https://discourse.julialang.org/t/how-to-serialize-an-object-on-a-x64-system-so-itll-work-on-a-32-bit-system/49188/8 "2020-10-29T15:26:52Z")

</div>

My point is that if it is just one kind of object, it might be easier to write a serializer by hand with HDF5.

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [October 29, 2020, 3:28pm UTC](https://discourse.julialang.org/t/how-to-serialize-an-object-on-a-x64-system-so-itll-work-on-a-32-bit-system/49188/9 "2020-10-29T15:28:34Z")

</div>

No idea how to do that, it’s an interpolation from `Interpolations.jl`… But see the comments [here](https://github.com/JuliaIO/JLD2.jl/issues/255#issuecomment-718767760), sounds like it’d be hard?

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [October 29, 2020, 3:33pm UTC](https://discourse.julialang.org/t/how-to-serialize-an-object-on-a-x64-system-so-itll-work-on-a-32-bit-system/49188/10 "2020-10-29T15:33:06Z")

</div>

I see. It does look complicated.

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [October 29, 2020, 5:21pm UTC](https://discourse.julialang.org/t/how-to-serialize-an-object-on-a-x64-system-so-itll-work-on-a-32-bit-system/49188/11 "2020-10-29T17:21:26Z")

</div>

What do you want to do with the deserialized object? If you want to serialize arbitrary object and expect them to behave exactly the same after deserialization then no that’s simply impossible. The object can in general encode architectural dependent info and there’s no way to automatically figure out how those should be converted. You’ve already seen this in your error message. The deserializer cannot make the decision of `Int32` vs `Int64` for you.

What you need first is a set of architecture independent objects before you can even talk about how to pass them between different machines. This will necessarily limit what you can serialize and after figuring that part out it’s pretty much guaranteed that your allowed object can be very easily encoded in any of the standard formats.

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [October 29, 2020, 5:41pm UTC](https://discourse.julialang.org/t/how-to-serialize-an-object-on-a-x64-system-so-itll-work-on-a-32-bit-system/49188/12 "2020-10-29T17:41:59Z")

</div>

Yap, what you suggested is what finally worked for me (detailed in that [issue](https://github.com/JuliaIO/JLD2.jl/issues/255)). It’s a workaround that works 🙂
