These are chat archives for ProtoDef-io/node-protodef

28th
Feb 2017
mhsjlw
@mhsjlw
Feb 28 2017 00:00
I wrote ocaml a long long time ago , not sure if I remember any at all lol
I wonder
Do I have no idea what I'm talking about, or would it be possible to write an ocaml protodef that compiles to elixir, JavaScript, rust, java, CPP etc. etc.
mhsjlw
@mhsjlw
Feb 28 2017 00:05
would that get us on trending :) lol
Romain Beaumont
@rom1504
Feb 28 2017 00:06
well yes
it's possible to do that it any language
the question is whether it would be easy
mhsjlw
@mhsjlw
Feb 28 2017 00:09
I think we should explore having a single toolchain
rather than writing an interpreter in each language
idk
ocaml seems like 'the' language to do this in
Robin Lambertz
@roblabla
Feb 28 2017 10:53
OCaml is a good language for compiler work in general.
That said, I think rust is a solid contender, and brings a lot of goodies.
also, it can be argued that protodef ain't much of a compiler. We delegate the parsing to a JSON lib 'n stuff
Robin Lambertz
@roblabla
Feb 28 2017 11:00
So I'm at that point where things get rough
I have to make switch work with both strings and integers
sigh
I'm not too sure how I want to handle that.
Romain Beaumont
@rom1504
Feb 28 2017 11:55
do you have to ?
switch handle strings ?
oh it does
I believe you need to do a bit of type inferring
ie check the type of the compareTo
do you have expand with $ and all yet btw ?
Hans Elias J.
@hansihe
Feb 28 2017 13:18
that's where you need to do type inference
it's relatively straightforward if your compiler is multipass
I had a plan for implementing it when I was writing my elixir compiler, but I have forgotten the specifics now
i can try to give you some pointers if you want
Romain Beaumont
@rom1504
Feb 28 2017 13:27
ProtoDef-io/elixir-protodef#1
Robin Lambertz
@roblabla
Feb 28 2017 14:45
I have the underlying type accessible, but I think I'm going to hack my way around for now.
Oh. Actually, I don't have the underlying type accessible
since it's in another field
Derp.
Robin Lambertz
@roblabla
Feb 28 2017 14:58
This sucks. I really wish we didn't have to go multipass :/
Hans Elias J.
@hansihe
Feb 28 2017 16:45
elixir_protodef is multipass :)
i think it generally makes the code a lot cleaner
you get ast -> ast operations that are fairly simple to read and understand, you avoid having everything that has to be done slinky'd together
mhsjlw
@mhsjlw
Feb 28 2017 18:13
so um
apparently rhino can compile JavaScript to Java
so I'm going to play with that for a bit
no love for node though I think
mhsjlw
@mhsjlw
Feb 28 2017 18:23
um
why is my avatar gone
hansihe lost his too ?
We are investigating issues serving web hooks as well as assets on GitHub.com.
ah
good one github
Hans Elias J.
@hansihe
Feb 28 2017 18:41
there is an outage in s3
so that's probably related
mhsjlw
@mhsjlw
Feb 28 2017 19:00
ah
mhsjlw
@mhsjlw
Feb 28 2017 20:16
@hansihe I'm thinking it might be interesting to write an example project for elixir-protodef? I still can't even figure out how to use it but I'd like to finish up my work on the Minecraft Classic server I was working on
Hans Elias J.
@hansihe
Feb 28 2017 20:17
mhsjlw: definitely
although there is a fairly comprehensive usage example in McProtocol
since it's a compiler, it really isn't as simple as just calling a function though
and since protodef only defines a type format, not a container format, you have to do that part yourself as well
that's what the majority of the code in packet.ex does
Hans Elias J.
@hansihe
Feb 28 2017 20:22
the actual protodef -> ast compilation is just a single function call
mhsjlw
@mhsjlw
Feb 28 2017 20:29
Ok
Yeah, you know what, I'll make a new repository, and I give this a try, I'll add you to it whether or not you want to commit. I think this could be useful for new ProtoDef projects if I document it properly
@hansihe ^
Hans Elias J.
@hansihe
Feb 28 2017 20:30
sure!
mhsjlw
@mhsjlw
Feb 28 2017 20:30
aside: the one damn day I actually have to download something from s3
lol
Hans Elias J.
@hansihe
Feb 28 2017 20:31
i'm in the middle of finishing up something else though, so I won't be doing anything with that today
mhsjlw
@mhsjlw
Feb 28 2017 20:31
yeah, yeah. I'll be able to ping you if I have a quick question?
Hans Elias J.
@hansihe
Feb 28 2017 20:32
of course
mhsjlw
@mhsjlw
Feb 28 2017 20:33
ah, slack is broken
hmmph
no work! wahoo!
lol
Hans Elias J.
@hansihe
Feb 28 2017 20:35
turns out 50% of the stuff i use gets fucked if aws goes south
mhsjlw
@mhsjlw
Feb 28 2017 20:37
yup :(
oh shit , i can't download minecraft assets
... kinda need those for ClassicalSharp (it requires 1.6.2 textures and jar file...)
web archive has it ;)
Romain Beaumont
@rom1504
Feb 28 2017 20:56
"and since protodef only defines a type format, not a container format, you have to do that part yourself as well" I recently added the protocol format in the ProtoDef repo
elixir-protodef doesn't have mapper though
so anyway you can't really use the whole protocol.json if I understand correctly
mhsjlw
@mhsjlw
Feb 28 2017 20:58
oh, totally forgot i never finished my minecraft classic client in the browser
i have to do that one day
Hans Elias J.
@hansihe
Feb 28 2017 20:59
yeah, no mapper
mhsjlw
@mhsjlw
Feb 28 2017 20:59
that would be a good example for using protodef in the browser
i'll put that on my todo
mhsjlw
@mhsjlw
Feb 28 2017 21:07
I can't think of a good name for this
so i just called it MinecraftClassic
if you can think of something, please tell me, i don't like using this as the module name :P
Hans Elias J.
@hansihe
Feb 28 2017 21:09
name for what? the elixir_protodef example?
mhsjlw
@mhsjlw
Feb 28 2017 21:11
for the minecraft classic server that i'm going to write for the example
mhsjlw
@mhsjlw
Feb 28 2017 21:30
why proto_def and not protodef
@hansihe ^
Hans Elias J.
@hansihe
Feb 28 2017 21:34
because the module name is ProtoDef
mhsjlw
@mhsjlw
Feb 28 2017 21:34
ah, yeah
Hans Elias J.
@hansihe
Feb 28 2017 21:34
by convention that becomes proto_def
mhsjlw
@mhsjlw
Feb 28 2017 21:34
yeah. also, update the poison dep to 3?
for some reason hex only allows for deps to all have the same version ? wtf
Failed to use "poison" (version 3.1.0) because   
  proto_def (version 0.0.4) requires ~> 2.0 
  mix.exs specifies ~> 3.1
