Example #1
0
func (this *MulticastPacketFactory) CreateMulticastPacket(data interface{}, sis ...*protocol.MCSessionUnion) proto.Message {
	pack := &protocol.SSPacketMulticast{Sessions: sis}
	if byteData, ok := data.([]byte); ok {
		pack.Data = byteData
	} else {
		byteData, err := netlib.MarshalPacket(data)
		if err == nil {
			pack.Data = byteData
		} else {
			logger.Info("MulticastPacketFactory.CreateMulticastPacket err:", err)
		}
	}
	proto.SetDefaults(pack)
	return pack
}
Example #2
0
func (this *BroadcastPacketFactory) CreateBroadcastPacket(sp *protocol.BCSessionUnion, data interface{}) proto.Message {
	pack := &protocol.SSPacketBroadcast{SessParam: sp}
	if byteData, ok := data.([]byte); ok {
		pack.Data = byteData
	} else {
		byteData, err := netlib.MarshalPacket(data)
		if err == nil {
			pack.Data = byteData
		} else {
			logger.Warn("BroadcastPacketFactory.CreateBroadcastPacket err:", err)
		}
	}
	proto.SetDefaults(pack)
	return pack
}