Eigenstate: myrddin-dev mailing list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question: has anyone worked on code for sockets?


On Sun, 30 Jul 2017 20:05:06 -0500, Ryan Gonzalez <rymg19@xxxxxxxxx> wrote:

> I'm actually using Unix sockets, so dial is literally PERFECT.
> 
> As a side note: what's the most idiomatic way of converting a pointer
> to a byte slice? I'm trying to transfer a union over a Unix socket,
> and right now I'm doing:
> 
> 
> type X = union
>     `Y
> ;;
> 
> /* ... */
> var x = `Y
> var bytes = (&x[:]) : (byte[:])
> 
> but it's not working:
> 
> src/common.myr:40: type union
> `Shutdown
> ;; does not support member operators near <message#>.len

You're close, only a few of small mistakes:

	1) operator precedence: postfix binds tighter than prefix. 
	2) you need to give a size when slicing a pointer, since
	   there's no implicit sizing there.
	3) if you want raw bytes, you'll need to cast the pointer
	   before slicing:

So:

	var bytes = ((&x : byte#)[:sizeof(thing)])

It's a tad ugly, unfortunately. I wouldn't object to tossing a generic
function into libstd, since it seems to have come up a few times. Maybe
something like:

     std.rawstorage : (valp : @a# -> byte[:])


-- 
    Ori Bernstein

References:
Question: has anyone worked on code for sockets?"rymg19@xxxxxxxxx" <rymg19@xxxxxxxxx>
Re: Question: has anyone worked on code for sockets?Ori Bernstein <ori@xxxxxxxxxxxxxx>
Re: Question: has anyone worked on code for sockets?Ryan Gonzalez <rymg19@xxxxxxxxx>
Re: Question: has anyone worked on code for sockets?Ori Bernstein <ori@xxxxxxxxxxxxxx>
Re: Question: has anyone worked on code for sockets?Ryan Gonzalez <rymg19@xxxxxxxxx>