Questions tagged [gob]

gob is a Go specific protocol and package for the exchange of data between Go programs. Any question having this tag should also be tagged with [go].

The Go protocol defines a solution for the binary encoding and decoding of go data, aimed at exchange between Go programs, in which it is supported by the gob package.

The Go playground has an example by the Go team :

package main

import (
    "bytes"
    "encoding/gob"
    "fmt"
    "log"
)

type P struct {
    X, Y, Z int
    Name    string
}

type Q struct {
    X, Y *int32
    Name string
}

func main() {
    // Initialize the encoder and decoder.  Normally enc and dec would be
    // bound to network connections and the encoder and decoder would
    // run in different processes.
    var network bytes.Buffer        // Stand-in for a network connection
    enc := gob.NewEncoder(&network) // Will write to network.
    dec := gob.NewDecoder(&network) // Will read from network.
    // Encode (send) the value.
    err := enc.Encode(P{3, 4, 5, "Pythagoras"})
    if err != nil {
        log.Fatal("encode error:", err)
    }
    // Decode (receive) the value.
    var q Q
    err = dec.Decode(&q)
    if err != nil {
        log.Fatal("decode error:", err)
    }
    fmt.Printf("%q: {%d,%d}\n", q.Name, *q.X, *q.Y)
}
111 questions
1
vote
0 answers

Extra data in buffer error when decoding with gob - golang

I'm decoding with gob several objects fetched from a key/value database called "bitcask". When I try to decode all of them one by one I get the "extra data in buffer" error from the gob decoder but exclusively for the first element that was added in…
NicoNex
  • 469
  • 2
  • 5
  • 15
1
vote
0 answers

golang RPC struct of type interface{} nested inside reply *Struct

I was wondering whether it is possible in go to initiate an RPC with a reply pointer to a value that looks like type NSReply struct { Done int Reply interface {} } In my case, I'm getting the error: rpc: gob error encoding body: gob: type…
wfehrnstrom
  • 329
  • 2
  • 17
1
vote
1 answer

Sequentially write protobuf messages to a file in go

I have a huge number of similar object (about hundreds of gigabytes) and I need to serialize it and write to a file sequentially and after that read it in the same order. How to do it in protobuf (gogo proto) in golang? Gob has a encoder which can…
abonec
  • 1,379
  • 1
  • 14
  • 23
1
vote
1 answer

Convert int array to byte array, compress it then reverse it

I have a large int array that I want to persist on the filesystem. My understanding is the best way to store something like this is to use the gob package to convert it to a byte array and then to compress it with gzip. When I need it again, I…
amlwwalker
  • 3,161
  • 4
  • 26
  • 47
1
vote
1 answer

Gob decoder throws EOF error for a time then stops

I'm trying to feed []byte over a chan to a gob decoder. It works, but at first the decoder throws a whole bunch of EOF errors then stops. When it stops throwing errors the program behaves exactly like I would expect with it decoding gobs and…
gochuck
  • 185
  • 2
  • 13
1
vote
2 answers

Golang + postgres storing gob data

I'm trying to store encoded data using encoding/gob from Golang into Postgres. I'm using Gorm as well. First, sending form data using if err := json.NewDecoder(r.Body).Decode(model); err != nil { http.Error(w, err.Error(), http.StatusBadRequest) …
Greg Miller
  • 1,064
  • 13
  • 22
1
vote
0 answers

Out of memory when transferring large file

I'm using Go Gob to transfer large files (~ 1 GB) or many small files (~ 30 MB). Server is running in a loop, and will receive files when clients send it. My code is working if I send one large file, or few small files, but when sending a large file…
grbueno
  • 11
  • 1
1
vote
0 answers

When using gob to serialiaze structs over the wire, why do we need to Register() any fields that are interfaces inside the transmitted struct?

If we were to send type ABC struct{ i interface{} } gob requires us to register the concrete type hidden behind our interface{}. Why can't gob use reflection to identify the underlying concrete class in the field by itself. That is, we…
Robert Jakubowicz
  • 338
  • 1
  • 4
  • 11
1
vote
2 answers

I'm getting "extra data in buffer" error when trying to decode a gob in golang

I'm encoding and sending multiple objects on a stream. I decode them as show in code below, keeping the connection open. I'm getting "extra data in buffer" error on the decode of all objects after the first. func handleAggregatorConnection(conn…
Rick Giuly
  • 983
  • 1
  • 14
  • 19
1
vote
1 answer

gob: type not registered for interface: http.gzipReader

I a simple TCP server that accept connection , Get a URL using http.Get and then encode the response using gob. But gob fails to encode http.gzipReader. On encoding it gives following error message: gob: type not registered for interface:…
Raja Hammad Farooq
  • 921
  • 1
  • 9
  • 17
1
vote
1 answer

Golang RPC encode custom function

I am trying to use github.com/dullgiulio/pingo and send my custom struct type LuaPlugin struct { Name string List []PluginTable } type PluginTable struct { Name string F lua.LGFunction } // LoadPlugins walks over the plugin…
Raggaer
  • 3,244
  • 8
  • 36
  • 67
1
vote
0 answers

beego session save struct

I'm giving up after few weeks, can't figure out a way to encode/decode a struct in session between beego apps. Question: How to store properly in session a struct say app1/models/User and decode it in other process/app to app2/models/User without…
1
vote
1 answer

redigo and gob how to retrieve slices of gob data

I'm pushing in my redis base my objects with the "RPUSH" command. // object is of type interface var network bytes.Buffer gob.NewEncoder(&network) enc.Encode(object /* interface{} */) redis.String(d.Conn.Do("RPUSH", "objects",…
Mr Bonjour
  • 3,330
  • 2
  • 23
  • 46
1
vote
1 answer

gob attempting to decode nil value results in EOF error

I need to use the gob to encode some data, however, I find that "type nil" can not be processed correctly (go 1.6.2) https://play.golang.org/p/faypK8uobF package main import ( "bytes" "encoding/gob" "log" ) type T struct { A…
llx
  • 365
  • 4
  • 7
1
vote
1 answer

How to encode/decode a empty string

I am using the GOB encoding for my project and i figured out (after a long fight) that empty strings are not encoded/decoded correctly. In my code i use a errormessage (string) to report any problems, this errormessage is most of the time empty. If…
Dippo
  • 184
  • 2
  • 11