// Use this for initialization void Start() { ProtoMapper.Initilize(); ProtoPacketQueueManager.instance.AddHandleListener(typeof(Chat_S2C), OnChatResp); ProtoPacketQueueManager.instance.AddHandleListener(typeof(GetUserInfo_S2C), OnGetPlayerInfoResp); EncodeAndDecodeTest(); }
private void CompanyJob_CRU_Test() { var client = new CompanyJob.CompanyJobClient(_channel); // add CompanyJobProto proto = ProtoMapper.MapFromCompanyJobPoco(_companyJob); CompanyJobList protos = new CompanyJobList(); protos.Items.Add(proto); client.AddCompanyJob(protos); proto = CheckGetCompanyJob(client, new CompanyJobKey() { Id = proto.Id }, proto); // check List protos = client.GetCompanyJobs(new Empty()); Assert.IsTrue(protos.Items.Count > 0); // check update proto.IsCompanyHidden = true; proto.IsInactive = true; proto.ProfileCreated = ConvertDateTime2TimeStamp(Faker.Date.Past()); protos = new CompanyJobList(); protos.Items.Add(proto); client.UpdateCompanyJob(protos); CheckGetCompanyJob(client, new CompanyJobKey() { Id = proto.Id }, proto); }
private void SecurityLoginsLog_CRU_Test() { var client = new SecurityLoginsLog.SecurityLoginsLogClient(_channel); // add SecurityLoginsLogProto proto = ProtoMapper.MapFromSecurityLoginsLogPoco(_securityLoginLog); SecurityLoginsLogList protos = new SecurityLoginsLogList(); protos.Items.Add(proto); client.AddSecurityLoginsLog(protos); proto = CheckGetSecurityLoginsLog(client, new SecurityLoginsLogKey() { Id = proto.Id }, proto); // check List protos = client.GetSecurityLoginsLogs(new Empty()); Assert.IsTrue(protos.Items.Count > 0); // check update proto.IsSuccesful = false; proto.LogonDate = ConvertDateTime2TimeStamp(Faker.Date.PastWithTime()); proto.SourceIP = Faker.Internet.IPv4().PadRight(15); protos = new SecurityLoginsLogList(); protos.Items.Add(proto); client.UpdateSecurityLoginsLog(protos); // e9261fa9-f0c3-4603-b400-63a5f26952c7 CheckGetSecurityLoginsLog(client, new SecurityLoginsLogKey() { Id = proto.Id }, proto); }
private void CompanyJobEducation_CRU_Test() { var client = new CompanyJobEducation.CompanyJobEducationClient(_channel); // add CompanyJobEducationProto proto = ProtoMapper.MapFromCompanyJobEducationPoco(_companyJobEducation); CompanyJobEducationList protos = new CompanyJobEducationList(); protos.Items.Add(proto); client.AddCompanyJobEducation(protos); proto = CheckGetCompanyJobEducation(client, new CompanyJobEducationKey() { Id = proto.Id }, proto); // check List protos = client.GetCompanyJobEducations(new Empty()); Assert.IsTrue(protos.Items.Count > 0); // check update proto.Importance = 1; proto.Major = Truncate(Faker.Lorem.Sentence(), 100); protos = new CompanyJobEducationList(); protos.Items.Add(proto); client.UpdateCompanyJobEducation(protos); CheckGetCompanyJobEducation(client, new CompanyJobEducationKey() { Id = proto.Id }, proto); }
private void SystemLanguageCode_CRU_Test() { var client = new SystemLanguageCode.SystemLanguageCodeClient(_channel); // add SystemLanguageCodeProto proto = ProtoMapper.MapFromSystemLanguageCodePoco(_systemLangCode); SystemLanguageCodeList protos = new SystemLanguageCodeList(); protos.Items.Add(proto); client.AddSystemLanguageCode(protos); CheckGetSystemLanguageCode(client, new SystemLanguageCodeKey() { LanguageID = proto.LanguageID }, proto); // check List protos = client.GetSystemLanguageCodes(new Empty()); Assert.IsTrue(protos.Items.Count > 0); // check update proto.Name = Truncate(Faker.Lorem.Sentence(), 50); proto.NativeName = Truncate(Faker.Lorem.Sentence(), 50); protos = new SystemLanguageCodeList(); protos.Items.Add(proto); client.UpdateSystemLanguageCode(protos); CheckGetSystemLanguageCode(client, new SystemLanguageCodeKey() { LanguageID = proto.LanguageID }, proto); }
private void ApplicantJobApplication_CRU_Test() { var client = new ApplicantJobApplication.ApplicantJobApplicationClient(_channel); // add ApplicantJobApplicationProto proto = ProtoMapper.MapFromApplicantJobApplicationPoco(_applicantJobApplication); ApplicantJobApplicationList protos = new ApplicantJobApplicationList(); protos.Items.Add(proto); client.AddApplicantJobApplication(protos); proto = CheckGetApplicantJobApplication(client, new ApplicantJobApplicationKey() { Id = proto.Id }, proto); // check List protos = client.GetApplicantJobApplications(new Empty()); Assert.IsTrue(protos.Items.Count > 0); // check update proto.ApplicationDate = ConvertDateTime2TimeStamp(Faker.Date.Recent()); protos = new ApplicantJobApplicationList(); protos.Items.Add(proto); client.UpdateApplicantJobApplication(protos); // e9261fa9-f0c3-4603-b400-63a5f26952c7 CheckGetApplicantJobApplication(client, new ApplicantJobApplicationKey() { Id = proto.Id }, proto); }
/// <summary> /// 在刚好接收完一个完整的协议的时候调用,构造一个完整的协议包 /// </summary> public void CreatePacketFromBuffer() { try { int bodyLen = BodyLength; int protoCode = ProtoCode; object decoder = ProtoMapper.GetProtoDecoder(protoCode); if (decoder != null) { byte[] dataBytes = new byte[bodyLen - ProtoCodeLength]; //协议体等于总的协议体长度减去协议号字节 Array.Copy(protobuffBytes, Header_Length + ProtoCodeLength, dataBytes, 0, dataBytes.Length); Debug.Log("Content :" + SocketController.ByteArrayToStr(dataBytes)); System.IO.MemoryStream stream_output = new System.IO.MemoryStream(dataBytes); RuntimeTypeModel.Default.Deserialize(stream_output, decoder, decoder.GetType()); ProtoPacketQueueManager.AddPacket(decoder); //用队列在帧更新的时候处理协议,是因为有可能是在多线程下通信,而有些操作是只能在主线程执行 } } catch (System.Exception ex) { Debug.LogError("协议包创建出错:" + ex.Message + ex.StackTrace); } }
/// <summary> /// 在刚好接收完一个完整的协议的时候调用,构造一个完整的协议包 /// </summary> public void CreatePacketFromBuffer() { byte[] packetBytes = new byte[BodyLength]; //从缓存里获取属于这个协议的内容 Array.Copy(protobuffBytes, Header_Length, packetBytes, 0, packetBytes.Length); byte[] protoCodeBytes = new byte[4]; Array.Copy(packetBytes, 0, protoCodeBytes, 0, protoCodeBytes.Length); //协议的前面四位为协议号 int protoCode = BitConverter.ToInt32(protoCodeBytes, 0); ProtoBase_S2C decoder = ProtoMapper.GetProtoDecoder(protoCode); if (decoder != null) { decoder.Decode(packetBytes); ProtoPacketQueueManager.instance.AddPacket(decoder); } }
private void SecurityLogin_CRU_Test() { var client = new SecurityLogin.SecurityLoginClient(_channel); // add SecurityLoginProto proto = ProtoMapper.MapFromSecurityLoginPoco(_securityLogin); SecurityLoginList protos = new SecurityLoginList(); protos.Items.Add(proto); client.AddSecurityLogin(protos); proto = CheckGetSecurityLogin(client, new SecurityLoginKey() { Id = proto.Id }, proto); // check List protos = client.GetSecurityLogins(new Empty()); Assert.IsTrue(protos.Items.Count > 0); // check update proto.Login = Faker.User.Email(); proto.AgreementAccepted = ConvertDateTime2TimeStamp(Faker.Date.PastWithTime()); proto.Created = ConvertDateTime2TimeStamp(Faker.Date.PastWithTime()); proto.EmailAddress = Faker.User.Email(); proto.ForceChangePassword = true; proto.FullName = Faker.Name.FullName(); proto.IsInactive = true; proto.IsLocked = true; proto.Password = "******"; proto.PasswordUpdate = ConvertDateTime2TimeStamp(Faker.Date.Forward()); proto.PhoneNumber = "416-416-9889"; proto.PrefferredLanguage = "FR".PadRight(10); protos = new SecurityLoginList(); protos.Items.Add(proto); client.UpdateSecurityLogin(protos); CheckGetSecurityLogin(client, new SecurityLoginKey() { Id = proto.Id }, proto); }
public static void Send(object o) { int code = ProtoMapper.GetProtoCode(o.GetType()); System.IO.MemoryStream stream = new System.IO.MemoryStream(); RuntimeTypeModel.Default.Serialize(stream, o); //先序列出协议体 byte[] contentBytes = stream.ToArray(); List <byte> byteList = new List <byte>(); byteList.AddRange(contentBytes); //添加协议号 byte[] bs = protoCodeToBytes(code); byteList.InsertRange(0, bs); //添加协议长度信息 byte[] lenBytes = protoLengthToBytes(byteList.Count); Debug.Log("总长度" + lenBytes.Length); byteList.InsertRange(0, lenBytes); SocketController.instance.SendBytes(byteList.ToArray()); }
private void ApplicantProfile_CRU_Test() { var client = new ApplicantProfile.ApplicantProfileClient(_channel); // add ApplicantProfileProto proto = ProtoMapper.MapFromApplicantProfilePoco(_applicantProfile); ApplicantProfileList protos = new ApplicantProfileList(); protos.Items.Add(proto); client.AddApplicantProfile(protos); proto = CheckGetApplicantProfile(client, new ApplicantProfileKey() { Id = proto.Id }, proto); // check List protos = client.GetApplicantProfiles(new Empty()); Assert.IsTrue(protos.Items.Count > 0); // check update proto.City = Faker.Address.CityPrefix(); proto.Currency = "US".PadRight(10); proto.CurrentRate = proto.CurrentRate.ConvertFrom(61.25M); proto.CurrentSalary = proto.CurrentSalary.ConvertFrom(77500); proto.Province = Truncate(Faker.Address.Province(), 10).PadRight(10); proto.Street = Truncate(Faker.Address.StreetName(), 100); proto.PostalCode = Truncate(Faker.Address.CanadianZipCode(), 20).PadRight(20); protos = new ApplicantProfileList(); protos.Items.Add(proto); client.UpdateApplicantProfile(protos); // e9261fa9-f0c3-4603-b400-63a5f26952c7 CheckGetApplicantProfile(client, new ApplicantProfileKey() { Id = proto.Id }, proto); }
private void ApplicantEducation_CRU_Test() { var client = new ApplicantEducation.ApplicantEducationClient(_channel); // add ApplicantEducationProto proto = ProtoMapper.MapFromApplicantEducationPoco(_applicantEducation); ApplicantEducationList protos = new ApplicantEducationList(); protos.Items.Add(proto); client.AddApplicantEducation(protos); proto = CheckGetApplicantEducation(client, new ApplicantEducationKey() { Id = proto.Id }, proto); // check List protos = client.GetApplicantEducations(new Empty()); Assert.IsTrue(protos.Items.Count > 0); // check update proto.Major = Faker.Education.Major(); proto.CertificateDiploma = Faker.Education.Major(); proto.StartDate = ConvertDateTime2TimeStamp(Faker.Date.Past(3)); proto.CompletionDate = ConvertDateTime2TimeStamp(Faker.Date.Forward(1)); proto.CompletionPercent = (byte)Faker.Number.RandomNumber(1); protos = new ApplicantEducationList(); protos.Items.Add(proto); client.UpdateApplicantEducation(protos); // e9261fa9-f0c3-4603-b400-63a5f26952c7 CheckGetApplicantEducation(client, new ApplicantEducationKey() { Id = proto.Id }, proto); }
// Use this for initialization void Start() { ProtoMapper.Initilize(); ProtoPacketQueueManager.instance.AddHandleListener <ChatApp.UserResp>(OnChatResp); EncodeAndDecodeTest(); }