Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
aeb30d83
Commit
aeb30d83
authored
Sep 20, 2011
by
csharptest
Committed by
rogerk
Sep 20, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changes from review
parent
ef4af57b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
45 deletions
+69
-45
unittest_extras_xmltest.proto
protos/extest/unittest_extras_xmltest.proto
+21
-23
SerializableTest.cs
src/ProtocolBuffers.Test/SerializableTest.cs
+36
-12
CustomSerialization.cs
src/ProtocolBuffers/CustomSerialization.cs
+12
-10
No files found.
protos/extest/unittest_extras_xmltest.proto
View file @
aeb30d83
...
...
@@ -8,46 +8,44 @@ package protobuf_unittest_extra;
option
optimize_for
=
SPEED
;
enum
EnumOptions
{
ONE
=
0
;
TWO
=
1
;
THREE
=
2
;
ONE
=
0
;
TWO
=
1
;
THREE
=
2
;
}
message
TestXmlChild
{
repeated
EnumOptions
options
=
3
;
optional
bytes
binary
=
4
;
message
TestXmlChild
{
repeated
EnumOptions
options
=
3
;
optional
bytes
binary
=
4
;
}
message
TestXmlNoFields
{
}
message
TestXmlRescursive
{
optional
TestXmlRescursive
child
=
1
;
optional
TestXmlRescursive
child
=
1
;
}
message
TestXmlMessage
{
optional
int64
number
=
6
;
repeated
int32
numbers
=
2
;
optional
string
text
=
3
;
repeated
string
textlines
=
700
;
optional
bool
valid
=
5
;
optional
TestXmlChild
child
=
1
;
repeated
group
Children
=
401
{
repeated
EnumOptions
options
=
3
;
optional
bytes
binary
=
4
;
}
extensions
100
to
199
;
optional
int64
number
=
6
;
repeated
int32
numbers
=
2
;
optional
string
text
=
3
;
repeated
string
textlines
=
700
;
optional
bool
valid
=
5
;
optional
TestXmlChild
child
=
1
;
repeated
group
Children
=
401
{
repeated
EnumOptions
options
=
3
;
optional
bytes
binary
=
4
;
}
extensions
100
to
199
;
}
message
TestXmlExtension
{
required
int32
number
=
1
;
}
extend
TestXmlMessage
{
optional
EnumOptions
extension_enum
=
101
;
optional
string
extension_text
=
102
;
...
...
src/ProtocolBuffers.Test/SerializableTest.cs
View file @
aeb30d83
...
...
@@ -31,9 +31,15 @@ namespace Google.ProtocolBuffers
.
AddNumbers
(
1
)
.
AddNumbers
(
2
)
.
AddNumbers
(
3
)
.
SetChild
(
TestXmlChild
.
CreateBuilder
().
AddOptions
(
EnumOptions
.
ONE
).
SetBinary
(
ByteString
.
CopyFrom
(
new
byte
[
1
])))
.
AddChildren
(
TestXmlMessage
.
Types
.
Children
.
CreateBuilder
().
AddOptions
(
EnumOptions
.
TWO
).
SetBinary
(
ByteString
.
CopyFrom
(
new
byte
[
2
])))
.
AddChildren
(
TestXmlMessage
.
Types
.
Children
.
CreateBuilder
().
AddOptions
(
EnumOptions
.
THREE
).
SetBinary
(
ByteString
.
CopyFrom
(
new
byte
[
3
])))
.
SetChild
(
TestXmlChild
.
CreateBuilder
()
.
AddOptions
(
EnumOptions
.
ONE
)
.
SetBinary
(
ByteString
.
CopyFrom
(
new
byte
[
1
])))
.
AddChildren
(
TestXmlMessage
.
Types
.
Children
.
CreateBuilder
()
.
AddOptions
(
EnumOptions
.
TWO
)
.
SetBinary
(
ByteString
.
CopyFrom
(
new
byte
[
2
])))
.
AddChildren
(
TestXmlMessage
.
Types
.
Children
.
CreateBuilder
()
.
AddOptions
(
EnumOptions
.
THREE
)
.
SetBinary
(
ByteString
.
CopyFrom
(
new
byte
[
3
])))
.
Build
();
MemoryStream
ms
=
new
MemoryStream
();
...
...
@@ -58,9 +64,15 @@ namespace Google.ProtocolBuffers
.
AddNumbers
(
1
)
.
AddNumbers
(
2
)
.
AddNumbers
(
3
)
.
SetChild
(
TestXmlChild
.
CreateBuilder
().
AddOptions
(
EnumOptions
.
ONE
).
SetBinary
(
ByteString
.
CopyFrom
(
new
byte
[
1
])))
.
AddChildren
(
TestXmlMessage
.
Types
.
Children
.
CreateBuilder
().
AddOptions
(
EnumOptions
.
TWO
).
SetBinary
(
ByteString
.
CopyFrom
(
new
byte
[
2
])))
.
AddChildren
(
TestXmlMessage
.
Types
.
Children
.
CreateBuilder
().
AddOptions
(
EnumOptions
.
THREE
).
SetBinary
(
ByteString
.
CopyFrom
(
new
byte
[
3
])))
.
SetChild
(
TestXmlChild
.
CreateBuilder
()
.
AddOptions
(
EnumOptions
.
ONE
)
.
SetBinary
(
ByteString
.
CopyFrom
(
new
byte
[
1
])))
.
AddChildren
(
TestXmlMessage
.
Types
.
Children
.
CreateBuilder
()
.
AddOptions
(
EnumOptions
.
TWO
)
.
SetBinary
(
ByteString
.
CopyFrom
(
new
byte
[
2
])))
.
AddChildren
(
TestXmlMessage
.
Types
.
Children
.
CreateBuilder
()
.
AddOptions
(
EnumOptions
.
THREE
)
.
SetBinary
(
ByteString
.
CopyFrom
(
new
byte
[
3
])))
.
SetExtension
(
UnitTestXmlSerializerTestProtoFile
.
ExtensionText
,
" extension text value ! "
)
.
SetExtension
(
UnitTestXmlSerializerTestProtoFile
.
ExtensionMessage
,
new
TestXmlExtension
.
Builder
().
SetNumber
(
42
).
Build
())
.
AddExtension
(
UnitTestXmlSerializerTestProtoFile
.
ExtensionNumber
,
100
)
...
...
@@ -97,9 +109,15 @@ namespace Google.ProtocolBuffers
.
AddNumbers
(
1
)
.
AddNumbers
(
2
)
.
AddNumbers
(
3
)
.
SetChild
(
TestXmlChild
.
CreateBuilder
().
AddOptions
(
EnumOptions
.
ONE
).
SetBinary
(
ByteString
.
CopyFrom
(
new
byte
[
1
])))
.
AddChildren
(
TestXmlMessage
.
Types
.
Children
.
CreateBuilder
().
AddOptions
(
EnumOptions
.
TWO
).
SetBinary
(
ByteString
.
CopyFrom
(
new
byte
[
2
])))
.
AddChildren
(
TestXmlMessage
.
Types
.
Children
.
CreateBuilder
().
AddOptions
(
EnumOptions
.
THREE
).
SetBinary
(
ByteString
.
CopyFrom
(
new
byte
[
3
])))
.
SetChild
(
TestXmlChild
.
CreateBuilder
()
.
AddOptions
(
EnumOptions
.
ONE
)
.
SetBinary
(
ByteString
.
CopyFrom
(
new
byte
[
1
])))
.
AddChildren
(
TestXmlMessage
.
Types
.
Children
.
CreateBuilder
()
.
AddOptions
(
EnumOptions
.
TWO
)
.
SetBinary
(
ByteString
.
CopyFrom
(
new
byte
[
2
])))
.
AddChildren
(
TestXmlMessage
.
Types
.
Children
.
CreateBuilder
()
.
AddOptions
(
EnumOptions
.
THREE
)
.
SetBinary
(
ByteString
.
CopyFrom
(
new
byte
[
3
])))
;
MemoryStream
ms
=
new
MemoryStream
();
...
...
@@ -124,9 +142,15 @@ namespace Google.ProtocolBuffers
.
AddNumbers
(
1
)
.
AddNumbers
(
2
)
.
AddNumbers
(
3
)
.
SetChild
(
TestXmlChild
.
CreateBuilder
().
AddOptions
(
EnumOptions
.
ONE
).
SetBinary
(
ByteString
.
CopyFrom
(
new
byte
[
1
])))
.
AddChildren
(
TestXmlMessage
.
Types
.
Children
.
CreateBuilder
().
AddOptions
(
EnumOptions
.
TWO
).
SetBinary
(
ByteString
.
CopyFrom
(
new
byte
[
2
])))
.
AddChildren
(
TestXmlMessage
.
Types
.
Children
.
CreateBuilder
().
AddOptions
(
EnumOptions
.
THREE
).
SetBinary
(
ByteString
.
CopyFrom
(
new
byte
[
3
])))
.
SetChild
(
TestXmlChild
.
CreateBuilder
()
.
AddOptions
(
EnumOptions
.
ONE
)
.
SetBinary
(
ByteString
.
CopyFrom
(
new
byte
[
1
])))
.
AddChildren
(
TestXmlMessage
.
Types
.
Children
.
CreateBuilder
()
.
AddOptions
(
EnumOptions
.
TWO
)
.
SetBinary
(
ByteString
.
CopyFrom
(
new
byte
[
2
])))
.
AddChildren
(
TestXmlMessage
.
Types
.
Children
.
CreateBuilder
()
.
AddOptions
(
EnumOptions
.
THREE
)
.
SetBinary
(
ByteString
.
CopyFrom
(
new
byte
[
3
])))
.
SetExtension
(
UnitTestXmlSerializerTestProtoFile
.
ExtensionText
,
" extension text value ! "
)
.
SetExtension
(
UnitTestXmlSerializerTestProtoFile
.
ExtensionMessage
,
new
TestXmlExtension
.
Builder
().
SetNumber
(
42
).
Build
())
.
AddExtension
(
UnitTestXmlSerializerTestProtoFile
.
ExtensionNumber
,
100
)
...
...
src/ProtocolBuffers/CustomSerialization.cs
View file @
aeb30d83
...
...
@@ -45,7 +45,7 @@ namespace Google.ProtocolBuffers
{
/*
* Specialized handing of *all* message types. Messages are serialized into a byte[] and stored
* into the SerializationInfo,
they are then reconstitud
ed by an IObjectReference class after
* into the SerializationInfo,
and are then reconstitut
ed by an IObjectReference class after
* deserialization. IDeserializationCallback is supported on both the Builder and Message.
*/
[
Serializable
]
...
...
@@ -71,22 +71,23 @@ namespace Google.ProtocolBuffers
_initialized
=
info
.
GetBoolean
(
"initialized"
);
}
O
bject
IObjectReference
.
GetRealObject
(
StreamingContext
context
)
o
bject
IObjectReference
.
GetRealObject
(
StreamingContext
context
)
{
ExtensionRegistry
registry
=
context
.
Context
as
ExtensionRegistry
;
TBuilder
builder
=
TemplateInstance
.
DefaultInstanceForType
.
CreateBuilderForType
();
builder
.
MergeFrom
(
_message
,
registry
??
ExtensionRegistry
.
Empty
);
if
(
builder
is
IDeserializationCallback
)
IDeserializationCallback
callback
=
builder
as
IDeserializationCallback
;
if
(
callback
!=
null
)
{
((
IDeserializationCallback
)
builder
)
.
OnDeserialization
(
context
);
callback
.
OnDeserialization
(
context
);
}
TMessage
message
=
_initialized
?
builder
.
Build
()
:
builder
.
BuildPartial
();
if
(
message
is
IDeserializationCallback
)
callback
=
message
as
IDeserializationCallback
;
if
(
callback
!=
null
)
{
((
IDeserializationCallback
)
message
)
.
OnDeserialization
(
context
);
callback
.
OnDeserialization
(
context
);
}
return
message
;
...
...
@@ -119,15 +120,16 @@ namespace Google.ProtocolBuffers
_message
=
(
byte
[])
info
.
GetValue
(
"message"
,
typeof
(
byte
[]));
}
O
bject
IObjectReference
.
GetRealObject
(
StreamingContext
context
)
o
bject
IObjectReference
.
GetRealObject
(
StreamingContext
context
)
{
ExtensionRegistry
registry
=
context
.
Context
as
ExtensionRegistry
;
TBuilder
builder
=
TemplateInstance
.
DefaultInstanceForType
.
CreateBuilderForType
();
builder
.
MergeFrom
(
_message
,
registry
??
ExtensionRegistry
.
Empty
);
if
(
builder
is
IDeserializationCallback
)
IDeserializationCallback
callback
=
builder
as
IDeserializationCallback
;
if
(
callback
!=
null
)
{
((
IDeserializationCallback
)
builder
)
.
OnDeserialization
(
context
);
callback
.
OnDeserialization
(
context
);
}
return
builder
;
...
...
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