func gobDecodeList(b *testing.B, l int) { var ( enc *gob.Encoder buf bytes.Buffer err error ) s := make([]int, l) for i, _ := range s { s[i] = rand.Int() } enc = gob.NewEncoder(&buf) err = enc.Encode(s) if err != nil { panic(err.Error()) } var dest []int bs := buf.Bytes() b.ResetTimer() // decode for i := 0; i < b.N; i++ { nbuffer := bytes.NewBuffer(bs) dec := gob.NewDecoder(nbuffer) err := dec.Decode(&dest) if err != nil { panic(err.Error()) } } }
func SendPeer(encod *gob.Encoder) { err := encod.Encode(*MyPublicPeer) if err != nil { log.Fatal("Error sending Public Peer: ", err) } }
func sendMakeDirectory(encoder *gob.Encoder, directory image.Directory) error { imageUpdate := imageserver.ImageUpdate{ Directory: &directory, Operation: imageserver.OperationMakeDirectory, } return encoder.Encode(imageUpdate) }
func netSender(netOutStream <-chan HashedInterval, encoder *gob.Encoder, netOutDoneStream chan<- bool) { for r := range netOutStream { if verboseServer { log.Debug("Server.netSender: sending", r.FileInterval) } err := encoder.Encode(r) if err != nil { log.Fatal("Protocol encoder error:", err) netOutDoneStream <- false return } } rEOF := HashedInterval{FileInterval{SparseIgnore, Interval{}}, make([]byte, 0)} if rEOF.Len() != 0 { log.Fatal("Server.netSender internal error") } // err := encoder.Encode(HashedInterval{FileInterval{}, make([]byte, 0)}) err := encoder.Encode(rEOF) if err != nil { log.Fatal("Protocol encoder error:", err) netOutDoneStream <- false return } if verboseServer { log.Debug("Server.netSender: finished sending hashes") } netOutDoneStream <- true }
func CreateGobsFile(targetFilePath string, recs *[]interface{}, getRecPtr GobRecPtrMaker, gzipped bool) { var file, err = os.Create(targetFilePath) var gobber *gob.Encoder var gzipper *gzip.Writer if file != nil { defer file.Close() } if err != nil { panic(err) } if gzipped { if gzipper, err = gzip.NewWriterLevel(file, gzip.BestCompression); gzipper != nil { defer gzipper.Close() gobber = gob.NewEncoder(gzipper) } if err != nil { panic(err) } } else { gobber = gob.NewEncoder(file) } for _, rec := range *recs { if err = gobber.Encode(coreutil.PtrVal(getRecPtr(rec))); err != nil { panic(err) } } }
func (conn *LocalConnection) exchangeHandshake(localConnID uint64, usingPassword bool, enc *gob.Encoder, dec *gob.Decoder) (*FieldValidator, *[32]byte, error) { handshakeSend := map[string]string{ "PeerNameFlavour": PeerNameFlavour, "Name": conn.local.Name.String(), "NickName": conn.local.NickName, "UID": fmt.Sprint(conn.local.UID), "ConnID": fmt.Sprint(localConnID)} handshakeRecv := map[string]string{} var public, private *[32]byte var err error if usingPassword { public, private, err = GenerateKeyPair() if err != nil { return nil, nil, err } handshakeSend["PublicKey"] = hex.EncodeToString(public[:]) } enc.Encode(handshakeSend) if err = dec.Decode(&handshakeRecv); err != nil { return nil, nil, err } fv := NewFieldValidator(handshakeRecv) fv.CheckEqual("PeerNameFlavour", PeerNameFlavour) return fv, private, nil }
func gobDecodeMap(b *testing.B, l int, kl int) { var ( enc *gob.Encoder buf bytes.Buffer err error ) s := make(map[string]int) for i := 0; i < l; i++ { key := keygen(i, kl) s[key] = rand.Int() } enc = gob.NewEncoder(&buf) err = enc.Encode(s) if err != nil { panic(err.Error()) } var dest map[string]int bs := buf.Bytes() b.ResetTimer() // decode for i := 0; i < b.N; i++ { nbuffer := bytes.NewBuffer(bs) dec := gob.NewDecoder(nbuffer) err := dec.Decode(&dest) if err != nil { panic(err.Error()) } } }
func readinput(c net.Conn, enc *gob.Encoder) { var buf [1]byte for { n, err := os.Stdin.Read(buf[:]) if err != nil { log.Print("Failed to read stdin.") return } if n != 1 { // short read? why? continue } if buf[0] == 0x01 { // ctrl-a ctrla := escape(c, enc) if !ctrla { continue } } if readwrite { req := &connReq{Cmd: Write, Input: buf[:]} err = enc.Encode(req) if err != nil { log.Print("Failed to write on connection.") // just keep trying } } } }
func (cbv *CachedBackendVersion) encodeCacheToGob(enc *gob.Encoder) error { cbv.mu.Lock() defer cbv.mu.Unlock() if err := enc.Encode(cbv.cache); err != nil { return fmt.Errorf("Failed to encode cache map: %v", err) } return nil }
func (m *gobMarshallingProvider) safeEncode(enc *gob.Encoder, val interface{}) (err error) { defer func() { if r := recover(); r != nil { err = fmt.Errorf("Panic encoding: %v", r) } }() err = enc.Encode(val) return }
func (console *Console) Save(encoder *gob.Encoder) error { encoder.Encode(console.RAM) console.CPU.Save(encoder) console.APU.Save(encoder) console.PPU.Save(encoder) console.Cartridge.Save(encoder) console.Mapper.Save(encoder) return encoder.Encode(true) }
func writeTo(buffers [][]*rfc5424.Message, enc *gob.Encoder) error { for _, buf := range buffers { for _, msg := range buf { if err := enc.Encode(msg); err != nil { return err } } } return nil }
func clientEncode(encode *gob.Encoder, buf *bufio.Writer, send <-chan *packet.Packet) { for msg := range send { if err := encode.Encode(msg); err != nil { log.Printf("Error encoding packet: %s", err) } if err := buf.Flush(); err != nil { log.Printf("Error writing buffer: %s", err) } } }
func (dn *DirNode) EncodeToGob(enc *gob.Encoder) error { if err := serializeCommon(enc, dn.GetType(), dn.INodeCommon); err != nil { return err } if err := enc.Encode(dn.Entries); err != nil { return fmt.Errorf("Failed to encode Entries: %v", err) } return nil }
// serializeStructInternalEncode takes struct field metadata and encodes the value using gob. func serializeStructInternalEncode(enc *gob.Encoder, smd *structMetaData, fieldName, metaData string, encodeValue bool, v reflect.Value) error { smd.metaDatas = append(smd.metaDatas, metaData) smd.totalLength += len(metaData) if encodeValue { if err := enc.EncodeValue(v); err != nil { return fmt.Errorf("goon: Failed to encode field %v value %v - %v", fieldName, v.Interface(), err) } } return nil }
func (m *Mapper1) Save(encoder *gob.Encoder) error { encoder.Encode(m.shiftRegister) encoder.Encode(m.control) encoder.Encode(m.prgMode) encoder.Encode(m.chrMode) encoder.Encode(m.prgBank) encoder.Encode(m.chrBank0) encoder.Encode(m.chrBank1) encoder.Encode(m.prgOffsets) encoder.Encode(m.chrOffsets) return nil }
func negotiateVersion(e *gob.Encoder, d *gob.Decoder) { var c Command c.Command = CmdVersion c.Params = []string{protocolVersion} err := e.Encode(c) panicOn(err) err = d.Decode(&c) if c.Params[0] != protocolVersion { panic(fmt.Errorf("Mismatched protocol version %s != %s", c.Params[0], protocolVersion)) } panicOn(err) }
// interfaceEncode encodes the interface value into the encoder. func interfaceEncode(enc *gob.Encoder, p Pythagoras) { // The encode will fail unless the concrete type has been // registered. We registered it in the calling function. // Pass pointer to interface so Encode sees (and hence sends) a value of // interface type. If we passed p directly it would see the concrete type instead. // See the blog post, "The Laws of Reflection" for background. err := enc.Encode(&p) if err != nil { log.Fatal("encode:", err) } }
func gobEncode(data interface{}) { var ( enc *gob.Encoder buf bytes.Buffer err error ) enc = gob.NewEncoder(&buf) err = enc.Encode(data) if err != nil { panic(err.Error()) } }
func (p *IndexDb) SaveConfig(path string, config *IndexDbConfig) error { var buf bytes.Buffer var enc *gob.Encoder = gob.NewEncoder(&buf) var encodeErr error = enc.Encode(config) if encodeErr != nil { log.Fatal("encode error:", encodeErr) } file, err := os.Create(path) file.Write(buf.Bytes()) file.Close() return err }
func (b *Bin1D) gobEncode(enc *gob.Encoder) error { var err error err = enc.Encode(b.entries) if err != nil { return err } err = enc.Encode(b.sw) if err != nil { return err } err = enc.Encode(b.swc) if err != nil { return err } err = enc.Encode(b.sw2) if err != nil { return err } return err }
func sendSyncRequest(encoder *gob.Encoder, decoder *gob.Decoder, path string, size int64, salt []byte) bool { err := encoder.Encode(requestHeader{requestMagic, syncRequestCode}) if err != nil { log.Fatal("Client protocol encoder error:", err) return false } err = encoder.Encode(path) if err != nil { log.Fatal("Client protocol encoder error:", err) return false } err = encoder.Encode(size) if err != nil { log.Fatal("Client protocol encoder error:", err) return false } err = encoder.Encode(salt) if err != nil { log.Fatal("Client protocol encoder error:", err) return false } var ack bool err = decoder.Decode(&ack) if err != nil { log.Fatal("Client protocol decoder error:", err) return false } return ack }
func (s *Server) clientWriteRoutine(enc *gob.Encoder) { defer s.StackCatcher() for event := range s.Events { var data wireData data.Event = event err := enc.Encode(data) if err != nil { if s.Logger != nil { s.Logger.Printf("CGF error writing to client: %v", err) } return } } }
func (peer *Peer) Encode(enc *gob.Encoder) { checkFatal(enc.Encode(peer.PeerSummary)) connSummaries := []ConnectionSummary{} for _, conn := range peer.connections { connSummaries = append(connSummaries, ConnectionSummary{ conn.Remote().NameByte, conn.RemoteTCPAddr(), conn.Outbound(), conn.Established(), }) } checkFatal(enc.Encode(connSummaries)) }
func (fn *FileNode) EncodeToGob(enc *gob.Encoder) error { if err := serializeCommon(enc, fn.GetType(), fn.INodeCommon); err != nil { return err } if err := enc.Encode(fn.Size); err != nil { return fmt.Errorf("Failed to encode Size: %v", err) } if err := enc.Encode(fn.Chunks); err != nil { return fmt.Errorf("Failed to encode Chunks: %v", err) } return nil }
func makeSend(fname string) (chan<- Request, <-chan error, Stopper) { var enc *gob.Encoder open := func(fname string) (*os.File, error) { file, err := os.OpenFile(fname, os.O_WRONLY, 0666) if err == nil { enc = gob.NewEncoder(file) } return file, err } tx := func(v interface{}) error { return enc.Encode(v) } return makeTx(fname, open, tx) }
func (peer *Peer) encode(enc *gob.Encoder) { if err := enc.Encode(peer.peerSummary); err != nil { log.Fatal(err) } connSummaries := []connectionSummary{} for _, conn := range peer.connections { connSummaries = append(connSummaries, connectionSummary{ conn.Remote().NameByte, conn.remoteTCPAddress(), conn.isOutbound(), conn.isEstablished(), }) } if err := enc.Encode(connSummaries); err != nil { log.Fatal(err) } }
func (apu *APU) Save(encoder *gob.Encoder) error { encoder.Encode(apu.cycle) encoder.Encode(apu.framePeriod) encoder.Encode(apu.frameValue) encoder.Encode(apu.frameIRQ) apu.pulse1.Save(encoder) apu.pulse2.Save(encoder) apu.triangle.Save(encoder) apu.noise.Save(encoder) apu.dmc.Save(encoder) return nil }
func gobEncodeMapIntNi(b *testing.B, l int) { s := make(map[int]int) for idx := 0; idx < l; idx++ { s[idx] = rand.Int() } var ( enc *gob.Encoder buf bytes.Buffer err error ) b.ResetTimer() b.StartTimer() for i := 0; i < b.N; i++ { enc = gob.NewEncoder(&buf) err = enc.Encode(s) if err != nil { panic(err.Error()) } //gobEncode(s) } }
func gobEncodeListNi(b *testing.B, l int) { s := make([]int, l) for idx, _ := range s { s[idx] = rand.Int() } var ( enc *gob.Encoder buf bytes.Buffer err error ) b.ResetTimer() for i := 0; i < b.N; i++ { enc = gob.NewEncoder(&buf) err = enc.Encode(s) if err != nil { panic(err.Error()) } } }