20 lines
457 B
Haxe
20 lines
457 B
Haxe
package ru.m.connect;
|
|
|
|
import haxe.io.Bytes;
|
|
import haxe.io.BytesOutput;
|
|
import protohx.Message;
|
|
|
|
class PacketUtil {
|
|
public static function fromBytes<P:Message>(bytes:Bytes, factory:Class<P>):P {
|
|
var packet:P = Type.createInstance(factory, []);
|
|
packet.mergeFrom(bytes);
|
|
return packet;
|
|
}
|
|
|
|
public static function toBytes<P:Message>(packet:P):Bytes {
|
|
var out = new BytesOutput();
|
|
packet.writeTo(out);
|
|
return out.getBytes();
|
|
}
|
|
}
|