mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
wal: minor fixes
- remove unnecessary type cast - simply modulo operations
This commit is contained in:
parent
c63eaf45f9
commit
008081ffb5
@ -70,7 +70,7 @@ func (e *encoder) encode(rec *walpb.Record) error {
|
||||
}
|
||||
|
||||
lenField, padBytes := encodeFrameSize(len(data))
|
||||
if err = writeInt64(e.bw, int64(lenField), e.uint64buf); err != nil {
|
||||
if err = writeUint64(e.bw, lenField, e.uint64buf); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -84,10 +84,9 @@ func (e *encoder) encode(rec *walpb.Record) error {
|
||||
func encodeFrameSize(dataBytes int) (lenField uint64, padBytes int) {
|
||||
lenField = uint64(dataBytes)
|
||||
// force 8 byte alignment so length never gets a torn write
|
||||
if padBytes = 8 - (dataBytes % 8); padBytes != 8 {
|
||||
padBytes = (8 - (dataBytes % 8)) % 8
|
||||
if padBytes != 0 {
|
||||
lenField |= uint64(0x80|padBytes) << 56
|
||||
} else {
|
||||
padBytes = 0
|
||||
}
|
||||
return
|
||||
}
|
||||
@ -98,9 +97,9 @@ func (e *encoder) flush() error {
|
||||
return e.bw.Flush()
|
||||
}
|
||||
|
||||
func writeInt64(w io.Writer, n int64, buf []byte) error {
|
||||
func writeUint64(w io.Writer, n uint64, buf []byte) error {
|
||||
// http://golang.org/src/encoding/binary/binary.go
|
||||
binary.LittleEndian.PutUint64(buf, uint64(n))
|
||||
binary.LittleEndian.PutUint64(buf, n)
|
||||
_, err := w.Write(buf)
|
||||
return err
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user