func (co *UserManager) ResultOK() { result := new(lm.Data_Result) result.Msg = new(string) *result.Msg = "ok" result.Code = new(int32) *result.Code = 1 data := new(lm.Data) data.Type = new(int32) *data.Type = 2 data.Time = new(uint64) *data.Time = 11111111 //TODO data.Version = new(int32) *data.Version = 1 data.Res = result data_, _ := proto.Marshal(data) co.Conn.Write(Size(data_)) co.Conn.Write(data_) }
func (co *UserManager) Output(userMap map[string]chan *lm.Data_Message, user *lm.Data_User) { defer co.Conn.Close() defer delete(userMap, user.GetUser()) //// del for { msg := <-userMap[user.GetUser()] println(user.GetUser(), "======= output") outData := new(lm.Data) outData.Version = new(int32) outData.Type = new(int32) outData.Time = new(uint64) *outData.Version = 1 *outData.Type = int32(lm.Data_MESSAGE) *outData.Time = 111111 outData.Msg = msg /////// data, _ := proto.Marshal(outData) dataSize := make([]byte, 4) binary.BigEndian.PutUint32(dataSize, uint32(len(data))) ////TODO data的长度要做限制,要不然会出现计数不准的情况 co.Conn.Write(dataSize) co.Conn.Write(data) } }