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
votes
1 answer

How to efficiently decode gobs and wait for more to arrive via tcp connection

I'd like to have a TCP connection for a gaming application. It's important to be time efficient. I want to receive many objects efficiently. It's also important to be CPU efficient because of the load. So far, I can make sure handleConnection is…
Rick Giuly
  • 983
  • 1
  • 14
  • 19
-1
votes
1 answer

gob decoder attempting to decode into a non-pointer

In my Go program I am encoding []byte data with gob buf := new(bytes.Buffer) enc := gob.NewEncoder(buf) //data is []byte buf.Reset() enc.Encode(data) but getting 'gob decoder attempting to decode into a non-pointer'…
irom
  • 3,316
  • 14
  • 54
  • 86
-1
votes
2 answers

use gobs directly in the source code, is it possible?

I would like to know if it's possible to have gob encoded data directly in the source code (e.g. in a function). The reason is to increase performance by not having to access the disk to get the gob file. I'm aware of memcached, redis and friends. i…
The user with no hat
  • 10,166
  • 20
  • 57
  • 80
-2
votes
2 answers

Golang gob serializes array wrongly

I pass to gob array like this []int{} but on the receiving end I get array like this []int(nil) What is the differences between these arrays? Why gob serializes empty array like this?
Mark
  • 423
  • 4
  • 12
-2
votes
1 answer

gob not decoding as expected

Here is my playground where I am trying to serialize a list of structures and read back from the file. https://play.golang.org/p/8x0uciOd1Sq I was expecting the object to be decoded successfully. What am I doing wrong?
user447851
  • 163
  • 2
  • 6
-5
votes
1 answer

trying to understand how the Go gob encoder works

in my ambitions to understand how gob work . i have severals question . i know that gob serialize a go type like struct map or interface(we must register it's real type) but : func (dec *Decoder) Decode(e interface{}) error Decode reads the next…
WALID BELRHALMIA
  • 441
  • 5
  • 12
1 2 3 4 5 6 7
8