why ?!
node doesn't do that?
i'll just relax it for now
Romain Beaumont
@rom1504
Feb 28 2017 21:36
npm is almost the only package manager which handle several versions for a dependency @mhsjlw
mhsjlw
@mhsjlw
Feb 28 2017 21:36
gotcha
Romain Beaumont
@rom1504
Feb 28 2017 21:36
maybe it doesn't make sense in other languages because of types though
Hans Elias J.
@hansihe
Feb 28 2017 21:37
and if that's a good idea or not in npm is still up for discussion, but that's something for another day :)
mhsjlw
@mhsjlw
Feb 28 2017 21:37
@hansihe so do I have to split up every single type and compile each one?
since it doesn't have full file compilation if i remember correctly ... ?
meaning i also have to figure out how to map incoming data from id -> specific packet
Hans Elias J.
@hansihe
Feb 28 2017 21:38
the compiler does single protodef type => ast, that's all
mhsjlw
@mhsjlw
Feb 28 2017 21:38
yeah
so when exactly should I compile
Romain Beaumont
@rom1504
Feb 28 2017 21:41
well compile all types, store them somewhere, then use them at runtime ?
mhsjlw
@mhsjlw
Feb 28 2017 21:41
well, i'm asking because I have code-implemented types
and the tests don't have anything that i can find useful
Hans Elias J.
@hansihe
Feb 28 2017 21:42
what you do is
at compile time, load your protodef .json file
then go through all types in that file, call ProtoDef.compile_json_type on it
that will return a map containing ASTs for the encoder and decoder
you then have to generate and define modules/functions that contains those ASTs
those functions can be used at runtime
Hans Elias J.
@hansihe
Feb 28 2017 21:47
then here it loops through all the packet types defined in that file https://github.com/McEx/McProtocol/blob/master/lib/packet.ex#L84
mhsjlw
@mhsjlw
Feb 28 2017 21:47
would McData work with 0.30c ?
Romain Beaumont
@rom1504
Feb 28 2017 21:47
oh that's pretty clean
Hans Elias J.
@hansihe
Feb 28 2017 21:47
then it gets embedded into the ast for a module definition and defined here https://github.com/McEx/McProtocol/blob/master/lib/packet.ex#L93-L118
mhsjlw
@mhsjlw
Feb 28 2017 21:48
o.O
wtf is wrong with gitter
can they get their shit together
the bridge has rebooted like 6 times in 30 minutes
mhsjlw
@mhsjlw
Feb 28 2017 22:01
yeah ok, no idea what I'm doing here. this protocol.json operates quite differently
and I don't have McProtocol. I'll figure it out eventually
I guess what my goal is is just to fill a map with state, packets and direction
no idea what state is, and not sure what packets i
*is
also, not sure how you represent direction
that's the general defintion of protocol.json if you feel like implementing it
state and direction are just particular case of namespaces
Hans Elias J.
@hansihe
Feb 28 2017 22:02
as a starting point, just try to call ProtoDef.compile_json_type and look at the output
that should get you started at least
mhsjlw
@mhsjlw
Feb 28 2017 22:03
to_client_packets = raw_data["toClient"]
|> Enum.flat_map(fn {name, container} ->
    %{
        state: ,
        direction: :to_client,
        packets: ,
        types: raw_data["toClient"]
    }
end
Hans Elias J.
@hansihe
Feb 28 2017 22:03
don't bother with that yet
just call ProtoDef.compile_json_type for a single type
mhsjlw
@mhsjlw
Feb 28 2017 22:03
ok
Hans Elias J.
@hansihe
Feb 28 2017 22:03
that's the entire api surface area for the compiler, everything else is just regular old data wrangling
good article btw
We do not have ONE web-server handling 2 millions sessions. We have 2 million webservers handling one session each.
made me laugh
20k webservers a second
mhsjlw
@mhsjlw
Feb 28 2017 22:14
mcpe server in elixir confirmed
I think I'm just going to use ranch
it'll make my life a little easier
Robin Lambertz
@roblabla
Feb 28 2017 23:55
I found a way to work around my problem to avoid multipass. It's so dirty it hurts :D