Skip to content

encoding/gob: (or maybe time.Time): unexplained error with time.Time value #4647

@robpike

Description

@robpike
http://play.golang.org/p/cNlOycuLzl is this:

package main

import (
    "bytes"
    "encoding/gob"
    "time"
)

type Update struct {
    Time        time.Time   // ***  Note1 : Works if change from time.Time -> int ***//
}

type Time struct {
    T   *time.Time
}

type PC struct {
    Id            int64 
    Update []Update  // ***  Note2 : Works if comment out one of  Update or LastUpdate ***//
    LastUpdate    Time 
}

func main() {
    buf := new(bytes.Buffer)
    enc := gob.NewEncoder(buf)
    var err error
    if err = enc.Encode(PC{}); err != nil {
        println("A", err.Error())
        return
    }
    dec := gob.NewDecoder(bytes.NewBuffer(buf.Bytes()))
    if err = dec.Decode(new(PC)); err != nil {
        println("B", err.Error())
        return
    }
}

It prints "B extra data in buffer. Removing either of the time.Time values from the
struct or replacing them with ints clears up the error. Something is awry with gots and
time.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions