Last active
August 29, 2015 14:21
-
-
Save Jsewill/3f60d88618fd816cf5d3 to your computer and use it in GitHub Desktop.
Makes a packet slice by splitting "slice"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ( | |
PACKET_DATA_SIZE uint = 65507 | |
) | |
var packets [][]byte | |
if length := len(slice); length >= PACKET_DATA_SIZE { | |
limit := length/PACKET_DATA_SIZE | |
for i := 0; i < limit; i++ { | |
if (i+1)*PACKET_DATA_SIZE < length { | |
packets = append(packets, slice[i*PACKET_DATA_SIZE:(i+1)*PACKET_DATA_SIZE]) | |
continue | |
} | |
packets = append(packets, slice[i*PACKET_DATA_SIZE:]) | |
} | |
} else { | |
packets = append(packets, slice) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment