remove unnecessary int64 casting

This commit is contained in:
David 2021-12-20 18:45:10 -05:00
parent 6ffa3b6dd4
commit 41c58fa100

View File

@ -46,30 +46,30 @@ func makeScanner(test bool) *bufio.Scanner {
return bufio.NewScanner(reader)
}
func parseNumber(stream []uint8, length int) int64 {
result := int64(0)
func parseNumber(stream []uint8, length int) int {
result := int(0)
for i := 0; i < length; i++ {
result += int64(stream[i]) << (length - 1 - i)
result += int(stream[i]) << (length - 1 - i)
}
return result
}
type packet struct {
version int64
typeID int64
version int
typeID int
subPackets []packet
encodedNumber int64
encodedNumber int
}
func getPacketVersion(stream []uint8) int64 {
func getPacketVersion(stream []uint8) int {
return parseNumber(stream, 3)
}
func getPacketType(stream []uint8) int64 {
func getPacketType(stream []uint8) int {
return parseNumber(stream, 3)
}
func getSubpacketLength(t uint8, stream []uint8) (int, int64) {
func getSubpacketLength(t uint8, stream []uint8) (int, int) {
if t == 0 {
return 15, parseNumber(stream, 15)
}
@ -79,7 +79,7 @@ func getSubpacketLength(t uint8, stream []uint8) (int, int64) {
return 0, 0
}
func parsePayload(stream []uint8) (int64, int) {
func parsePayload(stream []uint8) (int, int) {
num := []uint8{}
pos := 0
chars := 0
@ -113,10 +113,10 @@ func parsePackets(stream []uint8) (int, packet) {
consumed, subs := parsePackets(stream[7+size+parsed:])
parsedPacket.subPackets = append(parsedPacket.subPackets, subs)
parsed += consumed
if size == 11 && int64(len(parsedPacket.subPackets)) == subpacketlength {
if size == 11 && len(parsedPacket.subPackets) == subpacketlength {
return parsed + 7 + size, parsedPacket
} else if size == 15 && int64(parsed) > subpacketlength || consumed == 0 {
} else if size == 15 && parsed > subpacketlength || consumed == 0 {
return parsed + 7 + size, parsedPacket
}
}