Exemple #1
0
//Creates MetaData from Data to send
func CreateSendMetaData(data []byte) (meta MetaData, tcpData []byte) {
	meta.DataId = lib.Random(1, IntMax)
	tcpData = append(tcpData, lib.Uin32ToBytes(meta.DataId)...)
	meta.Length = uint32(len(data))
	tcpData = append(tcpData, lib.Uin32ToBytes(meta.Length)...)
	meta.PocketCount = lib.CalcPocketCount(meta.Length, uint32(PocketLength))
	meta.StopUDP = false
	meta.DataStack = make(map[uint32][]byte, int(meta.PocketCount))
	var (
		pos, next int
		current   uint32
	)
	data_id_byte := lib.Uin32ToBytes(meta.DataId)
	var append_data []byte
	for i := uint32(0); i < meta.PocketCount; i++ {
		current = uint32(i)
		pos = int(i * PocketLength)

		meta.DataStack[current] = append(meta.DataStack[current], data_id_byte...)
		meta.DataStack[current] = append(meta.DataStack[current], lib.Uin32ToBytes(current)...)
		next = pos + int(PocketLength)
		if uint32(next) > meta.Length {
			append_data = append(data[pos:], lib.FakeData((next - int(meta.Length)))...)
		} else {
			append_data = data[pos:next]
		}
		meta.DataStack[current] = append(meta.DataStack[current], append_data...)
	}
	return
}
Exemple #2
0
//Crates MetaData from TCP received headers
func CreateMetaData(data []byte) (meta MetaData, converted bool) {
	converted = true
	meta.DataId, converted = lib.BytesToUint32(data[0:4])
	if !converted {
		lib.Log("Error Converting DataID !!")
		return
	}
	meta.Length, converted = lib.BytesToUint32(data[4:8])
	if !converted {
		lib.Log("Error Converting Length !!")
		return
	}
	meta.PocketCount = lib.CalcPocketCount(meta.Length, uint32(PocketLength))
	meta.StopUDP = false
	meta.DataStack = make(map[uint32][]byte)
	return
}