ChanServ changed the topic of #crystal-lang to: The Crystal programming language | | Fund Crystal's development: | GH: | Docs: | Gitter:
<FromGitter> <domgetter> Is there a way to pretty-print a JSON string to a file? Using JSON::Serializable
<FromGitter> <Blacksmoke16> i dont think `JSON::Serializable` would help you if you want to pretty a JSON string
<FromGitter> <HertzDevil> `Object#to_pretty_json`
<FromGitter> <Blacksmoke16> there's a `to_pretty_json` if you wanted to convert an object to pretty json
<FromGitter> <Blacksmoke16> but wont help much if you just have the string
<FromGitter> <Blacksmoke16> unless maybe like `JSON.parse(str).to_pretty_json`?
<FromGitter> <domgetter> hmm Okay I'll try those out
<FromGitter> <domgetter> thank you
<FromGitter> <Blacksmoke16> what are you wanting to do?
<FromGitter> <domgetter> Well my ultimate goal is that I'm making a build tool to build my video game, and I need to do work on the art assets, but I want that work to be done incrementally and work with Make so that I don't build everything every time I make a change to anything. It didn't really matter that the JSON was pretty, I just wanted to know if I could.
<FromGitter> <domgetter> I think I might serialize to a manual binary format, though, because these JSON files are several megabytes
<FromGitter> <domgetter> Thank you for pointing me in the direction of Serializable thought
<FromGitter> <Blacksmoke16> could you just compress them?
<FromGitter> <domgetter> The size problem is manifesting as a parse time problem. I have plenty of hard drive space
<FromGitter> <Blacksmoke16> oh, are you doing `IO` based parsing?
<FromGitter> <domgetter> Or do you mean compress prior to serializing?
<FromGitter> <Blacksmoke16> just meant to reduce storage requirements
<FromGitter> <domgetter> Right now, Im just using Serializable.from_json to parse
<FromGitter> <Blacksmoke16> but what is the input?
<FromGitter> <Blacksmoke16> ` "input.json"`?
<FromGitter> <domgetter> I have an object representing a World in my game, and (for example) the `to_json` for village_animated makes a json file that is ~6 MB
<FromGitter> <Blacksmoke16> what im getting at is that like
<FromGitter> <Blacksmoke16> ``` "world.json", "w" do |file| ⏎ world.to_json file ⏎ end``` []
<FromGitter> <Blacksmoke16> is better than
<FromGitter> <Blacksmoke16> ```File.write "world.json", world.to_json```
<FromGitter> <Blacksmoke16> as the former doesn't load all the JSON into memory first, which might be helpful
<FromGitter> <domgetter> It's the read time that's "slow" for me right now
<FromGitter> <Blacksmoke16> also using an `IO` based read?
<FromGitter> <domgetter> Creating and writing the json files can take a long time for all I care, since I'm just trying to save time on future builds
<FromGitter> <Blacksmoke16> hmm
<FromGitter> <domgetter> Okay I'll try an IO based read
<FromGitter> <Blacksmoke16> would help reduce memory, but prob would be similar read time total tho
<FromGitter> <domgetter> Right now I'm doing `nes_world = NES::World.from_json(["name"] + "_serialized.json"))`
<FromGitter> <Blacksmoke16> try
<FromGitter> <Blacksmoke16> ```code paste, see link``` []
<FromGitter> <domgetter> Yeah, it takes about the same amount of time
<FromGitter> <domgetter> Thanks for the help though. The arrays in the JSON are full of numbers <256 so I was just trying to be quick and dirty with an off-the-shelf serialization.
<FromGitter> <domgetter> I just need to sit down and make a binary file format and write the bytes in.
<FromGitter> <Blacksmoke16> is this just like startup speed, or do you need to load them a bunch of times?
<FromGitter> <domgetter> I'll need to read each world file on every build to build the game
<FromGitter> <domgetter> I'll need to read each file once on each build
<FromGitter> <Blacksmoke16> is that a big deal then if it takes a few sec more?
<FromGitter> <Blacksmoke16> be much easier to work with JSON than bytes
<FromGitter> <domgetter> A few seconds now will turn into 10s of seconds when there are more worlds. This won't scale up and meet my needs
<FromGitter> <Blacksmoke16> hm, could do them concurrently?
<FromGitter> <domgetter> I mean, I know I'm misusing JSON for this purpose
<FromGitter> <domgetter> Yeah that's true, Make will help about 8x on that front.
<FromGitter> <Blacksmoke16> spawn each world in its own fiber and send the world back thru a channel
<FromGitter> <Blacksmoke16> should be quite a bit faster, esp if you enable MT mode
<FromGitter> <Blacksmoke16> the read of each world*
ur5us has joined #crystal-lang
ur5us has quit [Ping timeout: 240 seconds]
<hightower3> domgetter: for binary serialization, maybe look at Crystalizer? It doesn't have particularly good docs for its binary ByteFormat, but see specs for usage examples. Also, it would theoretically allow you to transparently switch between json, yaml, and binary
elf_fortrez has joined #crystal-lang
elf_fortrez has quit [Quit: Client closed]
elf-fortrez has joined #crystal-lang
notzmv has quit [Ping timeout: 240 seconds]
elf-fortrez has quit [Quit: Client closed]
scott_tams has quit [Quit: Leaving]
notzmv has joined #crystal-lang
<FromGitter> <mattrberry> This may be a silly question, but simply requiring the "llvm" module yields this error for me ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ Any clue why that might be? []
<FromGitter> <mattrberry> ccccccvcetdflfkvlgdiigvebgugjhebjtjgvghfgevh
<FromGitter> <Blacksmoke16> Looks like that const is returning an empty string
<FromGitter> <Blacksmoke16> Would have to look in the code to see why, probably missing some package or env var
<FromGitter> <christopherzimmerman> ```code paste, see link``` ⏎ ⏎ Is there a way to access the passed type here in the macro? []
<FromGitter> <Blacksmoke16> what is `S`? a generic on the type this macro is used in?
<FromGitter> <christopherzimmerman> yes, class is defined as `Tensor(T, S)`, I just want to catch certain methods being called for certain generic types on a class. Was hoping I could use an annotation, but honestly have no ideas how those work, figured a macro would work as well.
<FromGitter> <Blacksmoke16> i think you'd have to do that in a method, like the constructor as `T` and `S` don't exist (or at least aren't typed) within the class body itself
notzmv has quit [Ping timeout: 240 seconds]
<FromGitter> <mattrberry> :p
notzmv has joined #crystal-lang
ur5us has joined #crystal-lang
hightower3 has quit [Ping timeout: 240 seconds]
Elouin has quit [Read error: Connection reset by peer]
Elouin has joined #crystal-lang