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

Fix TXT Records Key Strings #3

Merged
merged 3 commits into from
Feb 3, 2014
Merged

Fix TXT Records Key Strings #3

merged 3 commits into from
Feb 3, 2014

Conversation

markjlorenz
Copy link
Contributor

The way TXT records keys are converted back into golang strings causes them to have too-long lengths, and they no longer == the original golang strings.

Example:

examples/test.go has been modified like this:

func main() {
  println("-----------------------")
  print("real key length: ")
  println(len("path"))
  println("-----------------------")

    ctx, err := RegisterService()
    if err != nil{
        panic(err)
    }
    defer ctx.Release()
    Discover()
}


func Discover() {
    //...

    resolveReply, _ := <-rc
    fmt.Println(resolveReply)

    println("-----------------------")
    print("after dnssd key length: ")
    for key, _ := range resolveReply.TxtRecordMap {
      println(len(key))
      print("the string comparison works: ")
      println(key == "path")
    }
    println("-----------------------")

    //...
    }
}

The current code outputs:

markjlorenz@BabyGoat:go-dnssd(master *|2403m) → go run example/test.go
-----------------------
real key length: 4
-----------------------
Register Reply:  &{My Server _http._tcp. local.}
&{5 My Server _http._tcp. local.}
start resolve
&{5 My\032Server._http._tcp.local. BabyGoat.local. 3000 map[path:/path-to-page.html]}
-----------------------
after dnssd key length: 24
the string comparison works: false
-----------------------
&{5 My\032Server._http._tcp.local. 33 1 22 [0 0 0 0 184 11 8 66 97 98 121 71 111 97 116 5 108 111 99 97 108 0] 120}
&{0 0 47115 BabyGoat.local.}
&{5 BabyGoat.local. 10.0.1.5 120}
closed

With the code in the pull request:

markjlorenz@BabyGoat:go-dnssd(master *|2403m) → go run example/test.go
-----------------------
real key length: 4
-----------------------
Register Reply:  &{My Server _http._tcp. local.}
&{5 My Server _http._tcp. local.}
start resolve
&{5 My\032Server._http._tcp.local. BabyGoat.local. 3000 map[path:/path-to-page.html]}
-----------------------
after dnssd key length: 4
the string comparison works: true
-----------------------
&{5 My\032Server._http._tcp.local. 33 1 22 [0 0 0 0 184 11 8 66 97 98 121 71 111 97 116 5 108 111 99 97 108 0] 120}
&{0 0 47115 BabyGoat.local.}
&{5 BabyGoat.local. 10.0.1.5 120}
closed

There's also a small change to the example file. We should check for errors before dnssd.Process(ctx)

@soh335
Copy link
Owner

soh335 commented Feb 2, 2014

fmm... string(...) does not seem to truncate ZERO value. I think string(bytes.Truncate(key, string(0))) is more simple approach.

@markjlorenz
Copy link
Contributor Author

I agree, your implementation is better. The function is Trim, not Truncate.

Thanks for the critique!

soh335 added a commit that referenced this pull request Feb 3, 2014
@soh335 soh335 merged commit 3689ccb into soh335:master Feb 3, 2014
@soh335
Copy link
Owner

soh335 commented Feb 3, 2014

👍

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

Successfully merging this pull request may close these issues.

2 participants