Beispiel #1
0
func PacketData(seqId uint64, data []byte) []byte {
	writer := packet.Writer()
	//size uint16
	writer.WriteU16(uint16(len(data)))
	//crc32 uint32
	crc32 := crc32.Checksum(data, crc32.IEEETable)

	writer.WriteU32(crc32)
	//seqid uint64
	writer.WriteU64(seqId)
	//data (uid + msgid + msgpack)
	writer.WriteRawBytes(data)

	return writer.Data()
}
Beispiel #2
0
func encode(uid uint64, msgid int32, reCode int32, _ack interface{}) []byte {
	var mh codec.MsgpackHandle
	var out []byte
	mh.EncodeOptions.StructToArray = true
	encode := codec.NewEncoderBytes(&out, &mh)
	encode.Encode(_ack)
	writer := packet.Writer()
	//计算包的长度
	writer.WriteU64(uid)
	writer.WriteS32(msgid)
	writer.WriteS32(reCode)
	writer.WriteRawBytes(out)

	return writer.Data()
}