Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
da69685e
Commit
da69685e
authored
Jun 29, 2010
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gob: a couple of tiny simplifications using Kind()
R=rsc CC=golang-dev
https://golang.org/cl/1695046
parent
059c7ba9
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
12 deletions
+26
-12
decoder.go
src/pkg/gob/decoder.go
+6
-5
encode.go
src/pkg/gob/encode.go
+19
-6
type.go
src/pkg/gob/type.go
+1
-1
No files found.
src/pkg/gob/decoder.go
View file @
da69685e
...
...
@@ -55,15 +55,16 @@ func (dec *Decoder) recvType(id typeId) {
// Decode reads the next value from the connection and stores
// it in the data represented by the empty interface value.
// The value underlying e must be the correct type for the next
// data item received,
which
must be a pointer.
// data item received,
and
must be a pointer.
func
(
dec
*
Decoder
)
Decode
(
e
interface
{})
os
.
Error
{
// If e represents a value, the answer won't get back to the
// caller. Make sure it's a pointer.
if
_
,
ok
:=
reflect
.
Typeof
(
e
)
.
(
*
reflect
.
PtrType
);
!
ok
{
value
:=
reflect
.
NewValue
(
e
)
// If e represents a value as opposed to a pointer, the answer won't
// get back to the caller. Make sure it's a pointer.
if
value
.
Type
()
.
Kind
()
!=
reflect
.
Ptr
{
dec
.
state
.
err
=
os
.
ErrorString
(
"gob: attempt to decode into a non-pointer"
)
return
dec
.
state
.
err
}
return
dec
.
DecodeValue
(
reflect
.
NewValue
(
e
)
)
return
dec
.
DecodeValue
(
value
)
}
// DecodeValue reads the next value from the connection and stores
...
...
src/pkg/gob/encode.go
View file @
da69685e
...
...
@@ -15,11 +15,10 @@
recursive values (data with cycles) are problematic. This may change.
To use gobs, create an Encoder and present it with a series of data items as
values or addresses that can be dereferenced to values. (At the moment, these
items must be structs (struct, *struct, **struct etc.), but this may change.) The
Encoder makes sure all type information is sent before it is needed. At the
receive side, a Decoder retrieves values from the encoded stream and unpacks them
into local variables.
values or addresses that can be dereferenced to values. The Encoder makes sure
all type information is sent before it is needed. At the receive side, a
Decoder retrieves values from the encoded stream and unpacks them into local
variables.
The source and destination values/types need not correspond exactly. For structs,
fields (identified by name) that are in the source but absent from the receiving
...
...
@@ -251,6 +250,20 @@ package gob
output will be just:
07 ff 82 01 2c 01 42 00
A single non-struct value at top level is transmitted like a field with
delta tag 0. For instance, a signed integer with value 3 presented as
the argument to Encode will emit:
03 04 00 06
Which represents:
03 // this value is 3 bytes long
04 // the type number, 2, represents an integer
00 // tag delta 0
06 // value 3
*/
import
(
...
...
@@ -810,7 +823,7 @@ func encode(b *bytes.Buffer, value reflect.Value) os.Error {
if
err
!=
nil
{
return
err
}
if
_
,
ok
:=
value
.
(
*
reflect
.
StructValue
);
ok
{
if
value
.
Type
()
.
Kind
()
==
reflect
.
Struct
{
return
encodeStruct
(
engine
,
b
,
value
.
Addr
())
}
return
encodeSingle
(
engine
,
b
,
value
.
Addr
())
...
...
src/pkg/gob/type.go
View file @
da69685e
...
...
@@ -395,7 +395,7 @@ var typeInfoMap = make(map[reflect.Type]*typeInfo) // protected by typeLock
// The reflection type must have all its indirections processed out.
// typeLock must be held.
func
getTypeInfo
(
rt
reflect
.
Type
)
(
*
typeInfo
,
os
.
Error
)
{
if
_
,
ok
:=
rt
.
(
*
reflect
.
PtrType
);
ok
{
if
rt
.
Kind
()
==
reflect
.
Ptr
{
panic
(
"pointer type in getTypeInfo: "
+
rt
.
String
())
}
info
,
ok
:=
typeInfoMap
[
rt
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment