public override Task <GetUsersResponse> GetUsers(EmptyMessagee request, ServerCallContext context) { var regiterUsers = _userRepository.GetUsers(); var getUsersResponse = new GetUsersResponse(); foreach (User user in regiterUsers) { ICollection <ImageProto> images = new List <ImageProto>(); IEnumerable <CommentProto> comments = new List <CommentProto>().ToArray(); foreach (Image image in user.Images) { comments = image.Comments.Select(c => new CommentProto { Text = c.Text, UserEmail = c.UserEmail, }); var imageToSave = new ImageProto { Name = image.Name }; imageToSave.Comments.AddRange(comments); images.Add(imageToSave); } ; var userToSave = new UserProto { UserEmail = user.Email, Password = user.Password, }; userToSave.Images.AddRange(images); getUsersResponse.Users.Add(userToSave); } _logSenderService.SendMessages("registered users are requested"); return(Task.FromResult(getUsersResponse)); }
public void Start() { UserProto proto = new UserProto(); proto.id = 1; proto.name = "2173"; //string name = "你好"; //proto.name = System.Text.Encoding.UTF8.GetString(System.Text.Encoding.UTF8.GetBytes(name)); //============================================================================序列化 string message = GameSocketInterface.Serialize(proto, "ExampleMessage", UserProto.GetProtoName()); //============================================================================反序列化 UserProto proto1 = new UserProto(); proto1 = GameSocketInterface.deserialize(proto1, message, "ExampleMessage", UserProto.GetProtoName()); Debug.LogError(proto1.name); }