Post ALWCVOUpKmTqhODSgi by helene@p.helene.moe
 (DIR) More posts by helene@p.helene.moe
 (DIR) Post #ALWCVOUpKmTqhODSgi by helene@p.helene.moe
       2022-07-15T14:27:46.495136Z
       
       0 likes, 0 repeats
       
       surely, there’s a better way to do this, right..? and i can’t even use it in further pattern matching… (maybe i shouldn’t do that?)  def deserialize_binary(<<254, size::little-unsigned-24, data::binary-size(size)>>)    when rem(size, 4) == 0, do: data  def deserialize_binary(<<254, size::little-unsigned-24, data::binary-size(size), _pad::binary-size(1)>>)    when rem(size, 4) == 1, do: data  def deserialize_binary(<<254, size::little-unsigned-24, data::binary-size(size), _pad::binary-size(2)>>)    when rem(size, 4) == 2, do: data  def deserialize_binary(<<254, size::little-unsigned-24, data::binary-size(size), _pad::binary-size(3)>>)    when rem(size, 4) == 3, do: data  def deserialize_binary(<<size::little-unsigned-8, data::binary-size(size)>>)    when rem(size, 4) == 3, do: data  def deserialize_binary(<<size::little-unsigned-8, data::binary-size(size), _pad::binary-size(1)>>)    when rem(size, 4) == 2, do: data  def deserialize_binary(<<size::little-unsigned-8, data::binary-size(size), _pad::binary-size(2)>>)    when rem(size, 4) == 1, do: data  def deserialize_binary(<<size::little-unsigned-8, data::binary-size(size), _pad::binary-size(3)>>)    when rem(size, 4) == 0, do: data
       
 (DIR) Post #ALWCgL4kOO4LH8Eio4 by lanodan@queer.hacktivis.me
       2022-07-15T14:29:42.937928Z
       
       1 likes, 0 repeats
       
       @helene This is almost unreadable, what are you trying to do?
       
 (DIR) Post #ALWD0Hr24v6P4oKjfU by helene@p.helene.moe
       2022-07-15T14:33:21.380702Z
       
       0 likes, 0 repeats
       
       @lanodan it definitely is gorei’m parsing binary packets in bitstrings, and there is a string type for one of fields, which has either a “compact” length encoding or an “extended” one ; and that field must be 4-byte alignedsome of the other fields are simple numbers and pattern matching works fine for those simpler packetsi’m assuming using pattern matching for that is not a good idea
       
 (DIR) Post #ALWD7tfJtcBgNAU2wS by helene@p.helene.moe
       2022-07-15T14:34:44.880059Z
       
       0 likes, 0 repeats
       
       @emilis it's elixirit's bad codeit's for parsing weird encoding
       
 (DIR) Post #ALWDPJuZZE6ahDvTeq by lanodan@queer.hacktivis.me
       2022-07-15T14:37:51.378884Z
       
       1 likes, 0 repeats
       
       @helene Pattern-matching might be right but maybe don't shove everything in it at once?You seem to have two possible cases, match against this first?Otherwise at least put a comment block which explains the functions beforehand, it's a bit more readable now that I know what you're trying to do.
       
 (DIR) Post #ALWDUUyZrB2cSbGhxw by lain@lain.com
       2022-07-15T14:38:44.942482Z
       
       2 likes, 0 repeats
       
       @helene looks like it makes more sense to just have one match for it (withouth the padding) and then just cut off whatever is not aligned from `data`.
       
 (DIR) Post #ALWE67v21zQtxCYJqC by helene@p.helene.moe
       2022-07-15T14:45:36.681040Z
       
       0 likes, 0 repeats
       
       @lanodan that would probably be better indeed, thank you, i’ll try that!won’t solve my issue of trying to add that type into pattern-matching like this:def deserialize(<<0x1234::little-unsigned-32, ping_id::little-unsigned-64>>) do  {:ok, :ping, %{ping_id: ping_id}}endbut maybe i shouldn’t use pattern matching here :akko_think2:
       
 (DIR) Post #ALWEJXHn1oP2OQajBY by lanodan@queer.hacktivis.me
       2022-07-15T14:47:16.559893Z
       
       1 likes, 0 repeats
       
       @helene What's wrong with this one?Other than being Java-verbose?
       
 (DIR) Post #ALWEeRAUy6dBV79Ckb by helene@p.helene.moe
       2022-07-15T14:51:49.423891Z
       
       0 likes, 0 repeats
       
       @lanodan nothing wrong for this one (tell me if i shouldn’t do that, still trying to learn Elixir properly!)but if I want to use that binary type from my OP (with its different length encodings and paddings), I don’t think it’d be possible directly from the pattern matching (e.g. imagine that ping_id would be that type, but that there are 3 more of them)
       
 (DIR) Post #ALWFY8GwPWUr71ibgm by helene@p.helene.moe
       2022-07-15T15:01:53.049529Z
       
       0 likes, 0 repeats
       
       @lain hm, i’d want to do that, but it seems like i cannot do something likedef binary(size, <<data::binary-size(size)>>), do: datashould i do that without pattern matching at all?
       
 (DIR) Post #ALWFthBrmTrLUScvtw by pleb@shitposter.club
       2022-07-15T15:05:17.808547Z
       
       1 likes, 0 repeats
       
       @helene @lain yeah pattern matching like that still isn't quite supported, you can do it in expression, but not function callshttps://github.com/elixir-lang/elixir/issues/10890which is why even if this code would look a bit nicer, it wasn't posted half an hour agodef deserialize_binary(<<254, size::little-unsigned-24, data::binary-size(size - rem(size, 4))>>) do  dataenddef deserialize_binary(<<size::little-unsigned-8, data::binary-size(size - rem(size/4))>>) do  dataend
       
 (DIR) Post #ALWFvJIjZUlryibpUO by helene@p.helene.moe
       2022-07-15T15:06:05.286659Z
       
       0 likes, 0 repeats
       
       @pleb @lain yep, that's what i originally wanted to write, but couldn't :blobcatpensive:
       
 (DIR) Post #ALWTZHuVSbrEeVfbFY by locusfokee@mastodon.online
       2022-07-15T17:35:58Z
       
       0 likes, 0 repeats
       
       @helene @lanodan Frankly, a terrible and advanced introduction to elixir. It seems similar to ruby. isn't?
       
 (DIR) Post #ALWTZIiqRS7jAdDniC by lanodan@queer.hacktivis.me
       2022-07-15T17:38:55.676368Z
       
       1 likes, 0 repeats
       
       @locusfokee @helene Not really, I wish internet would go beyond simple syntax similarities.