<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>
<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>
<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
<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