Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(680)

Delta Between Two Patch Sets: src/pkg/encoding/gob/encoder.go

Issue 12681044: code review 12681044: encoding/gob: support new generic interfaces in package... (Closed)
Left Patch Set: diff -r e052a6dba066 https://code.google.com/p/go/ Created 10 years, 7 months ago
Right Patch Set: diff -r 00b5a40ae411 https://code.google.com/p/go/ Created 10 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/encoding/gob/encode.go ('k') | src/pkg/encoding/gob/gobencdec_test.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package gob 5 package gob
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "errors" 9 "errors"
10 "io" 10 "io"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 case reflect.Map: 128 case reflect.Map:
129 enc.sendType(w, state, st.Key()) 129 enc.sendType(w, state, st.Key())
130 enc.sendType(w, state, st.Elem()) 130 enc.sendType(w, state, st.Elem())
131 } 131 }
132 return true 132 return true
133 } 133 }
134 134
135 // sendType sends the type info to the other side, if necessary. 135 // sendType sends the type info to the other side, if necessary.
136 func (enc *Encoder) sendType(w io.Writer, state *encoderState, origt reflect.Typ e) (sent bool) { 136 func (enc *Encoder) sendType(w io.Writer, state *encoderState, origt reflect.Typ e) (sent bool) {
137 ut := userType(origt) 137 ut := userType(origt)
138 » if ut.isGobEncoder || ut.isBinaryMarshaler || ut.isTextMarshaler { 138 » if ut.externalEnc != 0 {
139 // The rules are different: regardless of the underlying type's representation, 139 // The rules are different: regardless of the underlying type's representation,
140 // we need to tell the other side that the base type is a GobEnc oder. 140 // we need to tell the other side that the base type is a GobEnc oder.
141 return enc.sendActualType(w, state, ut, ut.base) 141 return enc.sendActualType(w, state, ut, ut.base)
142 } 142 }
143 143
144 // It's a concrete value, so drill down to the base type. 144 // It's a concrete value, so drill down to the base type.
145 switch rt := ut.base; rt.Kind() { 145 switch rt := ut.base; rt.Kind() {
146 default: 146 default:
147 // Basic types and interfaces do not need to be described. 147 // Basic types and interfaces do not need to be described.
148 return 148 return
(...skipping 28 matching lines...) Expand all
177 return enc.EncodeValue(reflect.ValueOf(e)) 177 return enc.EncodeValue(reflect.ValueOf(e))
178 } 178 }
179 179
180 // sendTypeDescriptor makes sure the remote side knows about this type. 180 // sendTypeDescriptor makes sure the remote side knows about this type.
181 // It will send a descriptor if this is the first time the type has been 181 // It will send a descriptor if this is the first time the type has been
182 // sent. 182 // sent.
183 func (enc *Encoder) sendTypeDescriptor(w io.Writer, state *encoderState, ut *use rTypeInfo) { 183 func (enc *Encoder) sendTypeDescriptor(w io.Writer, state *encoderState, ut *use rTypeInfo) {
184 // Make sure the type is known to the other side. 184 // Make sure the type is known to the other side.
185 // First, have we already sent this type? 185 // First, have we already sent this type?
186 rt := ut.base 186 rt := ut.base
187 » if ut.isGobEncoder || ut.isBinaryMarshaler || ut.isTextMarshaler { 187 » if ut.externalEnc != 0 {
188 rt = ut.user 188 rt = ut.user
189 } 189 }
190 if _, alreadySent := enc.sent[rt]; !alreadySent { 190 if _, alreadySent := enc.sent[rt]; !alreadySent {
191 // No, so send it. 191 // No, so send it.
192 sent := enc.sendType(w, state, rt) 192 sent := enc.sendType(w, state, rt)
193 if enc.err != nil { 193 if enc.err != nil {
194 return 194 return
195 } 195 }
196 // If the type info has still not been transmitted, it means we have 196 // If the type info has still not been transmitted, it means we have
197 // a singleton basic type (int, []byte etc.) at top level. We d on't 197 // a singleton basic type (int, []byte etc.) at top level. We d on't
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 250
251 // Encode the object. 251 // Encode the object.
252 enc.encode(state.b, value, ut) 252 enc.encode(state.b, value, ut)
253 if enc.err == nil { 253 if enc.err == nil {
254 enc.writeMessage(enc.writer(), state.b) 254 enc.writeMessage(enc.writer(), state.b)
255 } 255 }
256 256
257 enc.freeEncoderState(state) 257 enc.freeEncoderState(state)
258 return enc.err 258 return enc.err
259 } 259 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b