6
84
Fork
You've already forked dns
39

demo of splitting out header #313

Closed
TomOnTime wants to merge 6 commits from TomOnTime/dns:tlim/issue20splitheader into main
pull from: TomOnTime/dns:tlim/issue20splitheader
merge into: miekg:main
miekg:main
miekg:miek/26/jul13ma/06
miekg:miek/26/mrt24di/tls
miekg:miek/26/mrt09ma/17
miekg:miek/26/feb15zo/13
miekg:miek/2025-10-26@1431
miekg:miek/2025-10-18@2017
Contributor
Copy link

Just a test balloon.

  1. I'm using MX_ instead of "Mx" (temporarily) so I don't confuse the two different Mx's.
  2. This doesn't compile:
# codeberg.org/miekg/dns
./zclone.go:86:3: cannot use rr.Preference (variable of type uint16) as MX_ value in struct literal
./zclone.go:87:3: too many values in struct literal of type MX
Just a test balloon. 1. I'm using MX_ instead of "Mx" (temporarily) so I don't confuse the two different Mx's. 2. This doesn't compile: ``` # codeberg.org/miekg/dns ./zclone.go:86:3: cannot use rr.Preference (variable of type uint16) as MX_ value in struct literal ./zclone.go:87:3: too many values in struct literal of type MX ```
demo of splitting out header
Some checks failed
ci/woodpecker/pr/build Pipeline failed
82edb9f5b4
Owner
Copy link

Maybe we should opt for different naming if you already get refused, like call the field Data or some such?

Maybe we should opt for different naming if you already get refused, like call the field Data or some such?
@ -380,0 +386,4 @@
sprintData(sb,strconv.Itoa(int(rr.Preference)),sprintName(rr.Mx))
s:=sb.String()
builderPool.Put(*sb)
returns
Owner
Copy link

Wouldn't it be cleaner if MX.String calls MX_.String?

Wouldn't it be cleaner if MX.String calls MX_.String?
TomOnTime marked this conversation as resolved
Owner
Copy link

@miekg wrote in #313 (comment):

Maybe we should opt for different naming if you already get refused, like call the field Data or some such?

Oh yeah, then you can't embed...

@miekg wrote in https://codeberg.org/miekg/dns/pulls/313#issuecomment-7743788: > Maybe we should opt for different naming if you already get refused, like call the field Data or some such? Oh yeah, then you can't embed...
Owner
Copy link

@TomOnTime wrote in #313 (comment):

codeberg.org/miekg/dns

./zclone.go:86:3: cannot use rr.Preference (variable of type uint16) as MX_ value in struct literal
./zclone.go:87:3: too many values in struct literal of type MX

