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

simplify repeated types with generics #18

Open
egonelbre opened this issue Sep 13, 2023 · 0 comments
Open

simplify repeated types with generics #18

egonelbre opened this issue Sep 13, 2023 · 0 comments

Comments

@egonelbre
Copy link
Member

egonelbre commented Sep 13, 2023

Currently we create quite a lot of boilerplate that looks like:

	c.Message(1, func(c *picobuf.Decoder) {
		if m.Value == nil {
			m.Value = new(Message)
		}
		m.Value.Decode(c)
	})
	c.Message(2, func(c *picobuf.Decoder) {
		if m.Opt == nil {
			m.Opt = new(Message)
		}
		m.Opt.Decode(c)
	})
	c.RepeatedMessage(3, func(c *picobuf.Decoder) {
		x := new(Message)
		c.Loop(x.Decode)
		m.Rep = append(m.Rep, x)
	})
	c.PresentMessage(4, m.PresentBasic.Decode)
	c.PresentMessage(5, m.PresentOpt.Decode)
	c.RepeatedMessage(6, func(c *picobuf.Decoder) {
		m.PresentRep = append(m.PresentRep, Message{})
		c.Loop(m.PresentRep[len(m.PresentRep)-1].Decode)
	})

We should be able to convert these to something along the lines of:

	picowire.DecodeMessage[Message](c, 1, &m.Value)
	picowire.DecodeMessage[Message](c, 2, &m.Opt)
	picowire.DecodeRepeatedMessage[Message](c, 3, &m.Rep)
	c.PresentMessage(4, m.PresentBasic.Decode)
	c.PresentMessage(5, m.PresentOpt.Decode)
	picowire.DecodeRepeatedPresentMessage[Message](c, 6, &m.PresentRep)
@egonelbre egonelbre changed the title generics: simplify repeated types simplify repeated types with generics Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant