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

对于 optional 字段,可以有一个缺省值,缺省值在编码时默认不打包 #486

Closed
lbbniu opened this issue Jun 24, 2023 · 0 comments · Fixed by #483
Closed
Labels
bug Something isn't working

Comments

@lbbniu
Copy link
Collaborator

lbbniu commented Jun 24, 2023

协议

代码位置

    struct ServerInfo
    {
        0 require string application;
        1 require string serverName;
        2 require int pid;
        3 optional string adapter;
    };

Adapter 字段为做判断,直接编码

代码位置

// WriteTo encode struct to buffer
func (st *ServerInfo) WriteTo(buf *codec.Buffer) (err error) {

	err = buf.WriteString(st.Application, 0)
	if err != nil {
		return err
	}

	err = buf.WriteString(st.ServerName, 1)
	if err != nil {
		return err
	}

	err = buf.WriteInt32(st.Pid, 2)
	if err != nil {
		return err
	}

	err = buf.WriteString(st.Adapter, 3)
	if err != nil {
		return err
	}

	return err
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant