N
N
Nube2017-02-12 07:41:14
Java
Nube, 2017-02-12 07:41:14

How to calculate the packet size?

I want to send a POJO to the server, for this I create a Message class

public abstract class Message {
    
    // размер пакета 
    public final int length;
    // тип сообщения
    public final int typeMessage;

    protected Message(int length, int typeMessage) {
        this.length = length;
        this.typeMessage = typeMessage;
    }

    public abstract byte[] getBytes();
}

this is an example of its implementation
public class Account extends Message {
    
    private char[] email;
    private char[] password;

    public Account(int length, int typeMessage, char[] email, char[] password) {
        super(length, typeMessage);
        this.email = email;
        this.password = password;
    }

    public char[] getEmail() {
        return email;
    }

    public void setEmail(char[] email) {
        this.email = email;
    }

    public char[] getPassword() {
        return password;
    }

    public void setPassword(char[] password) {
        this.password = password;
    }

    @Override
    public byte[] getBytes() {
        return null;
    }
}

Now questions: 1) how to find out the length of the packet? (I think you need to add the email and password arrays to each other)
2) Is the idea of ​​creating a package correct at all?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question