remove unnecessary int64 casting
This commit is contained in:
parent
6ffa3b6dd4
commit
41c58fa100
24
16/main.go
24
16/main.go
@ -46,30 +46,30 @@ func makeScanner(test bool) *bufio.Scanner {
|
|||||||
return bufio.NewScanner(reader)
|
return bufio.NewScanner(reader)
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseNumber(stream []uint8, length int) int64 {
|
func parseNumber(stream []uint8, length int) int {
|
||||||
result := int64(0)
|
result := int(0)
|
||||||
for i := 0; i < length; i++ {
|
for i := 0; i < length; i++ {
|
||||||
result += int64(stream[i]) << (length - 1 - i)
|
result += int(stream[i]) << (length - 1 - i)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
type packet struct {
|
type packet struct {
|
||||||
version int64
|
version int
|
||||||
typeID int64
|
typeID int
|
||||||
subPackets []packet
|
subPackets []packet
|
||||||
encodedNumber int64
|
encodedNumber int
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPacketVersion(stream []uint8) int64 {
|
func getPacketVersion(stream []uint8) int {
|
||||||
return parseNumber(stream, 3)
|
return parseNumber(stream, 3)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPacketType(stream []uint8) int64 {
|
func getPacketType(stream []uint8) int {
|
||||||
return parseNumber(stream, 3)
|
return parseNumber(stream, 3)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSubpacketLength(t uint8, stream []uint8) (int, int64) {
|
func getSubpacketLength(t uint8, stream []uint8) (int, int) {
|
||||||
if t == 0 {
|
if t == 0 {
|
||||||
return 15, parseNumber(stream, 15)
|
return 15, parseNumber(stream, 15)
|
||||||
}
|
}
|
||||||
@ -79,7 +79,7 @@ func getSubpacketLength(t uint8, stream []uint8) (int, int64) {
|
|||||||
return 0, 0
|
return 0, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func parsePayload(stream []uint8) (int64, int) {
|
func parsePayload(stream []uint8) (int, int) {
|
||||||
num := []uint8{}
|
num := []uint8{}
|
||||||
pos := 0
|
pos := 0
|
||||||
chars := 0
|
chars := 0
|
||||||
@ -113,10 +113,10 @@ func parsePackets(stream []uint8) (int, packet) {
|
|||||||
consumed, subs := parsePackets(stream[7+size+parsed:])
|
consumed, subs := parsePackets(stream[7+size+parsed:])
|
||||||
parsedPacket.subPackets = append(parsedPacket.subPackets, subs)
|
parsedPacket.subPackets = append(parsedPacket.subPackets, subs)
|
||||||
parsed += consumed
|
parsed += consumed
|
||||||
if size == 11 && int64(len(parsedPacket.subPackets)) == subpacketlength {
|
if size == 11 && len(parsedPacket.subPackets) == subpacketlength {
|
||||||
return parsed + 7 + size, parsedPacket
|
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
|
return parsed + 7 + size, parsedPacket
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user