cross socket和msgpack的数据序列和还原
procedure TForm1.Button1Click(Sender: TObject);begin var pack: TSimpleMsgPack := TSimpleMsgPack.Create; pack.ForcePathObject('sql').AsString := '测试'; IdTCPClient1.IOHandler.Write(tidbytes(pack.EncodeToBytes)); //发送TBytesend;procedure TcrossTcp.OnReceived(Sender: TObject; AConnection: ICrossConnection; ABuf: Pointer; ALen: Integer);begin var b: tbytes; SetLength(b, ALen); Move(ABuf^, b[0], ALen); // 还原TBytes var pack: TSimpleMsgPack := TSimpleMsgPack.Create; pack.DecodeFromBytes(b); Writeln(pack.ForcePathObject('sql').AsString);end;procedure TForm1.Button1Click(Sender: TObject);begin var pack: TSimpleMsgPack := TSimpleMsgPack.Create; pack.ForcePathObject('sql').AsString := '测试'; var ms: TMemoryStream := TMemoryStream.Create; pack.EncodeToStream(ms); ms.Position := 0; IdTCPClient1.IOHandler.Write(ms, ms.Size); //发送流end;procedure TcrossTcp.OnReceived(Sender: TObject; AConnection: ICrossConnection; ABuf: Pointer; ALen: Integer);begin var ms: TMemoryStream := TMemoryStream.Create; ms.Size := ALen; ms.Write(ABuf^, ALen);//还原流 var pack: TSimpleMsgPack := TSimpleMsgPack.Create; ms.Position := 0; pack.DecodeFromStream(ms); Writeln(pack.ForcePathObject('sql').AsString);end;