-
-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #113 from tdakkota/feature/gen/encode-zero-value
gen: automatic encoding of optional fields
- Loading branch information
Showing
763 changed files
with
24,706 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{{ define "zero_derive" }}{{ $s := . }} | ||
{{- /*gotype: github.com/gotd/td/internal/gen.structDef*/ -}} | ||
func ({{ $s.Receiver }} *{{ $s.Name }}) Zero() bool { | ||
if {{ $s.Receiver }} == nil { | ||
return true | ||
} | ||
{{- /*gotype: github.com/gotd/td/internal/gen.fieldDef*/ -}} | ||
{{- range $f := $s.Fields }}{{- if ne ($f.Name) ($f.ConditionalField) }} | ||
if !({{ $s.Receiver }}.{{template "compare_zero" $f}}) { | ||
return false | ||
} | ||
{{- end }}{{- end }} | ||
|
||
return true | ||
} | ||
{{- end -}} | ||
|
||
{{ define "compare_zero" }} | ||
{{- /*gotype: github.com/gotd/td/internal/gen.fieldDef*/ -}} | ||
{{- .Name -}} | ||
{{- if or (.Slice) (.DoubleSlice) -}} == nil | ||
{{- else if eq (.Type) ("bin.Int128") -}} == bin.Int128{} | ||
{{- else if eq (.Type) ("bin.Int256") -}} == bin.Int256{} | ||
{{- else if or (hasPrefix (.Type) ("int")) (hasPrefix (.Type) ("float")) }} == 0 | ||
{{- else if eq (.Type) ("string") -}} == "" | ||
{{- else if eq (.Type) ("bool") -}} == false | ||
{{- else if eq (.Type) ("bin.Object") }} == nil | ||
{{- else if hasSuffix (.Type) ("Class") }} == nil | ||
{{- else -}}.Zero() | ||
{{- end -}}{{- end }} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.