-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make packed
substructs auto-serialize to []byte
#5
Comments
You'd need to support both variants. Imaging adding "noindex" to existing struct. Requiring map reduce to convert entities is unreasonable in this case. Consider adding new meta tag ",packed" (or something) instead. So the magic is visible to users. |
yeah ok, that sounds like a good idea. maybe packed implies noindex, but noindex doesn't imply packed? |
Yes :) And a big red warning that adding\removing "pack" requires running map reduce to update entities (or something). In worst case developers can do some stuff like OldCrap S and then read from Crap, falling backto OldCrap if needed. |
e.g. type Something struct {
Nums []int
Strings []string
}
type Group struct {
Things []Something `gae:",packed"`
} Would normally fail, but now type Group struct {
Things []byte `gae:",noindex"`
} Which means that Group would also itself be embeddable now. edit: gofmt pedantics |
I could use gob to pack, probably? |
Using gob would also allow a bit of flexibility when adding new fields and such, or embedding pointers or whatnot. |
Actually, I could make removing pack transparent. Basically if I try to unpack []byte into a struct, use gob to do it, and if I have it defined as packed, but see struct data, I can use the existing substruct serialization code (which would still imply that nested slices are banned, but that's fine). |
I've never used gob. I've used encoding/binary, and it won't work if structs have slices (seems like you want to support this case). So gob, yeah... Does it mean each struct type would have to be explicitly added to gob registry? |
gob registers all the basic types automatically, I think... it's only if you have an interface type that you need to register? |
Oh, or internal types maybe. |
"Only types that will be transferred as implementations of interface values need to be registered." https://golang.org/pkg/encoding/gob/#Register |
It's like magic! ✨ |
packed
substructs auto-serialize to []byte
was thinking about this a bit more. I think we could use a syntax like type Foo struct {
Field []ComplexType `gae:",pack=gob|gzip"`
} So it would be I think for compatibility purposes, the first 4 bytes would be |
Even though slice-of-slice isn't reasonable to implement, a substructure marked as noindex could /totally/ be serialized as just a normal []byte. This would allow the common nested-structs use case trivially handled by adding noindex. Folks that want indexes for their deeply nested stuff will have to denormalize or something, but I'm not too worried about that.
The text was updated successfully, but these errors were encountered: