Skip to content

Instantly share code, notes, and snippets.

@Jsewill
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jsewill/3f60d88618fd816cf5d3 to your computer and use it in GitHub Desktop.
Save Jsewill/3f60d88618fd816cf5d3 to your computer and use it in GitHub Desktop.
Makes a packet slice by splitting "slice"
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