Skip to content

Commit

Permalink
Refactor rawDataStartIndex method in share package (#1646)
Browse files Browse the repository at this point in the history
<!--
Please read and fill out this form before submitting your PR.

Please make sure you have reviewed our contributors guide before
submitting your
first PR.
-->

## Overview

Refactors `rawDataStartIndex` using fewer lines of code and removing
unreachable code.

<!-- 
Please provide an explanation of the PR, including the appropriate
context,
background, goal, and rationale. If there is an issue with this
information,
please provide a tl;dr and link the issue. 
-->

## Checklist

<!-- 
Please complete the checklist to ensure that the PR is ready to be
reviewed.

IMPORTANT:
PRs should be left in Draft until the below checklist is completed.
-->

- [x] New and updated code has appropriate documentation
- [x] New and updated code has new and/or updated testing
- [x] Required CI checks are passing
- [x] Visual proof for any user facing features like CLI or
documentation updates
- [ ] Linked issues closed with keywords
  • Loading branch information
Manav-Aggarwal committed Apr 24, 2023
1 parent 058442d commit 309c650
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions pkg/shares/shares.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,17 +180,15 @@ func (s *Share) rawDataStartIndex() int {
if err != nil {
panic(err)
}
if isStart && isCompact {
return appconsts.NamespaceSize + appconsts.ShareInfoBytes + appconsts.SequenceLenBytes + appconsts.CompactShareReservedBytes
} else if isStart && !isCompact {
return appconsts.NamespaceSize + appconsts.ShareInfoBytes + appconsts.SequenceLenBytes
} else if !isStart && isCompact {
return appconsts.NamespaceSize + appconsts.ShareInfoBytes + appconsts.CompactShareReservedBytes
} else if !isStart && !isCompact {
return appconsts.NamespaceSize + appconsts.ShareInfoBytes
} else {
panic(fmt.Sprintf("unable to determine the rawDataStartIndex for share %s", s.data))

index := appconsts.NamespaceSize + appconsts.ShareInfoBytes
if isStart {
index += appconsts.SequenceLenBytes
}
if isCompact {
index += appconsts.CompactShareReservedBytes
}
return index
}

func ToBytes(shares []Share) (bytes [][]byte) {
Expand Down

0 comments on commit 309c650

Please sign in to comment.