Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] PackBytes bug when length < MAX16BIT #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 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 All @@ -186,7 +188,7 @@ func PackBytes(writer io.Writer, value []byte) (n int, err error) {
n2, err := writer.Write(value)
return n1 + n2, err
} else if length < MAX16BIT {
n1, err := writer.Write(Bytes{RAW16, byte(length >> 16), byte(length)})
n1, err := writer.Write(Bytes{RAW16, byte(length >> 8), byte(length)})
if err != nil {
return n1, err
}
Expand Down