~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/pkg/gob/encode.go

  • Committer: Bazaar Package Importer
  • Author(s): Ondřej Surý
  • Date: 2011-08-03 17:04:59 UTC
  • mfrom: (14.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20110803170459-wzd99m3567y80ila
Tags: 1:59-1
* Imported Upstream version 59
* Refresh patches to a new release
* Fix FTBFS on ARM (Closes: #634270)
* Update version.bash to work with Debian packaging and not hg
  repository

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
        "unsafe"
12
12
)
13
13
 
14
 
const uint64Size = unsafe.Sizeof(uint64(0))
 
14
const uint64Size = int(unsafe.Sizeof(uint64(0)))
15
15
 
16
16
// encoderState is the global execution state of an instance of the encoder.
17
17
// Field numbers are delta encoded and always increase. The field
468
468
 
469
469
// encGobEncoder encodes a value that implements the GobEncoder interface.
470
470
// The data is sent as a byte array.
471
 
func (enc *Encoder) encodeGobEncoder(b *bytes.Buffer, v reflect.Value, index int) {
 
471
func (enc *Encoder) encodeGobEncoder(b *bytes.Buffer, v reflect.Value) {
472
472
        // TODO: should we catch panics from the called method?
473
473
        // We know it's a GobEncoder, so just call the method directly.
474
474
        data, err := v.Interface().(GobEncoder).GobEncode()
592
592
        return &op, indir
593
593
}
594
594
 
595
 
// methodIndex returns which method of rt implements the method.
596
 
func methodIndex(rt reflect.Type, method string) int {
597
 
        for i := 0; i < rt.NumMethod(); i++ {
598
 
                if rt.Method(i).Name == method {
599
 
                        return i
600
 
                }
601
 
        }
602
 
        errorf("internal error: can't find method %s", method)
603
 
        return 0
604
 
}
605
 
 
606
595
// gobEncodeOpFor returns the op for a type that is known to implement
607
596
// GobEncoder.
608
597
func (enc *Encoder) gobEncodeOpFor(ut *userTypeInfo) (*encOp, int) {
624
613
                        v = reflect.ValueOf(unsafe.Unreflect(rt, p))
625
614
                }
626
615
                state.update(i)
627
 
                state.enc.encodeGobEncoder(state.b, v, methodIndex(rt, gobEncodeMethodName))
 
616
                state.enc.encodeGobEncoder(state.b, v)
628
617
        }
629
618
        return &op, int(ut.encIndir) // encIndir: op will get called with p == address of receiver.
630
619
}