Comments (2)
Currently it should work with nested hashes as long as you use the primitive types known to message pack. Symbol and MyClass are not known.
You would have to create a new class with mapping defined in the class.
https://github.com/benoist/msgpack-crystal/blob/master/src/message_pack/mapping.cr
However the Union type with a custom class is difficult to do, as you might get the following problem:
class MyHash
MessagePack.mapping({
hash: Hash(Symbol, (Int32 | String | MyClass))
})
end
class MyClass
MessagePack.mapping({
my_string: String
})
end
{
"string" => MyHash.new({
:symbol1 => "string",
:symbol2 => MyClass.new("class string")
})
}.to_msgpack
It will create a message packed buffer something like this (its missing a few bits but I left it out so its more readable)
[ :hash_start, :string, "string", :hash_start, :string, "symbol1", :string, "string", :string, "symbol2", :string, "class string"]
When you want to unpack it and gets to the symbol2 value, it doesn't know it should be of type MyClass.
The only way to do this would be to use message pack extensions, which requires you to define the extension types yourself.
This is currently not supported.
from msgpack-crystal.
@benoist Thanks :) That helped.
from msgpack-crystal.
Related Issues (20)
- Packing array of hashes HOT 11
- Failed giving version HOT 1
- not compiled with crystal 0.17
- Parsing an unknown data structure. HOT 1
- not correct handle union type in mapping
- Crash in mapping HOT 3
- Error while building with Crystal 0.21 HOT 1
- Add support for type extension HOT 4
- Support tarantool serializable HOT 3
- Support for missing or optional HOT 1
- Bad process on nil HOT 2
- The fix of #49 doesn't cover type restriction. HOT 1
- Broken stream reading, when type mismatch
- Typo
- Can't infer the type of instance variable '@var_present' HOT 5
- Shall not include Time conversion by default HOT 11
- Missing Timestamp extension type HOT 2
- have Serializable override inspect? HOT 2
- Type discriminator HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from msgpack-crystal.