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)) }
// 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 }
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), } }
func (p *ENetPacket) Destroy() { C.enet_packet_destroy((*C.ENetPacket)(p)) }