Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Big struct is null when serialize #29

Closed
nvh2001 opened this issue Jul 8, 2024 · 29 comments
Closed

Big struct is null when serialize #29

nvh2001 opened this issue Jul 8, 2024 · 29 comments
Labels
enhancement New feature or request help wanted Extra attention is needed solved the question is solved

Comments

@nvh2001
Copy link

nvh2001 commented Jul 8, 2024

Test: Unity .NET Standartd 2.1 & .NET 8 Console

 var playerSessionModel = JsonConvert.DeserializeObject<PlayerSessionModel>("{\"statePlayer\":1,\"name\":\"vanhaodev\",\"id\":\"6683564e64fb47b6286e10a2\",\"point\":20,\"webUserInfo\":{\"phone\":\"null\",\"_id\":\"6683564e64fb47b6286e10a2\",\"name\":\"Baby Monster\",\"email\":\"vanhao.dev@gmail.com\",\"username\":\"vanhaodev\",\"telegram_id\":\"\",\"avatar\":{\"_id\":\"66272f0450c3064eceb18fa3\",\"name\":\"avt 4\",\"key\":\"games/66272f0450c3064eceb18fa3/avt-4.png\",\"full_url\":\"https://ntada.s3.ap-southeast-2.amazonaws.com/games/66272f0450c3064eceb18fa3/avt-4.png\",\"id\":\"66272f0450c3064eceb18fa3\"},\"banner\":\"null\",\"is_active\":true,\"invite_code\":\"r2n42raxgy\",\"balance\":20,\"titles\":\"newbie\",\"wallets\":[],\"is_online\":true,\"is_email_verified\":false,\"is_phone_verified\":false,\"is_telegram_verified\":false,\"is_wallet_connect\":false,\"tickets\":0,\"usdt_balance\":0,\"last_online_at\":\"2024-07-04T07:16:23.3Z\",\"about\":\"\",\"is_use_password\":true,\"id\":\"6683564e64fb47b6286e10a2\",\"telegram_ref\":\"https://google.com\"}}");

        Debug.Log(JsonConvert.SerializeObject(playerSessionModel)); //WORK
        Primitive p = new Primitive();
        p.Add.Struct(playerSessionModel);

        Primitive p2 = new Primitive(p.GetBytes());
        var model = p2.Get.Struct<PlayerSessionModel>();

        Debug.Log(JsonConvert.SerializeObject(model)); //NULL

The structs

    public struct PlayerSessionModel
    {
        public TypeStatePlayer statePlayer { get; set; }
        public string name { get; set; }
        public string id { get; set; }
        public long point { get; set; }
        public WebUserInfo webUserInfo { get; set; }
    }
    
public struct WebUserInfo
{
    [JsonProperty("phone")]
    public string phone { get; set; }
    [JsonProperty("_id")]
    public string _id { get; set; }
    [JsonProperty("name")]
    public string name { get; set; }
    [JsonProperty("email")]
    public string email { get; set; }
    [JsonProperty("username")]
    public string username { get; set; }
    [JsonProperty("telegram_id")]
    public string telegram_id { get; set; }
    [JsonProperty("avatar")]
    public Avatar avatar { get; set; }
    [JsonProperty("banner")]
    public object banner { get; set; }
    [JsonProperty("is_active")]
    public bool is_active { get; set; }
    [JsonProperty("invite_code")]
    public string invite_code { get; set; }
    [JsonProperty("balance")]
    public long balance { get; set; }
    [JsonProperty("titles")]
    public string titles { get; set; }
    [JsonProperty("wallets")]
    public object wallets { get; set; }
    [JsonProperty("is_online")]
    public bool is_online { get; set; }
    [JsonProperty("is_email_verified")]
    public bool is_email_verified { get; set; }
    [JsonProperty("is_phone_verified")]
    public bool is_phone_verified { get; set; }
    [JsonProperty("is_telegram_verified")]
    public bool is_telegram_verified { get; set; }
    [JsonProperty("is_wallet_connect")]
    public bool is_wallet_connect { get; set; }
    [JsonProperty("tickets")]
    public int tickets { get; set; }
    [JsonProperty("usdt_balance")]
    public int usdt_balance { get; set; }
    [JsonProperty("last_online_at")]
    public DateTime last_online_at { get; set; }
    [JsonProperty("about")]
    public string about { get; set; }
    [JsonProperty("is_use_password")]
    public bool is_use_password { get; set; }
    [JsonProperty("id")]
    public string id { get; set; }
    [JsonProperty("telegram_ref")]
    public string telegram_ref { get; set; }
}

