{"action":"created","issue":{"url":"https://api.github.com/repos/gonum/matrix/issues/337","repository_url":"https://api.github.com/repos/gonum/matrix","labels_url":"https://api.github.com/repos/gonum/matrix/issues/337/labels{/name}","comments_url":"https://api.github.com/repos/gonum/matrix/issues/337/comments","events_url":"https://api.github.com/repos/gonum/matrix/issues/337/events","html_url":"https://github.com/gonum/matrix/issues/337","id":136383545,"number":337,"title":"Use in conjunction with gob","user":{"login":"pcostanza","id":5313179,"avatar_url":"https://avatars.githubusercontent.com/u/5313179?v=3","gravatar_id":"","url":"https://api.github.com/users/pcostanza","html_url":"https://github.com/pcostanza","followers_url":"https://api.github.com/users/pcostanza/followers","following_url":"https://api.github.com/users/pcostanza/following{/other_user}","gists_url":"https://api.github.com/users/pcostanza/gists{/gist_id}","starred_url":"https://api.github.com/users/pcostanza/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pcostanza/subscriptions","organizations_url":"https://api.github.com/users/pcostanza/orgs","repos_url":"https://api.github.com/users/pcostanza/repos","events_url":"https://api.github.com/users/pcostanza/events{/privacy}","received_events_url":"https://api.github.com/users/pcostanza/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-02-25T13:09:04Z","updated_at":"2016-02-25T15:11:08Z","closed_at":null,"body":"I'm trying to send instances of `mat64.Vector` over a TCP/IP connection, and use `encoding/gob` from the Go standard library for this purpose. While it's possible to make it work, I believe it's currently not ideal.\r\n\r\nEncoding (sending) is relatively straightforward:\r\n\r\n    func EncodeVector(enc *gob.Encoder, v *mat64.Vector) {\r\n        enc.Encode(v.RawVector().Data)\r\n    }\r\n\r\nEncoding the vector instance directly, like in `enc.Encode(v)` is not possible, because the instance variables of the `mat64.Vector` struct are not exported, and therefore the gob library does not (cannot?) access them. Encoding the raw `[]float64` slice instead is fine, though.\r\n\r\nHowever, decoding is wasteful. In my version, it currently looks like this:\r\n\r\n    func DecodeVector(dec *gob.Decoder, v *mat64.Vector) *mat64.Vector {\r\n        floats := v.RawVector().Data\r\n        dec.Decode(&floats)\r\n        return mat64.NewVector(len(floats), floats)\r\n    }\r\n\r\nWhile I'm making some attempt to reuse the raw `[]float64` slice of an existing vector, there is actually a good chance a new slice will be created, and on top of that, a new `mat64.Vector` instance needs to be created in any case.\r\n\r\nMy preference would be to be able to say `dec.Decode(&v.RawVector().Data)`, but Go doesn't allow for taking the address of the field `Data` in the non-addressable instance returned by `RawVector()`, which is probably good, because the original `Data` field inside `v` would not be assigned to if a new slice needs to be allocated.\r\n\r\nDo you see a possibility to make `gonum/matrix` interact better with `encoding/gob`? Or am I missing a way to have them work better together already? (I'm new to Go, so please accept my apologies if I'm missing something obvious here.)\r\n\r\nThanks,\r\nPascal\r\n"},"comment":{"url":"https://api.github.com/repos/gonum/matrix/issues/comments/188828545","html_url":"https://github.com/gonum/matrix/issues/337#issuecomment-188828545","issue_url":"https://api.github.com/repos/gonum/matrix/issues/337","id":188828545,"user":{"login":"btracey","id":3680859,"avatar_url":"https://avatars.githubusercontent.com/u/3680859?v=3","gravatar_id":"","url":"https://api.github.com/users/btracey","html_url":"https://github.com/btracey","followers_url":"https://api.github.com/users/btracey/followers","following_url":"https://api.github.com/users/btracey/following{/other_user}","gists_url":"https://api.github.com/users/btracey/gists{/gist_id}","starred_url":"https://api.github.com/users/btracey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/btracey/subscriptions","organizations_url":"https://api.github.com/users/btracey/orgs","repos_url":"https://api.github.com/users/btracey/repos","events_url":"https://api.github.com/users/btracey/events{/privacy}","received_events_url":"https://api.github.com/users/btracey/received_events","type":"User","site_admin":false},"created_at":"2016-02-25T15:11:08Z","updated_at":"2016-02-25T15:11:08Z","body":"If Vector et al were to implement the GobEncoder and GobDecoder interfaces would that fix the problm?"}}