Permalink
Browse files

Fixing RPC Bytes handling

  • Loading branch information...
MattTuttle committed Feb 25, 2014
1 parent da0cf72 commit cc0ef0c39aa6621e97e8ba7398cfa34b426347ef
Showing with 21 additions and 6 deletions.
  1. +14 −5 hxnet/base/Protocol.hx
  2. +7 −1 hxnet/protocols/RPC.hx
View
@@ -9,7 +9,10 @@ import haxe.io.Input;
class Protocol implements hxnet.interfaces.Protocol
{
public function new() { }
public function new()
{
_packetLength = _packetPos = 0;
}
public function isConnected():Bool { return this.cnx != null; }
@@ -26,7 +29,7 @@ class Protocol implements hxnet.interfaces.Protocol
}
}
private function fullPacketReceived(input:Input):Void
private function packetReceived(input:Input):Void
{
}
@@ -36,12 +39,18 @@ class Protocol implements hxnet.interfaces.Protocol
try
{
_packetLength = input.readInt32();
if (_packetLength == 0) return false;
_packet = Bytes.alloc(_packetLength);
}
catch (e:Eof)
{
return false;
}
catch (e:Dynamic)
{
trace(e);
return false;
}
return true;
}
@@ -64,7 +73,7 @@ class Protocol implements hxnet.interfaces.Protocol
if (_packetPos >= _packetLength)
{
var input = new BytesInput(_packet);
fullPacketReceived(input);
packetReceived(input);
_packetPos = 0;
break;
}
@@ -78,7 +87,7 @@ class Protocol implements hxnet.interfaces.Protocol
private var cnx:Connection;
private var _packetLength:Int = 0;
private var _packetPos:Int = 0;
private var _packetLength:Int;
private var _packetPos:Int;
private var _packet:Bytes;
}
View
@@ -15,7 +15,7 @@ class RPC extends hxnet.base.Protocol
public var dispatcher:Dynamic;
override private function fullPacketReceived(input:Input)
override private function packetReceived(input:Input)
{
var func = readString(input);
var numArgs = input.readInt16();
@@ -32,6 +32,11 @@ class RPC extends hxnet.base.Protocol
arguments.push(input.readInt8() == 1 ? true : false);
case TYPE_STRING:
arguments.push(readString(input));
case TYPE_BYTES:
var length = input.readInt32();
var bytes = Bytes.alloc(length);
input.readFullBytes(bytes, 0, length);
arguments.push(bytes);
case TYPE_OBJECT:
arguments.push(haxe.Unserializer.run(readString(input)));
}
@@ -95,6 +100,7 @@ class RPC extends hxnet.base.Protocol
}
else if (Std.is(arg, Bytes))
{
o.writeInt8(TYPE_BYTES);
o.writeInt32(arg.length);
o.writeFullBytes(arg, 0, arg.length);
}

0 comments on commit cc0ef0c

Please sign in to comment.