public struct Avatar
{
    [JsonProperty("_id")]public string _id { get; set; }
    [JsonProperty("name")] public string name { get; set; }
    [JsonProperty("key")]public string key { get; set; }
    [JsonProperty("full_url")]public string full_url { get; set; }
    [JsonProperty("id")]public string id { get; set; }
}
    

SEND

{
  "statePlayer": 1,
  "name": "vanhaodev",
  "id": "6683564e64fb47b6286e10a2",
  "point": 20,
  "webUserInfo": {
    "phone": "null",
    "_id": "6683564e64fb47b6286e10a2",
    "name": "Baby Monster",
    "email": "vanhao.dev@gmail.com",
    "username": "vanhaodev",
    "telegram_id": "",
    "avatar": {
      "_id": "66272f0450c3064eceb18fa3",
      "name": "avt 4",
      "key": "games/66272f0450c3064eceb18fa3/avt-4.png",
      "full_url": "https://ntada.s3.ap-southeast-2.amazonaws.com/games/66272f0450c3064eceb18fa3/avt-4.png",
      "id": "66272f0450c3064eceb18fa3"
    },
    "banner": "null",
    "is_active": true,
    "invite_code": "r2n42raxgy",
    "balance": 20,
    "titles": "newbie",
    "wallets": "null",
    "is_online": true,
    "is_email_verified": false,
    "is_phone_verified": false,
    "is_telegram_verified": false,
    "is_wallet_connect": false,
    "tickets": 0,
    "usdt_balance": 0,
    "last_online_at": "2024-07-04T07:16:23.3Z",
    "about": "",
    "is_use_password": true,
    "id": "6683564e64fb47b6286e10a2",
    "telegram_ref": "https://google.com"
  }
}

RECEIVE

{
  "statePlayer": 0,
  "name": null,
  "id": null,
  "point": 0,
  "webUserInfo": {
    "phone": null,
    "_id": null,
    "name": null,
    "email": null,
    "username": null,
    "telegram_id": null,
    "avatar": {
      "_id": null,
      "name": null,
      "key": null,
      "full_url": null,
      "id": null
    },
    "banner": null,
    "is_active": false,
    "invite_code": null,
    "balance": 0,
    "titles": null,
    "wallets": null,
    "is_online": false,
    "is_email_verified": false,
    "is_phone_verified": false,
    "is_telegram_verified": false,
    "is_wallet_connect": false,
    "tickets": 0,
    "usdt_balance": 0,
    "last_online_at": "0001-01-01T00:00:00",
    "about": null,
    "is_use_password": false,
    "id": null,
    "telegram_ref": null
  }
}

My deadline is killing me haha

@alec1o
Copy link
Owner

alec1o commented Jul 8, 2024

Chill I'll respond you again at 1h or less.

@nvh2001
Copy link
Author

nvh2001 commented Jul 8, 2024

More issue:
If list of struct is length = 0 (not null), will error when deserialize

 Idol idol = new Idol();
 idol.name = "Karina";
 idol.birthdayYear = 2000;
 idol.group = new Group
 {
     name = "aespa",
     birthdayYear = 2019,
     songs = new List<Song>()
     {
         //new Song{name = "Supernova", birthdayYear = 2024},
         //new Song{name = "Armageddon", birthdayYear = 2024}
     }
 };

 Idol[] list = new Idol[1];
 list[0] = (idol);
 Primitive send = new Primitive();
 send.Add.Array<Idol>(list);

 Primitive recive = new Primitive(send.GetBytes());
 var reIdol = recive.Get.Array<Idol>();

 Debug.Log(reIdol[0].name);
 Debug.Log(reIdol[0].birthdayYear);
 Debug.Log(reIdol[0].group.name);
 Debug.Log(reIdol[0].group.birthdayYear);

 //foreach (var song in reIdol[0].group.songs)
 //{
 //    Debug.Log(song.name + " | " + song.birthdayYear);
 //}

@alec1o
Copy link
Owner

alec1o commented Jul 8, 2024

