Skip to content

Commit

Permalink
Removed payload.Length property and calculate length with len(payload…
Browse files Browse the repository at this point in the history
….Data) (#3)

Co-authored-by: Jason Shiverick <jshiverick@rivian.coml>
  • Loading branch information
jshiv and Jason Shiverick authored Mar 2, 2021
1 parent 047b82f commit 9986b66
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ import (
//type Packed *big.Int

type Payload struct {
// Message length
Length uint16

// Binary data
Data []byte

Expand Down Expand Up @@ -223,7 +220,7 @@ func (p *Payload) SignedBitsBigEndian(start, length uint16) int64 {

// Bit returns the value of the i:th bit in the data as a bool.
func (p *Payload) Bit(i uint16) bool {
if i > 8*p.Length-1 {
if int(i) > 8*len(p.Data)-1 {
return false
}
// calculate which byte the bit belongs to
Expand All @@ -238,7 +235,7 @@ func (p *Payload) Bit(i uint16) bool {

// SetBit sets the value of the i:th bit in the data.
func (p *Payload) SetBit(i uint16, value bool) {
if i > 8*p.Length-1 {
if int(i) > 8*len(p.Data)-1 {
return
}
byteIndex := i / 8
Expand Down

0 comments on commit 9986b66

Please sign in to comment.