msgpack-go icon indicating copy to clipboard operation
msgpack-go copied to clipboard

pack float data wrong

Open alex-hsl opened this issue 13 years ago • 0 comments

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

alex-hsl avatar Nov 14 '12 07:11 alex-hsl