Exemplo n.º 1
0
func TestMsgHeaderGateClient(t *testing.T) {
	byMsg := make([]byte, 4)
	msgHeader := NewMsgHeaderGateClient(1, 2, bsn_common.TMsgLen(len(byMsg)))

	vUserId := bsn_common.MakeGateUserId(1, 2)
	if msgHeader.UserId() != vUserId {
		t.Error(msgHeader.UserId())
	}
	if msgHeader.Len() != 4 {
		t.Error(msgHeader.Len())
	}

	if bsn_common.TMsgLen(unsafe.Sizeof(*msgHeader)) != CSMsgHeaderGateClient_Size {
		t.Errorf("bsn_common.TMsgLen(unsafe.Sizeof(*msgHeader))=%v != CSMsgHeaderGateClient_Size=%v", bsn_common.TMsgLen(unsafe.Sizeof(*msgHeader)), CSMsgHeaderGateClient_Size)
	}

	byDatas := msgHeader.Serialize()
	GSLog.Mustln(byDatas)

	msgHeader = NewMsgHeaderGateClientFromBytes(byDatas)

	if msgHeader.UserId() != vUserId {
		t.Error(msgHeader.UserId())
	}
	if msgHeader.Len() != 4 {
		t.Error(msgHeader.Len())
	}
}
Exemplo n.º 2
0
func NewClient2GateMsg(vu8ServerType, vu8ServerId uint8, u16Type uint16, byMsg []byte) []byte {
	vTMsgLen := bsn_common.TMsgLen(len(byMsg))
	vSMsgHeader := NewMsgHeader(bsn_common.TMsgType(u16Type), vTMsgLen)
	vSMsgHeaderGateClient := NewMsgHeaderGateClient(vu8ServerType, vu8ServerId, vTMsgLen+bsn_common.TMsgLen(unsafe.Sizeof(*vSMsgHeader)))

	byData := make([]byte, vSMsgHeaderGateClient.Len()+bsn_common.TMsgLen(unsafe.Sizeof(*vSMsgHeaderGateClient)))
	copy(byData, vSMsgHeaderGateClient.Serialize())
	copy(byData[int(unsafe.Sizeof(*vSMsgHeaderGateClient)):], vSMsgHeader.Serialize())
	copy(byData[int(unsafe.Sizeof(*vSMsgHeaderGateClient))+int(unsafe.Sizeof(*vSMsgHeader)):], byMsg)
	GSLog.Debugln("byData= ", byData)
	return byData
}
Exemplo n.º 3
0
func (this *SMsgHeaderServer2Gate) DeSerialize(byDatas []byte) bsn_common.TMsgLen {
	vTMsgLen := this.SMsgHeader.DeSerialize(byDatas)

	this.M_TMsgLenServerMsg = bsn_common.TMsgLen(binary.LittleEndian.Uint16(byDatas[vTMsgLen:]))
	vTMsgLen += 2

	return vTMsgLen
}
Exemplo n.º 4
0
func (this *SMsgHeader) DeSerialize(byDatas []byte) bsn_common.TMsgLen {
	var vTMsgLen bsn_common.TMsgLen = 0

	this.M_TMsgType = bsn_common.TMsgType(binary.LittleEndian.Uint16(byDatas[vTMsgLen:]))
	vTMsgLen += 2
	this.M_TMsgLen = bsn_common.TMsgLen(binary.LittleEndian.Uint16(byDatas[vTMsgLen:]))
	vTMsgLen += 2

	return vTMsgLen
}
Exemplo n.º 5
0
func (this *SMsg_Server2Gate_ClientMsg) DeSerialize(byDatas []byte) bsn_common.TMsgLen {
	var vTMsgLen bsn_common.TMsgLen = 0

	this.M_ClientId = binary.LittleEndian.Uint16(byDatas[vTMsgLen:])
	vTMsgLen += 2

	this.M_byMsg = byDatas[vTMsgLen:]
	vTMsgLen += bsn_common.TMsgLen(len(this.M_byMsg))

	return vTMsgLen
}
Exemplo n.º 6
0
func (this *SMsg_Server2Gate_ClientMsg) Serialize2Byte(byDatas []byte) bsn_common.TMsgLen {
	var vTMsgLen bsn_common.TMsgLen = 0

	binary.LittleEndian.PutUint16(byDatas[vTMsgLen:], this.M_ClientId)
	vTMsgLen += 2

	copy(byDatas[vTMsgLen:], this.M_byMsg)
	vTMsgLen += bsn_common.TMsgLen(len(this.M_byMsg))

	return vTMsgLen
}
Exemplo n.º 7
0
func NewMsgWithMsgHeader(vTMsgType bsn_common.TMsgType, byMsg []byte) []byte {
	vLen := len(byMsg)
	vMsg := NewMsgHeader(vTMsgType, bsn_common.TMsgLen(vLen))

	byData := make([]byte, vLen+int(CSMsgHeader_Size))
	vLen = int(vMsg.Serialize2Byte(byData))
	if byMsg != nil {
		copy(byData[vLen:], byMsg)
	}

	return byData
}
Exemplo n.º 8
0
func (this *SMsg_Gate2Server_ClientMsg) DeSerialize(byDatas []byte) bsn_common.TMsgLen {
	var vTMsgLen bsn_common.TMsgLen = 0

	this.M_ClientId = binary.LittleEndian.Uint16(byDatas[vTMsgLen:])
	vTMsgLen += 2

	vTMsgLen += this.M_SMsgHeader.DeSerialize(byDatas[vTMsgLen:])

	this.M_byMsgBody = byDatas[vTMsgLen:]
	vTMsgLen += bsn_common.TMsgLen(len(this.M_byMsgBody))

	return vTMsgLen
}
Exemplo n.º 9
0
func (this *SMsg_Gate2Server_ClientMsg) Serialize2Byte(byDatas []byte) bsn_common.TMsgLen {
	var vTMsgLen bsn_common.TMsgLen = 0

	binary.LittleEndian.PutUint16(byDatas[vTMsgLen:], this.M_ClientId)
	vTMsgLen += 2

	vTMsgLen += this.M_SMsgHeader.Serialize2Byte(byDatas[vTMsgLen:])

	copy(byDatas[vTMsgLen:], this.M_byMsgBody)
	vTMsgLen += bsn_common.TMsgLen(len(this.M_byMsgBody))

	return vTMsgLen
}
Exemplo n.º 10
0
func TestMsgHeaderGateServer(t *testing.T) {
	byMsg := make([]byte, 4)
	msgHeader := NewMsgHeaderGateServer(CServerMsgType_ToUser, 1, 2, bsn_common.TMsgLen(len(byMsg)))
	if msgHeader.ServerMsgType() != CServerMsgType_ToUser {
		t.Error(msgHeader.ServerMsgType())
	}
	if msgHeader.GroupId() != 1 {
		t.Error(msgHeader.GroupId())
	}
	if msgHeader.UserId() != 2 {
		t.Error(msgHeader.UserId())
	}
	if msgHeader.Len() != 4 {
		t.Error(msgHeader.Len())
	}

	if bsn_common.TMsgLen(unsafe.Sizeof(*msgHeader)) != CSMsgHeaderGateServer_Size {
		t.Errorf("bsn_common.TMsgLen(unsafe.Sizeof(*msgHeader))=%v != CSMsgHeaderGateServer_Size=%v", bsn_common.TMsgLen(unsafe.Sizeof(*msgHeader)), CSMsgHeaderGateServer_Size)
	}

	byDatas := msgHeader.Serialize()
	GSLog.Mustln(byDatas)

	msgHeader = NewMsgHeaderGateServerFromBytes(byDatas)
	if msgHeader.ServerMsgType() != CServerMsgType_ToUser {
		t.Error(msgHeader.ServerMsgType())
	}
	if msgHeader.GroupId() != 1 {
		t.Error(msgHeader.GroupId())
	}
	if msgHeader.UserId() != 2 {
		t.Error(msgHeader.UserId())
	}
	if msgHeader.Len() != 4 {
		t.Error(msgHeader.Len())
	}
}
Exemplo n.º 11
0
func WriteMsgWithMsgHeader(conn net.Conn, u16Type uint16, byData []byte) (err error) {
	vTMsgLen := bsn_common.TMsgLen(len(byData))
	vSMsgHeader := NewMsgHeader(bsn_common.TMsgType(u16Type), vTMsgLen)

	_, err = conn.Write(vSMsgHeader.Serialize())
	if err != nil {
		return
	}

	if vTMsgLen > 0 {
		_, err = conn.Write(byData)
		if err != nil {
			return
		}
	}

	return
}
Exemplo n.º 12
0
func TestMsgHeader(t *testing.T) {
	msgHeader := NewMsgHeader(1, 2)
	if msgHeader.Type() != 1 {
		t.Error(msgHeader.Type())
	}
	if msgHeader.Len() != 2 {
		t.Error(msgHeader.Len())
	}

	if bsn_common.TMsgLen(unsafe.Sizeof(*msgHeader)) != CSMsgHeader_Size {
		t.Errorf("bsn_common.TMsgLen(unsafe.Sizeof(*msgHeader))=%v != CSMsgHeader_Size=%v", bsn_common.TMsgLen(unsafe.Sizeof(*msgHeader)), CSMsgHeader_Size)
	}

	byDatas := msgHeader.Serialize()
	GSLog.Mustln(byDatas)

	msgHeader = NewMsgHeaderFromBytes(byDatas)
	if msgHeader.Type() != 1 {
		t.Error(msgHeader.Type())
	}
	if msgHeader.Len() != 2 {
		t.Error(msgHeader.Len())
	}
}
Exemplo n.º 13
0
func (this *SMsgHeaderServer2Gate) FillMsg(vTServer2GateMsgType TServer2GateMsgType, by2GateMsg, by2ClientMsg []byte) {
	this.SMsgHeader.Fill(bsn_common.TMsgType(vTServer2GateMsgType), bsn_common.TMsgLen(len(by2GateMsg)))
	this.Fill(bsn_common.TMsgLen(len(by2ClientMsg)))
}