msgpack-go's Introduction
This builds with the new 'go' tool. It is installable with "go get github.com/msgpack/msgpack-go". FYI, [go-msgpack](https://github.com/ugorji/go) contains a better msgpack implementation for go.
msgpack-go's People
Forkers
ngmoco skelterjohn xyproto hyber yhcflyy gobwas cuiwm byorty huangwei1024 pyway weiyuefei lawlielt guoyu07 flyarong kenfoo wangjunemse xxgf scriptmaster isabella232 halokid facchinm lsutils seanpm2001msgpack-go's Issues
No license or Copyrights present
Please include all the license and copyrights used for this repo
floats need special handling when unpacked
Packing a float value does not necessarily pack it as a float in the underlying protocol you try to optimize for space. This is not a bug, but it makes for very cumbersome code when unpacking floats, because a float can be encoded either a UInt of some length, or an Int of some length.
Unless I'm missing something (I'm pretty new to Go), you have to decode it as such:
switch value.Kind() {
case reflect.Uint, reflect.Uint64, reflect.Uint32, reflect.Uint16, reflect.Uint8:
ival := value.Uint()
fval = *(*float32)(unsafe.Pointer(&ival))
case reflect.Int, reflect.Int64, reflect.Int32, reflect.Int16, reflect.Int8:
ival := value.Int()
fval = *(*float32)(unsafe.Pointer(&ival))
}
Shouldn't this be handled automatically with something like UnpackFloat32/64() ?
Deprecate msgpack-go (in favor of go-msgpack)
As msgpack-go is no longer actively maintained mainly because of the original developer being a way too busy to pay attention (kudos to @methane and all the guys having worked on it), I think it's time to start thinking of deprecating msgpack-go and possibly embracing a great alternative, go-msgpack (please supply any if there are more) as a new, official Go implementation of msgpack.
pack float data wrong
I think that the method of using pack uint data method to pack float data is wrong, because the head sign of packing float is different from the head sign of packing uint, so I modify code:
// Packs a given value and writes it into the specified writer.
func PackFloat32(writer io.Writer, value float32) (n int, err error) {
valueToUint32 := _(_uint32)(unsafe.Pointer(&value))
return writer.Write([]byte{0xca, byte(valueToUint32 >> 24), byte(valueToUint32 >> 16), byte(valueToUint32 >> 8), byte(valueToUint32)})
}
// Packs a given value and writes it into the specified writer.
func PackFloat64(writer io.Writer, value float64) (n int, err error) {
valueToUint64 := _(_uint64)(unsafe.Pointer(&value))
return writer.Write([]byte{0xcb, byte(valueToUint64 >> 56), byte(valueToUint64 >> 48), byte(valueToUint64 >> 40), byte(valueToUint64 >> 32), byte(valueToUint64 >> 24), byte(valueToUint64 >> 16), byte(valueToUint64 >> 8), byte(valueToUint64)})
}
Unpack should return interface{} instead of reflect.Value
I am trying to use this and the RPC library and I think the code requires a major refactor to match standard encoding libraries in Go. I have made changes on the ngmoco fork but I didn't want to open a pull request until there was some discussion around the matter.
I personally suggest trashing the current interface since this separate project is fairly new. It only took me a few hours to switch the code to something that is far more usable.
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.