Comments (4)
I also suffer from new Rust serialize
interface.
It would appear that the only option left is to re-implement msgpack::Decoder#decode_value() in terms > of the generic serialize::Decoder trait.
But how? By reading a single byte one-by-one via read_u8() and analyzing it with further decoding?
What if you actually need to access Decoder<R: Reader>
impl (for example, you might want to cache something)?
from rust-msgpack.
In looking at rustc-serialize::json
: they don't even implement Decodable
for their enum Json
which is the equivalent of our enum Value
type.
Instead they have a Builder
which takes a Reader
and yields a Json
enumeration. (This is all hidden behind some helper functions: from_str
, from_reader
, etc.)
Then their implementation of Decoder just runs through this parsed representation.
So in essence json::Builder
does all the work of actually parsing and decoding Json.
impl serialize::Decoder for json::Decoder {}
is just there to shove the pre-parsed Json
value into the requested Rust type. Since json::Builder
doesn't implement the serialize::Decoder
interface directly it can do all the caching, etc. that it wants.
The unfortunate thing about this strategy is that it appears to require reading the stream to completion.
from rust-msgpack.
The unfortunate thing about this strategy is that it appears to require reading the stream to completion.
This is bad for me, because I use msgpack in conjunction with TcpStream, which yields msgpack object every time it's ready.
Moreover, this is bad even for json, because many applications need to stream json'ed values through sockets.
from rust-msgpack.
It's worth noting the distinction: the json::Builder
which can be constructed from a Reader
is built on top of json::Parser
which is a streaming parser. -- json::Builder
calls #read_to_end()
on the Reader so constructing it from a TcpStream would not be a good idea.
In practice I can't say I've ever done that. I usually pull TcpStream#read()
into a buffer and then construct the entire Json
value from that buffer. In my recent applications I'm using websockets; but any protocol w/ basic framing can be used to guarantee you've received the entire message before trying to deserialize it.
If you really need to do streaming (e.g: you're receiving fragments of a message) then you would have to use serialize::json::Parser
directly. Again that's not a common use-case for me; especially considering std::io
is synchronous.
from rust-msgpack.
Related Issues (20)
- Add enum support. HOT 3
- Out of touch with master. HOT 4
- Build failing on serialise::Decoder trait HOT 2
- Travis builds failing since bbd93a7 HOT 1
- Support rust enums HOT 1
- Doesn't compile with the latest rust HOT 1
- Fails to pack/unpack
- task '<main>' failed at 'called `Option::unwrap()` on a `None` value' HOT 5
- Structs are encoded w/ map type but are not valid msgpack maps! HOT 8
- Nullary option variants corrupt the next element in the decoder. HOT 2
- Publish to crates.io HOT 1
- port to rust 1.0.0 alpha
- Clone Trait
- Build is broken against nightly
- msgpack-rpc HOT 5
- Does not compile with rustc 1.7.0 HOT 3
- Won't Compile with rustc 1.15.0-nightly (8f02c429a 2016-12-15)
- It doesn't compile with byteorder v1.2.1 HOT 1
- Mark this library as deprecated
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 rust-msgpack.