msgpack / msgpack-go

149 stars 25 forks source link

pack float data wrong #4

Open alex-hsl opened 11 years ago

alex-hsl commented 11 years ago

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)}) }