/*
文件名:PacketClass.nut
路径:BaseClass/PacketClass/PacketClass.nut
创建日期:2024-04-07	16:59
文件用途:数据包类
*/
class Packet extends Base_C_Object {

    //传参就构造 不传就new一个新包
    constructor(...) {
        if (vargv.len() > 0) {
            base.constructor(vargv[0]);
        } else {
            local Buf = Sq_New_Point(0x20000);
            Sq_CallFunc(S_Ptr("0x858DD4C"), "void", ["pointer"], Buf);
            base.constructor(Buf);
        }
    }

    function Put_Header(a, b) {
        Sq_CallFunc(S_Ptr("0x80CB8FC"), "int", ["pointer", "int", "int"], this.C_Object, a, b);
        // Sq_Packet_Put_header(this.C_Object, a, b);
    }

    function Put_Byte(Value) {
        Sq_CallFunc(S_Ptr("0x80CB920"), "int", ["pointer", "int"], this.C_Object, Value);
        // Sq_Packet_Put_byte(this.C_Object, Value);
    }

    function Put_Short(Value) {
        Sq_CallFunc(S_Ptr("0x80D9EA4"), "int", ["pointer", "int"], this.C_Object, Value);
        // Sq_Packet_Put_short(this.C_Object, Value);
    }

    function Put_Int(Value) {
        Sq_CallFunc(S_Ptr("0x80CB93C"), "int", ["pointer", "int"], this.C_Object, Value);
        // Sq_Packet_Put_int(this.C_Object, Value);
    }

    function Put_Binary(Value) {
        local StrPoint = Str_Ptr(Value);
        Sq_CallFunc(S_Ptr("0x811DF08"), "int", ["pointer", "pointer", "int"], this.C_Object, StrPoint, Value.len());
        // Sq_Packet_Put_binary(this.C_Object, Value);
    }

    function Put_BinaryEx(Str, Len) {
        Sq_CallFunc(S_Ptr("0x811DF08"), "int", ["pointer", "pointer", "int"], this.C_Object, Str, Len);
        //Sq_Packet_Put_binaryex(this.C_Object, Str, Len);
    }

    function Put_BinaryEx_M(Str, Len) {
        // Sq_Packet_Put_binaryex(this.C_Object, Str, Len);
        Sq_CallFunc(S_Ptr("0x811DF08"), "int", ["pointer", "pointer", "int"], this.C_Object, Str, Len);
    }

    function Put_Str(Str, Len) {
        Sq_CallFunc(S_Ptr("0x81B73E4"), "int", ["pointer", "pointer", "int"], this.C_Object, Str, Len);
    }

    function Finalize(Value) {
        Sq_Packet_Finalize(this.C_Object, Value);
    }

    function Send(SUser) {
        Sq_Packet_Send(SUser.C_Object, this.C_Object);
    }

    function Delete() {
        Sq_CallFunc(S_Ptr("0x858DE80"), "void", ["pointer"], this.C_Object);
        Sq_Delete_Point(this.C_Object);
        // Sq_Packet_Delete(this.C_Object);
    }
}