Skip to content

Commit

Permalink
[fix] PackFloat32 using PackInt32 but no modified type
Browse files Browse the repository at this point in the history
  • Loading branch information
huangwei1024 committed Mar 18, 2017
1 parent 6080433 commit 24d3b82
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,14 @@ func PackBool(writer io.Writer, value bool) (n int, err error) {

// Packs a given value and writes it into the specified writer.
func PackFloat32(writer io.Writer, value float32) (n int, err error) {
return PackUint32(writer, *(*uint32)(unsafe.Pointer(&value)))
_value := *(*uint32)(unsafe.Pointer(&value))
return writer.Write(Bytes{FLOAT, byte(_value >> 24), byte(_value >> 16), byte(_value >> 8), byte(_value)})
}

// Packs a given value and writes it into the specified writer.
func PackFloat64(writer io.Writer, value float64) (n int, err error) {
return PackUint64(writer, *(*uint64)(unsafe.Pointer(&value)))
_value := *(*uint64)(unsafe.Pointer(&value))
return writer.Write(Bytes{DOUBLE, byte(_value >> 56), byte(_value >> 48), byte(_value >> 40), byte(_value >> 32), byte(_value >> 24), byte(_value >> 16), byte(_value >> 8), byte(_value)})
}

// Packs a given value and writes it into the specified writer.
Expand Down

0 comments on commit 24d3b82

Please sign in to comment.