ChanServ changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Fund Crystal's development: https://crystal-lang.org/sponsors | GH: https://github.com/crystal-lang/crystal | Docs: https://crystal-lang.org/docs | Gitter: https://gitter.im/crystal-lang/crystal
ur5us has quit [Ping timeout: 250 seconds]
hightower3 has joined #crystal-lang
hightower2 has quit [Ping timeout: 250 seconds]
ur5us has joined #crystal-lang
<mikko> how would you implement a resettable timer (something like setTimeout in javascript) in crystal? i've been using spawn and sleep but i'm not sure if there's any nice way to get rid of timers like that
<mikko> hmm, maybe Fiber.timeout is what i'm looking for.. the docs are not exactly clear though so i'm not sure
<FromGitter> <Blacksmoke16> thats for the `select` keyword
<FromGitter> <Blacksmoke16> which allows waiting on multiple channels
<mikko> seems like that would work, i could use the channel to signal that i don't want the timeout action to happen
avane_ has joined #crystal-lang
avane has quit [Ping timeout: 245 seconds]
ur5us has quit [Quit: Leaving]
ur5us has joined #crystal-lang
ur5us has quit [Ping timeout: 250 seconds]
elf_fortres has joined #crystal-lang
elf_fortres has quit [Ping timeout: 246 seconds]
ur5us has joined #crystal-lang
ur5us has quit [Ping timeout: 250 seconds]
elf_fortrez has joined #crystal-lang
elf_fortrez has quit [Ping timeout: 246 seconds]
elf_fortrez has joined #crystal-lang
elf_fortrez has quit [Quit: Client closed]
<FromGitter> <RespiteSage> I'm doing the admittedly dubious process of taking an image from `crsfml` and trying to output it as a gif. Unfortunately, `stumpy_gif` seems insufficient for that task.
<FromGitter> <RespiteSage> Does anyone know if it's even still maintained or if there's an alternative?
<FromGitter> <RespiteSage> *an animated gif
<SamantazFox_> That should work, right?
<FromGitter> <Blacksmoke16> idt `[0]` is valid
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/bth3
<FromGitter> <Blacksmoke16> looks like the key is `"foo[]"`
<FromGitter> <Blacksmoke16> doesnt look like there are any tests for array contexts, so not sure if thats expected or not...
<FromGitter> <Blacksmoke16> oh can just do `foo=bar&foo=baz`
<FromGitter> <Blacksmoke16> dont need the `[]`
<SamantazFox_> I don't control that
<SamantazFox_> it's provided by the browser when it sends the HTTP form
<FromGitter> <Blacksmoke16> and its coming thru as `[0]` and `[1]`?
<SamantazFox_> `%5B0%5D` and `%5B1%5D`, to be exact
<FromGitter> <Blacksmoke16> you'd need to decode it first
<FromGitter> <Blacksmoke16> `URI.decode_www_form test2`
<FromGitter> <Blacksmoke16> but it'll see them as diff keys: URI::Params(@raw_params={"foo[0]" => ["bar"], "foo[1]" => ["baz"]})
<FromGitter> <Blacksmoke16> idt there's a standard for array params like that, so maybe could be a feature request to better handle some common forms of it
<FromGitter> <Blacksmoke16> PHP seems to handle both `foo[0]` and `foo[]`, but not just multiple `foo`
<SamantazFox_> I'm trying to find the RFC for that
<SamantazFox_> maybe it's not standardized per se, but became standardized de-facto
<FromGitter> <Blacksmoke16> https://stackoverflow.com/a/28590927
<FromGitter> <Blacksmoke16> i've always seem `[]`, but not `[idx]`
<SamantazFox_> Looks like it's not standardized, yeah
<SamantazFox_> though, could be a nice addition, at it is frequently used
<FromGitter> <Blacksmoke16> id open an issue for it
<SamantazFox_> mmh, sure :)
<SamantazFox_> I'll do that later
<hightower3> Hey let's say I want to read some data from IO and turn it into structs. The first struct is a header which is always the same. After the header follows body, but it is not unstructured - it has a structure and length which are specified in the header.
<FromGitter> <Blacksmoke16> what format is the data in? Just bytes or?
<hightower3> yes, just bytes although maybe not relevant for the question... And my question is:
<hightower3> What's a good way to represent this body struct, which obviously varies. How do I make a function which reads from IO to return both (header and body struct), where that body is something meaningful, and not something which I can't use without always checking for type?
<hightower3> Actually maybe I have an answer...
<FromGitter> <Blacksmoke16> https://github.com/j8r/crystalizer supports a byte format
<hightower3> This data needs to be processed. So if I define a process() function which has overloads for every type, I could get this going automatically
<hightower3> Yes yes, I use crystalizer just for convenience... I am asking about the high-level design of the types, the low-level stuff of reading the data is not a problem.
<hightower3> Does the approach with a process() and overloads sound OK? or there's a more common way or something?
<FromGitter> <Blacksmoke16> this isnt like protobuf or something is it?
<FromGitter> <Blacksmoke16> but when you say the header has the length and structure, do you mean the header contains something that could tell you want object the data maps to?
<hightower3> yes, the header has a 'type' and 'length'. Based on 'type', I then know which struct I need to read the rest of the body into
<FromGitter> <Blacksmoke16> and type is `type`?
<FromGitter> <Blacksmoke16> what type is `type`?*
<hightower3> UInt32
<FromGitter> <Blacksmoke16> prob would have to use a `case` then
<FromGitter> <Blacksmoke16> could maybe do something with annotations to build out the case automatically
<hightower3> Yes, I mean, my concern is, after I read the body into appropriate struct, how would I ensure that further code can do something useful with it without always checking for which type that body is... But well, I probably do need to check, since that's the whole purpose (that different processing happens based on type of body :)
<FromGitter> <Blacksmoke16> my understanding was you'd have a `.from_io` on your type
<FromGitter> <Blacksmoke16> so you deserialize the bytes, using crystalizer for example, like you would if was json
<hightower3> Right, OK, will probably use 'case' for <appropriate struct>.from_io() (this just calls Crystalize::ByteFormat.deserialize(io, to: ...)) , and then a single function called process() which has overloads for all possible types
<FromGitter> <Blacksmoke16> yea seems fine
<hightower3> ++, great, thanks for help/discussion
elf_fortrez has joined #crystal-lang
ur5us has joined #crystal-lang
elf_fortrez has quit [Quit: Client closed]
<hightower3> If I am reading a string from IO (terminated by \0), what's the best way to define max length?
hightower3 has quit [Ping timeout: 240 seconds]
<FromGitter> <Blacksmoke16> you mean like read x bytes from the IO?