jdpage/heroburn — Issue #1: Fix network code
Author: jdpage
Created: 2011-12-09 05:29:38+00:00
State: open

[00:23:22] jdpage: presumably how you deal with each struct after decoding it is also different
[00:23:29] Guest86887: nope.
[00:23:35] I just stuff it all into a channel
[00:23:39] jdpage, this is one the reasons I was expecting Go to have some kind of union C-like struct ... but apparently "that would go against Go principle design"
[00:23:39] then why are they different types?
[00:23:44] which *does* actually use interface magic
[00:23:53] Guest86887: a different part of the code cares about that.
[00:24:13] araujo: well sure. we have interface{}
[00:24:25] which covers 98.43% of use cases for unions.
[00:24:34] ah.
[00:24:58] one way to do it is to have a map from type int to a reflect.Type
[00:25:06] and use the reflect package to instantiate a value of that type
[00:25:19] which you can then pass to the gob decoder as an interface{}
[00:25:31] (gob also uses the reflection layer, so it all works out)
[00:25:38] I feel like is a terrible terrible idea which might actually work :|
[00:25:44] *that is
[00:25:51] that will just give you an interface{}, but that seems to be what you want in any case
[00:25:55] Yeah
[00:26:00] Hmm.
[00:26:13] Actually, I think that works.
[00:26:15] or you could move the processing to this side of the channel
[00:26:27] it does. I've used that registry technique before
[00:26:40] Guest86887: Oh, it works, the question is am I prepared to deal with reflection
[00:26:52] as long as I don't have reflection leaking all over my code, it should be fine.
[00:27:03] populating the map makes you feel a little dirty (you need to reflect.TypeOf(mystruct{}) a bunch of times)
[00:27:09] it won't leak.
[00:27:31] once you've constructed the object with the reflection API, it's a regular interface{}
[00:27:38] --> eikenberry has joined this channel (~jae@97-115-112-57.ptld.qwest.net).
[00:27:56] araujo: and the design principle unions violate is memory safety
[00:28:04] Guest27490, yes
[00:28:36] Guest86887: well, I am going to sleep now. I am just going to copy this entire conversation into a bug report assigned to me
[00:28:40] Guest86887: thanks very much.