More issue: If list of struct is length = 0 (not null), will error when deserialize

true, Primitive don't allow write null information

@nvh2001
Copy link
Author

nvh2001 commented Jul 8, 2024

To avoid error On Byter, my funny way, huhu i crying

public async Task<PlayerSessionModel> OnGetUserInfo(string accessToken)
{
    PlayerSessionModel pModel = new PlayerSessionModel();
    var url = ServerURL.GetUrlByTypeGetRequest(TypeGetRequest.UserInfo);
    var result = await ServerAPI.GetAPI<WebUserInfo>(url, accessToken);
    if (result.Item2)
    {
        var webUserInfo = result.Item1;
        if (webUserInfo.id != null)
        {
            pModel = new PlayerSessionModel
            {
                statePlayer = TypeStatePlayer.Idle,
                id = webUserInfo.id,
                name = webUserInfo.username,
                point = webUserInfo.balance,
                webUserInfo = new WebUserInfo
                {
                    _id = webUserInfo._id ?? "null",
                    phone = webUserInfo.phone ?? "null",
                    name = webUserInfo.name ?? "null",
                    email = webUserInfo.email ?? "null",
                    username = webUserInfo.username ?? "null",
                    telegram_id = webUserInfo.telegram_id ?? "null",
                    avatar = new Avatar
                    {
                        _id = webUserInfo.avatar._id ?? "null",
                        name = webUserInfo.avatar.name ?? "null",
                        key = webUserInfo.avatar.key ?? "null",
                        full_url = webUserInfo.avatar.full_url ?? "null",
                        id = webUserInfo.avatar.id ?? "null",
                    },
                    banner = webUserInfo.banner ?? "null",
                    is_active = webUserInfo.is_active,
                    invite_code = webUserInfo.invite_code ?? "null",
                    balance = webUserInfo.balance,
                    titles = webUserInfo.titles ?? "null",
                    wallets = webUserInfo.wallets ?? "null",
                    is_online = webUserInfo.is_online,
                    is_email_verified = webUserInfo.is_email_verified,
                    is_phone_verified = webUserInfo.is_phone_verified,
                    is_telegram_verified = webUserInfo.is_telegram_verified,
                    is_wallet_connect = webUserInfo.is_wallet_connect,
                    tickets = webUserInfo.tickets,
                    usdt_balance = webUserInfo.usdt_balance,
                    last_online_at = webUserInfo.last_online_at,
                    about = webUserInfo.about ?? "null",
                    is_use_password = webUserInfo.is_use_password,
                    id = webUserInfo.id ?? "null",
                    telegram_ref = webUserInfo.telegram_ref ?? "null"
                }
            };
        }
    }
    return pModel;
}

@alec1o
Copy link
Owner

alec1o commented Jul 8, 2024

To avoid error On Byter, my funny way, huhu i crying

Do you fixed?

@nvh2001
Copy link
Author

nvh2001 commented Jul 8, 2024

More issue: If list of struct is length = 0 (not null), will error when deserialize

true, Primitive don't allow write null information

To avoid error On Byter, my funny way, huhu i crying

Do you fixed?

no, it's just set for default custom for null but still error

@alec1o
Copy link
Owner

alec1o commented Jul 8, 2024

Ok, Tell me what result do you expect

@alec1o
Copy link
Owner

alec1o commented Jul 8, 2024

what is TypeStatePlayer object, can send me?

@nvh2001
Copy link
Author

nvh2001 commented Jul 8, 2024

Ok, Tell me what result do you expect

Can byter send null value?

@nvh2001
Copy link
Author

nvh2001 commented Jul 8, 2024

what is TypeStatePlayer object, can send me?

It's Enum

public enum TypeStatePlayer
{
    None,
    Idle,
    Ready,
    Play,
}

@alec1o
Copy link
Owner

alec1o commented Jul 8, 2024

#28 (comment)
WebUserInfo->wallet, WebUserInfo->banner, is a object! I told you before Primitive not support object will make error 🤣

@alec1o
Copy link
Owner

alec1o commented Jul 8, 2024

Can byter send null value?

Do you mean I implement a way to serialize and deserialize null objects??? 🤯😨

@nvh2001
Copy link
Author

nvh2001 commented Jul 8, 2024

Can byter send null value?

Do you mean I implement a way to serialize and deserialize null objects??? 🤯😨

