On Wed, Oct 11, 2017, 9:51 AM Christian LeMoussel <cnh...@gmail.com> wrote:
> > connections.send(s, "getwork", 10) > > I searched a little bit more and here is in Python send() function > > def send(sdef, data, slen): > sdef.setblocking(0) > > sdef.sendall(str(len(str(json.dumps(data)))).encode("utf-8" > ).zfill(slen)) > sdef.sendall(str(json.dumps(data)).encode("utf-8")) > > Unfortunately, I don't know Python. the challenge is to rewrite the send > function > in Go. > This code is converting the data to json twice. The first time it converts it to get the length of the json string, and pad it out to the expected length (10). The second send converts it again and just sends the encoded json string. Your Go version would just want to encode your data as json, send and first send the length of it: // Some Data data := Data{"Foo"} enc, err := json.Marshal(data) if err != nil { panic(err) } size := fmt.Sprintf("%010d", len(data) ) // send size // send enc > > > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.