Comments (14)
#114 was merged into v1.
from msgpack-ruby.
The reason of it is just performance. It makes makes packer/unpacker slower to make it possible to pack strings/symbols/numbers (or some others) into different representations.
I'm ok to make it modify-able by using ext types if there's any way without performance regression.
from msgpack-ruby.
Okay, I might try and have a look at this. It seems like it should be fairly straightforward to do it with minimal performance impact (i.e. done in the native code with an 'if').
from msgpack-ruby.
I'm having the same problem. What about giving the (un)packer an allow_core_ext
option on initialization? It had to be checked once for every (un)pack.
- If
false
(default) it selects the (fast) current algorithm. - If
true
it selects the (slow) modified algorithm looking for an ext type before defaulting to the current algorithm.
from msgpack-ruby.
It looks an option to make it implemented.
from msgpack-ruby.
I had some time to take a closer look at it.
-
Allowing all core types (number, strings, …) to be custom serialized in the way I proposed above imposes the performance penalty to every serialization of every type. And this even if we only want to use an ext type for just one core type (like with symbols). This seems to be too much. Especially when most of the time (if not always) there is no need to use an ext type for the general core types (nil, bool, number, string, array, hash). The only remaining exception are symbols.
-
So, I think it's best to only support an ext type for symbols. Once an ext type is registered for them the intention is clear:
packer = MessagePack::Packer.new
packer.register_type(0x00, Symbol, :to_msgpack_ext)
packer.pack(:symbol).to_s # => "\xc7\x06\x00symbol"
No further option/configuration needed.
- For an implementation see #114.
from msgpack-ruby.
IMO that approach looks reasonable... @frsyuki how do you think about it?
My understanding:
- there's no case to want to pack core types into ext types - except for symbols
- add just a flag/hook to check whether Symbol is registered into registry for ext types
- pack Symbols as ext types if it's already registered into ext types
from msgpack-ruby.
and @simonrussell ?
from msgpack-ruby.
That suits me; that's more-or-less what I was thinking for an implementation; thanks @christopheraue for following this up. I guess the only other part of my problem was that Symbols get encoded and there's no way to disable that (i.e. throw an exception) -- I suppose I could register a handler that just throws an exception? (My issue here is the non-round-trip nature of encoding/decoding with Symbols).
Personally I think the pattern works for all core types; maybe as a future extension those could be implemented -- I doubt that would impact performance that much in the case where the extension types weren't registered.
from msgpack-ruby.
Concept of #114 looks very good. That is because I agree that there are some use cases where Symbol needs a custom serialization format so that receiver of the serialized data can distinguish it from strings. And the other core types don't need such customization.
A missing thing is that there're no pretty ways to configure Packer to throw exceptions when a Symbol is given. But registering a method that throws an exception as ext type handler is possible as a workaround. I think it's good enough for its limited use case. So I think we can go with #114.
from msgpack-ruby.
@frsyuki What you meant as "a missing thing" is: we need a way to prohibit serialization of symbols, and it's be done by hack to raise an exception in ext type handler. Is it right?
from msgpack-ruby.
Yes, I think that was the same comment I was making -- you can't disable Symbol packing completely; so you can't be sure that you'll get a clean round-trip (your Symbols will become Strings).
from msgpack-ruby.
@tagomoris right.
from msgpack-ruby.
OK, let's go forward with #114.
from msgpack-ruby.
Related Issues (20)
- Does msgpack_each support nested calls in design principle? HOT 3
- Unpack "end of buffer reached" error on Windows HOT 13
- Extra bytes when loading string HOT 5
- Seg Fault in #load HOT 3
- msgpack.jar seems to be missing in v1.5.5 HOT 7
- Correct way to pack and unpack `Struct` instances. HOT 4
- Packer can overwrite earlier parts of its buffer in version 1.6.0 HOT 10
- jruby: `MessagePack::Unpacker#buffer` is missing
- [BUG] Failed to free an rmem pointer, memory leak? HOT 8
- Compile fails on older toolsets HOT 5
- undefined method `to_msgpack' for BigDecimal (NoMethodError) HOT 4
- Attempt to GC mark already marked object HOT 22
- Pass empty string into MessagePack::Unpacker.feed will stop further feeding valid string in version >= 1.7.0 HOT 1
- Amazon Linux 2 w Ruby 2.6.10 - msgpack requires Ruby version >= 2.5. HOT 1
- Write msgpack to msgpack HOT 2
- Pack as uint16 HOT 1
- Feature request: Time packer HOT 1
- Fix for platforms without compaction support not complete
- 10 extra bytes after the deserialized object HOT 1
- Is Ruby 3.3.0 supported? 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-ruby.