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

gen: incorrect bool decoder generation for some objects #101

Closed
tdakkota opened this issue Jan 1, 2021 · 1 comment · Fixed by #102
Closed

gen: incorrect bool decoder generation for some objects #101

tdakkota opened this issue Jan 1, 2021 · 1 comment · Fixed by #102
Labels
area: gen Codegen issues

Comments

@tdakkota
Copy link
Member

tdakkota commented Jan 1, 2021

For example: https://core.telegram.org/constructor/peerNotifySettings.

Should be:

  func (p *PeerNotifySettings) Decode(b *bin.Buffer) error {
	  if p == nil {
		  return fmt.Errorf("can't decode peerNotifySettings#af509d20 to nil")
	  }
	  if err := b.ConsumeID(PeerNotifySettingsTypeID); err != nil {
		  return fmt.Errorf("unable to decode peerNotifySettings#af509d20: %w", err)
	  }
	  {
		  if err := p.Flags.Decode(b); err != nil {
			  return fmt.Errorf("unable to decode peerNotifySettings#af509d20: field flags: %w", err)
		  }
	  }
	  if p.Flags.Has(0) {
		  value, err := b.Bool()
		  if err != nil {
			  return fmt.Errorf("unable to decode peerNotifySettings#af509d20: field show_previews: %w", err)
		  }
		  r.ShowPreviews = value
	  }
	  if p.Flags.Has(1) {
		  value, err := b.Bool()
		  if err != nil {
			  return fmt.Errorf("unable to decode peerNotifySettings#af509d20: field silent: %w", err)
		  }
		  r.Silent = value
	  }
	  if p.Flags.Has(2) {
		  value, err := b.Int()
		  if err != nil {
			  return fmt.Errorf("unable to decode peerNotifySettings#af509d20: field mute_until: %w", err)
		  }
		  p.MuteUntil = value
	  }
	  if p.Flags.Has(3) {
		  value, err := b.String()
		  if err != nil {
			  return fmt.Errorf("unable to decode peerNotifySettings#af509d20: field sound: %w", err)
		  }
		  p.Sound = value
	  }
	  return nil
  }

Now:

func (p *PeerNotifySettings) Decode(b *bin.Buffer) error {
if p == nil {
return fmt.Errorf("can't decode peerNotifySettings#af509d20 to nil")
}
if err := b.ConsumeID(PeerNotifySettingsTypeID); err != nil {
return fmt.Errorf("unable to decode peerNotifySettings#af509d20: %w", err)
}
{
if err := p.Flags.Decode(b); err != nil {
return fmt.Errorf("unable to decode peerNotifySettings#af509d20: field flags: %w", err)
}
}
p.ShowPreviews = p.Flags.Has(0)
p.Silent = p.Flags.Has(1)
if p.Flags.Has(2) {
value, err := b.Int()
if err != nil {
return fmt.Errorf("unable to decode peerNotifySettings#af509d20: field mute_until: %w", err)
}
p.MuteUntil = value
}
if p.Flags.Has(3) {
value, err := b.String()
if err != nil {
return fmt.Errorf("unable to decode peerNotifySettings#af509d20: field sound: %w", err)
}
p.Sound = value
}
return nil
}

@shadowspore
Copy link
Member

Seems like we interpret all Bool values as True (the difference between them is that True encoded in bitflag where Bool is not)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: gen Codegen issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants