It is simply awesome! Thanks!
понедельник, 27 июля 2015 г., 22:54:22 UTC+3 пользователь Matthew Flatt написал:
> At Sun, 26 Jul 2015 22:42:48 -0700 (PDT), Слава ПолноеИмя wrote:
> > Sorry, list, for dumb unprofessional question, but I'm not even amateur
> > programmer)
> > How can I convert string and floats to bytes, that can be passed to
> > udp-send?
> > Tried real->floating-point-bytes and string->bytes/utf-8 but it produces
> > not
> > compatible output.
>
> The `real->floating-point-bytes` bytes conversion gives you a machine
> representation of number. To convert bytes back to a number, you'd use
> `floating-point-bytes->real`.
>
> Alternatively, you could use `number->string` to get a human-readable
> encoding of a number, and then using `string->bytes/utf-8` to encode
> the string into bytes. The reverse would be `bytes->string/utf-8` and
> then `string->number`.
>
>
> > Any best practices of forming udp datagrams in racket exists?
>
> A more general strategy would be to use `write` to convert anything to
> bytes, then then use `read` to convert back from a byte string to the
> value. The `read` and `write` functions work on ports, and some ports
> can write to or read from a byte string. This approach works for
> numbers, strings, symbols, lists, and other things that can round-trip
> with `read` and `write`.
>
> (define (value->bytes v)
> (define o (open-output-bytes))
> (write v o)
> (get-output-bytes o))
>
> (define (bytes->value bstr)
> (define i (open-input-bytes bstr))
> (read i))
--
You received this message because you are subscribed to the Google Groups
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.