Ejemplo n.º 1
0
    public bool TryParse(byte[] data, out PackageHead head, out byte[] bodyBytes)
    {
        bodyBytes = new byte[0];
        head      = null;
        int pos = 0;

        if (data == null || data.Length == 0)
        {
            return(false);
        }
        Sproto.SprotoPack pack = new Sproto.SprotoPack();
        var bin = pack.unpack(data);
        SprotoTypeDeserialize d       = new SprotoTypeDeserialize(bin);
        SprotoTypeReader      sReader = new SprotoTypeReader(bin, 0, bin.Length);

        SprotoType.package headpack = new SprotoType.package();
        headpack.init(sReader);
        head            = new PackageHead();
        head.ActionId   = headpack.protoId;
        head.MsgId      = headpack.session;
        head.StatusCode = headpack.errorcode;

        if (sReader.Length - sReader.Position > 0)
        {
            bodyBytes = new byte[sReader.Length - sReader.Position];
            sReader.Read(bodyBytes, 0, bodyBytes.Length);
        }
        return(true);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// rebuild socket send hearbeat package
    /// </summary>
    public SocketPackage ReBuildHearbeat()
    {
        var writer = NetWriter.Instance;

        SprotoType.package headPack = new SprotoType.package()
        {
            protoId   = 2,
            session   = NetWriter.MsgId,
            errorcode = 0,
        };
        Sproto.SprotoPack pack      = new Sproto.SprotoPack();
        byte[]            headBytes = headPack.encode();
        writer.SetHeadBuffer(headBytes);
        writer.SetBodyData(new byte[0]);
        var data = writer.PostData();

        NetWriter.resetData();
        _hearbeatPackage = data;
        SocketPackage package = new SocketPackage();

        package.MsgId      = (int)headPack.session;
        package.ActionId   = 2;
        package.Action     = ActionFactory.Create(package.ActionId);
        package.SendTime   = DateTime.Now;
        package.HasLoading = false;
        return(package);
    }
Ejemplo n.º 3
0
    public byte[] BuildHearbeatPackage()
    {
        var writer = NetWriter.Instance;

        SprotoType.package headPack = new SprotoType.package()
        {
            protoId   = 2,
            session   = NetWriter.MsgId,
            errorcode = 0,
        };
        Sproto.SprotoPack pack      = new Sproto.SprotoPack();
        byte[]            headBytes = headPack.encode();
        writer.SetHeadBuffer(headBytes);
        writer.SetBodyData(new byte[0]);
        var data = writer.PostData();

        NetWriter.resetData();
        return(data);
    }