Skip to content

Commit

Permalink
gopls/internal/util/frob: use binary.LittleEndian.AppendUint{16,32,64}
Browse files Browse the repository at this point in the history
Complete a TODO.

Change-Id: I5ef391754d516a9a7672308e1f7e829789f6ac2e
  • Loading branch information
qiulaidongfeng committed Feb 5, 2024
1 parent a1fbc78 commit e439b13
Showing 1 changed file with 3 additions and 34 deletions.
37 changes: 3 additions & 34 deletions gopls/internal/util/frob/frob.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,38 +402,7 @@ func (r *reader) bytes(n int) []byte {
type writer struct{ data []byte }

func (w *writer) uint8(v uint8) { w.data = append(w.data, v) }
func (w *writer) uint16(v uint16) { w.data = appendUint16(w.data, v) }
func (w *writer) uint32(v uint32) { w.data = appendUint32(w.data, v) }
func (w *writer) uint64(v uint64) { w.data = appendUint64(w.data, v) }
func (w *writer) uint16(v uint16) { w.data = binary.LittleEndian.AppendUint16(w.data, v) }
func (w *writer) uint32(v uint32) { w.data = binary.LittleEndian.AppendUint32(w.data, v) }
func (w *writer) uint64(v uint64) { w.data = binary.LittleEndian.AppendUint64(w.data, v) }
func (w *writer) bytes(v []byte) { w.data = append(w.data, v...) }

// TODO(adonovan): delete these as in go1.19 they are methods on LittleEndian:

func appendUint16(b []byte, v uint16) []byte {
return append(b,
byte(v),
byte(v>>8),
)
}

func appendUint32(b []byte, v uint32) []byte {
return append(b,
byte(v),
byte(v>>8),
byte(v>>16),
byte(v>>24),
)
}

func appendUint64(b []byte, v uint64) []byte {
return append(b,
byte(v),
byte(v>>8),
byte(v>>16),
byte(v>>24),
byte(v>>32),
byte(v>>40),
byte(v>>48),
byte(v>>56),
)
}

0 comments on commit e439b13

Please sign in to comment.