yes, you'll need to fix all generators as well
(note it helps e.g. to remove Cloner from the RR interface while fixing this, as you then sometimes can't run go generate, because the current version of zclone.go is broken/out of date)

@TomOnTime wrote in https://codeberg.org/miekg/dns/pulls/313#issue-2523980: > # codeberg.org/miekg/dns > ./zclone.go:86:3: cannot use rr.Preference (variable of type uint16) as MX_ value in struct literal > ./zclone.go:87:3: too many values in struct literal of type MX yes, you'll need to fix all generators as well (note it helps e.g. to remove Cloner from the RR interface while fixing this, as you then sometimes can't run go generate, because the current version of zclone.go is broken/out of date)
update clone_generate.go
Some checks are pending
ci/woodpecker/pr/build Pipeline is pending approval
1a8f09668c
all but msg_generate.go work
Some checks are pending
ci/woodpecker/pr/build Pipeline is pending approval
87dcf56e7e
fix generators
Some checks are pending
ci/woodpecker/pr/build Pipeline is pending approval
253494eb8e
Author
Contributor
Copy link

All the generators are now fixed. (at least go test ./... thinks so!)

Feedback?

All the generators are now fixed. (at least `go test ./...` thinks so!) Feedback?
Merge branch 'main' into tlim/issue20splitheader
All checks were successful
ci/woodpecker/pr/build Pipeline was successful
68f3a2bf8b
@ -386,1 +390,4 @@
}
func(rr*MX)String()string{
sb:=sprintHeader(rr)
s:=sb.String()+rr.MX_.String()
Owner
Copy link

Naming keeps being hard... You've opted for MX_ for the field? I (subjectively) believe Mx is better because it's shorten and typing _ is only need for a few records, where only A_ will be used a lot.

But generally I think this is the correct way forward.

Does cmd/atomdns compile with these changes? Think it should because that included in the CI build pipeline <- that would be good!

Naming keeps being hard... You've opted for MX_ for the field? I (subjectively) believe `Mx` is better because it's shorten and typing `_` is only need for a few records, where only `A_` will be used a lot. But generally I think this is the correct way forward. Does cmd/atomdns compile with these changes? Think it should because that included in the CI build pipeline <- that would be good!
Author
Contributor
Copy link

Naming keeps being hard... You've opted for MX_ for the field?

Naming is one of the 2 most difficult problems in computer science, of course.

It will complicate the code to have two different formats. I opted for "_" because it works in all cases. I'm also concerned about usability: won't it be confusing for users of the package to remember the exceptions?

Does cmd/atomdns compile with these changes?

It compiles. I haven't tested anything more.

> Naming keeps being hard... You've opted for MX_ for the field? Naming is one of the 2 most difficult problems in computer science, of course. It will complicate the code to have two different formats. I opted for "_" because it works in all cases. I'm also concerned about usability: won't it be confusing for users of the package to remember the exceptions? > Does cmd/atomdns compile with these changes? It compiles. I haven't tested anything more.
Update 'A' records to A + A_
Some checks are pending
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pull_request_closed/build Pipeline is pending approval
a6985b212e
Author
Contributor
Copy link

I converted "A" records and discovered that embedded structs don't work the same for struct literals, so I had to edit a lot of files:

https://go.dev/ref/spec#Struct_types

A field or method f of an embedded field in a struct x is called promoted if x.f is a legal selector that denotes that field or method f.

Promoted fields act like ordinary fields of a struct except that they cannot be used as field names in composite literals of the struct.

That's disappointing.

I converted "A" records and discovered that embedded structs don't work the same for struct literals, so I had to edit a lot of files: https://go.dev/ref/spec#Struct_types > A field or method f of an embedded field in a struct x is called promoted if x.f is a legal selector that denotes that field or method f. > > Promoted fields act like ordinary fields of a struct except that they cannot be used as field names in composite literals of the struct. That's disappointing.
Owner
Copy link

hrrmm, yep

- rr = &dns.A{Hdr: dns.Header{Name: dom, Class: dns.ClassINET}, A: a.To4()}
+ rr = &dns.A{Hdr: dns.Header{Name: dom, Class: dns.ClassINET}, A_: dns.A_{A: a.To4()}}

this is exactly the stottering we should not want, thought with embedding this would be OK, guess not.

Guess back to drawing board, and think about what do we actually need/want in this case and see what can be done.

Think with generics you ultimately run into the same thing, execpt A_ then is Fields (or whatever) in each case

hrrmm, yep ~~~ - rr = &dns.A{Hdr: dns.Header{Name: dom, Class: dns.ClassINET}, A: a.To4()} + rr = &dns.A{Hdr: dns.Header{Name: dom, Class: dns.ClassINET}, A_: dns.A_{A: a.To4()}} ~~~ this is exactly the stottering we should not want, thought with embedding this would be OK, guess not. Guess back to drawing board, and think about what do we _actually_ need/want in this case and see what can be done. Think with generics you ultimately run into the same thing, execpt `A_` then is `Fields` (or whatever) in each case
Author
Contributor
Copy link

Guess back to drawing board, and think about what do we actually need/want in this case and see what can be done.

Agreed.

To reset: What we're trying to achieve is (1) save memory by being able to allocate the struct without the header, (2) generate the .String() without a header.

> Guess back to drawing board, and think about what do we actually need/want in this case and see what can be done. Agreed. To reset: What we're trying to achieve is (1) save memory by being able to allocate the struct without the header, (2) generate the .String() without a header.
Owner
Copy link

@TomOnTime wrote in #313 (comment):

Guess back to drawing board, and think about what do we actually need/want in this case and see what can be done.

Agreed.

To reset: What we're trying to achieve is (1) save memory by being able to allocate the struct without the header, (2) generate the .String() without a header.

ack. Let's go back to the issue and close this.

@TomOnTime wrote in https://codeberg.org/miekg/dns/pulls/313#issuecomment-7869992: > > Guess back to drawing board, and think about what do we actually need/want in this case and see what can be done. > > Agreed. > > To reset: What we're trying to achieve is (1) save memory by being able to allocate the struct without the header, (2) generate the .String() without a header. ack. Let's go back to the issue and close this.
Owner
Copy link
mx1:=&_MX1{Hdr:Header{Name:"miek.nl.",Class:ClassINET},Flds:_Mx1{Preference:10,Mx:"mx.miek.nl"}}mx:=&MX{Hdr:Header{Name:"miek.nl.",Class:ClassINET},Preference:10,Mx:"mx.miek.nl"}

with generics you hit exactly the same issue (obvs)

```go mx1 := &_MX1{Hdr: Header{Name: "miek.nl.", Class: ClassINET}, Flds: _Mx1{Preference: 10, Mx: "mx.miek.nl"}} mx := &MX{Hdr: Header{Name: "miek.nl.", Class: ClassINET}, Preference: 10, Mx: "mx.miek.nl"} ``` with generics you hit exactly the same issue (obvs)
miekg closed this pull request 2025年10月24日 07:22:42 +02:00
Some checks are pending
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pull_request_closed/build Pipeline is pending approval

Pull request closed

Please reopen this pull request to perform a merge.
Sign in to join this conversation.
No reviewers
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
miekg/dns!313
Reference in a new issue
miekg/dns
No description provided.
Delete branch "TomOnTime/dns:tlim/issue20splitheader"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?