yep, because my struct request from api web so it have somany null field, and sometime i create struct and just use only a few internal variables to achieve the goal

@alec1o
Copy link
Owner

alec1o commented Jul 8, 2024

yep, because my struct request from api web so it have somany null field, and sometime i create struct and just use only a few internal variables to achieve the goal

😭 😭 😭 😭 😭 😭 😭 😭 😭 😭 😭 😭 😭

@nvh2001
Copy link
Author

nvh2001 commented Jul 8, 2024

yep, because my struct request from api web so it have somany null field, and sometime i create struct and just use only a few internal variables to achieve the goal

😭 😭 😭 😭 😭 😭 😭 😭 😭 😭 😭 😭 😭

If it's difficult then skip it, but lists and arrays should be able to fix it

@alec1o
Copy link
Owner

alec1o commented Jul 8, 2024

I'll implement it, To allow any null data. But have a big problem about the way.

How Skip null value in Primitive.Add?

  1. Use null suffix/prefix, (Bug when object value contain same value then prefix/suffix). ❓ (Conflict)
  2. Update overhead of Primitive from 1 byte to bytes. ❓ (Force incress data)

Have a idea smart boys? (Nguyen Van Hao: @nvh2001 @vanhaodev), (Alecio Furanze: @alec1o)

@alec1o
Copy link
Owner

alec1o commented Jul 8, 2024

I'll implement it, To allow any null data. But have a big problem about the way.

How Skip null value in Primitive.Add?

  1. Use null suffix/prefix, (Bug when object value contain same value then prefix/suffix). ❓ (Conflict)
  2. Update overhead of Primitive from 1 byte to bytes. ❓ (Force incress data)

Have a idea smart boys? (Nguyen Van Hao: @nvh2001 @vanhaodev), (Alecio Furanze: @alec1o)

Do you have a ideia about?

alec1o added a commit that referenced this issue Jul 8, 2024
add primitive skipping null/empty test #29 #30
alec1o added a commit that referenced this issue Jul 8, 2024
improve Primitive.Null environment #29 #30
alec1o added a commit that referenced this issue Jul 8, 2024
primitive write and read null and empty string #29 #30
alec1o added a commit that referenced this issue Jul 8, 2024
primitive write and read null and empty class #29 #30
alec1o added a commit that referenced this issue Jul 8, 2024
primitive write and read null and empty struct #29 #30
@alec1o
Copy link
Owner

alec1o commented Jul 8, 2024

Bro can you test if null object is skipped by primitive. (Use current updated sources) from main branch

@alec1o
Copy link
Owner

alec1o commented Jul 9, 2024

It's working?

@nvh2001
Copy link
Author

nvh2001 commented Jul 10, 2024

It's working?

sorry i have some problem in my life, in today, i'll check this

@alec1o
Copy link
Owner

alec1o commented Jul 10, 2024

I'm waiting for you feedback

@alec1o
Copy link
Owner

alec1o commented Jul 13, 2024

Hi @nvh2001 @vanhaodev

@alec1o
Copy link
Owner

alec1o commented Jul 19, 2024

Can you give me a review? ☹️😭

@alec1o
Copy link
Owner

alec1o commented Jul 22, 2024

😭 bro!!! Talk something, are you okay? @nvh2001 @vanhaodev

@alec1o
Copy link
Owner

alec1o commented Jul 29, 2024

☕ Hello! @nvh2001 @vanhaodev

@vanhaodev
Copy link

☕ Hello! @nvh2001 @vanhaodev

sorry, I have some issue in my life. Now im here to continue my project.

@alec1o
Copy link
Owner

alec1o commented Oct 7, 2024

Good! I was worried about you a lot. Welcome.

@alec1o
Copy link
Owner

alec1o commented Oct 19, 2024

Hey @nvh2001 @vanhaodev Did you test it? I'm waiting for you feedback update it to v4

@alec1o
Copy link
Owner

alec1o commented Dec 11, 2024

I'm marking as Solved.

@alec1o alec1o closed this as completed Dec 11, 2024
@alec1o alec1o added enhancement New feature or request help wanted Extra attention is needed solved the question is solved labels Dec 11, 2024
@alec1o alec1o pinned this issue Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed solved the question is solved
Projects
None yet
Development

No branches or pull requests

3 participants