Ejemplo n.º 1
0
func from_packet(c_packet *C.ENetPacket) []byte {
	log.Printf("from packet: %#v", c_packet)
	if c_packet == nil {
		return nil
	}
	defer C.enet_packet_destroy(c_packet)
	return C.GoBytes(unsafe.Pointer(c_packet.data), C.int(c_packet.dataLength))
}
Ejemplo n.º 2
0
// enet_peer_send
func (peer *Peer) Send(channelID uint8, data []byte, flags Flag) error {
	c_packet := new_packet(data, flags)
	defer C.enet_packet_destroy(c_packet)

	ret := C.enet_peer_send(peer.peer, C.enet_uint8(channelID), c_packet)
	if ret < 0 {
		return errors.New("ENet failed to send packet")
	}
	return nil
}
Ejemplo n.º 3
0
func eventFromCEvent(cEventI interface{}) Event {
	cEvent := cEventI.(*C.ENetEvent)
	defer C.enet_packet_destroy(cEvent.packet)

	return Event{
		Type:      EventType(cEvent._type),
		Peer:      peerFromCPeer(cEvent.peer),
		ChannelId: uint8(cEvent.channelID),
		Data:      uint32(cEvent.data),
		Packet:    packetFromCPacket(cEvent.packet),
	}
}
Ejemplo n.º 4
0
Archivo: packet.go Proyecto: boj/goenet
func (p *ENetPacket) Destroy() {
	C.enet_packet_destroy((*C.ENetPacket)(p))
}