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
4ad55269
Commit
4ad55269
authored
Oct 01, 2011
by
csharptest
Committed by
rogerk
Oct 01, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved all extension methods to a single class/file
parent
adfdc008
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
65 additions
and
76 deletions
+65
-76
Extensions.cs
src/ProtocolBuffers.Serialization/Extensions.cs
+65
-0
MessageFormatFactory.cs
...rotocolBuffers.Serialization/Http/MessageFormatFactory.cs
+0
-40
ServiceExtensions.cs
src/ProtocolBuffers.Serialization/Http/ServiceExtensions.cs
+0
-34
ProtocolBuffers.Serialization.csproj
...uffers.Serialization/ProtocolBuffers.Serialization.csproj
+0
-1
ProtocolBuffersLite.Serialization.csproj
...rs.Serialization/ProtocolBuffersLite.Serialization.csproj
+0
-1
No files found.
src/ProtocolBuffers.Serialization/Extensions.cs
View file @
4ad55269
...
@@ -3,6 +3,7 @@ using System.Text;
...
@@ -3,6 +3,7 @@ using System.Text;
using
System.IO
;
using
System.IO
;
using
System.Xml
;
using
System.Xml
;
using
Google.ProtocolBuffers.Serialization
;
using
Google.ProtocolBuffers.Serialization
;
using
Google.ProtocolBuffers.Serialization.Http
;
namespace
Google.ProtocolBuffers
namespace
Google.ProtocolBuffers
{
{
...
@@ -43,6 +44,28 @@ namespace Google.ProtocolBuffers
...
@@ -43,6 +44,28 @@ namespace Google.ProtocolBuffers
return
w
.
ToString
();
return
w
.
ToString
();
}
}
/// <summary>
/// Writes the message instance to the stream using the content type provided
/// </summary>
/// <param name="message">An instance of a message</param>
/// <param name="options">Options specific to writing this message and/or content type</param>
/// <param name="contentType">The mime type of the content to be written</param>
/// <param name="output">The stream to write the message to</param>
public
static
void
WriteTo
(
this
IMessageLite
message
,
MessageFormatOptions
options
,
string
contentType
,
Stream
output
)
{
ICodedOutputStream
codedOutput
=
MessageFormatFactory
.
CreateOutputStream
(
options
,
contentType
,
output
);
// Output the appropriate message preamble
codedOutput
.
WriteMessageStart
();
// Write the message content to the output
message
.
WriteTo
(
codedOutput
);
// Write the closing message fragment
codedOutput
.
WriteMessageEnd
();
codedOutput
.
Flush
();
}
#
endregion
#
endregion
#
region
IBuilderLite
Extensions
#
region
IBuilderLite
Extensions
/// <summary>
/// <summary>
...
@@ -95,6 +118,48 @@ namespace Google.ProtocolBuffers
...
@@ -95,6 +118,48 @@ namespace Google.ProtocolBuffers
.
Merge
(
rootElementName
,
builder
,
extensionRegistry
);
.
Merge
(
rootElementName
,
builder
,
extensionRegistry
);
}
}
/// <summary>
/// Merges the message from the input stream based on the contentType provided
/// </summary>
/// <typeparam name="TBuilder">A type derived from IBuilderLite</typeparam>
/// <param name="builder">An instance of a message builder</param>
/// <param name="options">Options specific to reading this message and/or content type</param>
/// <param name="contentType">The mime type of the input stream content</param>
/// <param name="input">The stream to read the message from</param>
/// <returns>The same builder instance that was supplied in the builder parameter</returns>
public
static
TBuilder
MergeFrom
<
TBuilder
>(
this
TBuilder
builder
,
MessageFormatOptions
options
,
string
contentType
,
Stream
input
)
where
TBuilder
:
IBuilderLite
{
ICodedInputStream
codedInput
=
MessageFormatFactory
.
CreateInputStream
(
options
,
contentType
,
input
);
codedInput
.
ReadMessageStart
();
builder
.
WeakMergeFrom
(
codedInput
,
options
.
ExtensionRegistry
);
codedInput
.
ReadMessageEnd
();
return
builder
;
}
#
endregion
#
region
IRpcServerStub
Extensions
/// <summary>
/// Used to implement a service endpoint on an HTTP server. This works with services generated with the
/// service_generator_type option set to IRPCDISPATCH.
/// </summary>
/// <param name="stub">The service execution stub</param>
/// <param name="methodName">The name of the method being invoked</param>
/// <param name="options">optional arguments for the format reader/writer</param>
/// <param name="contentType">The mime type for the input stream</param>
/// <param name="input">The input stream</param>
/// <param name="responseType">The mime type for the output stream</param>
/// <param name="output">The output stream</param>
public
static
void
HttpCallMethod
(
this
IRpcServerStub
stub
,
string
methodName
,
MessageFormatOptions
options
,
string
contentType
,
Stream
input
,
string
responseType
,
Stream
output
)
{
ICodedInputStream
codedInput
=
MessageFormatFactory
.
CreateInputStream
(
options
,
contentType
,
input
);
codedInput
.
ReadMessageStart
();
IMessageLite
response
=
stub
.
CallMethod
(
methodName
,
codedInput
,
options
.
ExtensionRegistry
);
codedInput
.
ReadMessageEnd
();
response
.
WriteTo
(
options
,
responseType
,
output
);
}
#
endregion
#
endregion
}
}
}
}
src/ProtocolBuffers.Serialization/Http/MessageFormatFactory.cs
View file @
4ad55269
...
@@ -31,24 +31,6 @@ namespace Google.ProtocolBuffers.Serialization.Http
...
@@ -31,24 +31,6 @@ namespace Google.ProtocolBuffers.Serialization.Http
return
codedInput
;
return
codedInput
;
}
}
/// <summary>
/// Merges the message from the input stream based on the contentType provided
/// </summary>
/// <typeparam name="TBuilder">A type derived from IBuilderLite</typeparam>
/// <param name="builder">An instance of a message builder</param>
/// <param name="options">Options specific to reading this message and/or content type</param>
/// <param name="contentType">The mime type of the input stream content</param>
/// <param name="input">The stream to read the message from</param>
/// <returns>The same builder instance that was supplied in the builder parameter</returns>
public
static
TBuilder
MergeFrom
<
TBuilder
>(
this
TBuilder
builder
,
MessageFormatOptions
options
,
string
contentType
,
Stream
input
)
where
TBuilder
:
IBuilderLite
{
ICodedInputStream
codedInput
=
CreateInputStream
(
options
,
contentType
,
input
);
codedInput
.
ReadMessageStart
();
builder
.
WeakMergeFrom
(
codedInput
,
options
.
ExtensionRegistry
);
codedInput
.
ReadMessageEnd
();
return
builder
;
}
/// <summary>
/// <summary>
/// Writes the message instance to the stream using the content type provided
/// Writes the message instance to the stream using the content type provided
/// </summary>
/// </summary>
...
@@ -93,28 +75,6 @@ namespace Google.ProtocolBuffers.Serialization.Http
...
@@ -93,28 +75,6 @@ namespace Google.ProtocolBuffers.Serialization.Http
return
codedOutput
;
return
codedOutput
;
}
}
/// <summary>
/// Writes the message instance to the stream using the content type provided
/// </summary>
/// <param name="message">An instance of a message</param>
/// <param name="options">Options specific to writing this message and/or content type</param>
/// <param name="contentType">The mime type of the content to be written</param>
/// <param name="output">The stream to write the message to</param>
public
static
void
WriteTo
(
this
IMessageLite
message
,
MessageFormatOptions
options
,
string
contentType
,
Stream
output
)
{
ICodedOutputStream
codedOutput
=
CreateOutputStream
(
options
,
contentType
,
output
);
// Output the appropriate message preamble
codedOutput
.
WriteMessageStart
();
// Write the message content to the output
message
.
WriteTo
(
codedOutput
);
// Write the closing message fragment
codedOutput
.
WriteMessageEnd
();
codedOutput
.
Flush
();
}
private
static
ICodedInputStream
ContentTypeToInputStream
(
string
contentType
,
MessageFormatOptions
options
,
Stream
input
)
private
static
ICodedInputStream
ContentTypeToInputStream
(
string
contentType
,
MessageFormatOptions
options
,
Stream
input
)
{
{
contentType
=
(
contentType
??
String
.
Empty
).
Split
(
';'
)[
0
].
Trim
();
contentType
=
(
contentType
??
String
.
Empty
).
Split
(
';'
)[
0
].
Trim
();
...
...
src/ProtocolBuffers.Serialization/Http/ServiceExtensions.cs
deleted
100644 → 0
View file @
adfdc008
using
System.Collections.Generic
;
using
System.Text
;
using
Google.ProtocolBuffers
;
using
System.IO
;
namespace
Google.ProtocolBuffers.Serialization.Http
{
/// <summary>
/// Extensions for the IRpcServerStub
/// </summary>
public
static
class
ServiceExtensions
{
/// <summary>
/// Used to implement a service endpoint on an HTTP server. This works with services generated with the
/// service_generator_type option set to IRPCDISPATCH.
/// </summary>
/// <param name="stub">The service execution stub</param>
/// <param name="methodName">The name of the method being invoked</param>
/// <param name="options">optional arguments for the format reader/writer</param>
/// <param name="contentType">The mime type for the input stream</param>
/// <param name="input">The input stream</param>
/// <param name="responseType">The mime type for the output stream</param>
/// <param name="output">The output stream</param>
public
static
void
HttpCallMethod
(
this
IRpcServerStub
stub
,
string
methodName
,
MessageFormatOptions
options
,
string
contentType
,
Stream
input
,
string
responseType
,
Stream
output
)
{
ICodedInputStream
codedInput
=
MessageFormatFactory
.
CreateInputStream
(
options
,
contentType
,
input
);
codedInput
.
ReadMessageStart
();
IMessageLite
response
=
stub
.
CallMethod
(
methodName
,
codedInput
,
options
.
ExtensionRegistry
);
codedInput
.
ReadMessageEnd
();
response
.
WriteTo
(
options
,
responseType
,
output
);
}
}
}
src/ProtocolBuffers.Serialization/ProtocolBuffers.Serialization.csproj
View file @
4ad55269
...
@@ -101,7 +101,6 @@
...
@@ -101,7 +101,6 @@
<Compile
Include=
"Http\FormUrlEncodedReader.cs"
/>
<Compile
Include=
"Http\FormUrlEncodedReader.cs"
/>
<Compile
Include=
"Http\MessageFormatFactory.cs"
/>
<Compile
Include=
"Http\MessageFormatFactory.cs"
/>
<Compile
Include=
"Http\MessageFormatOptions.cs"
/>
<Compile
Include=
"Http\MessageFormatOptions.cs"
/>
<Compile
Include=
"Http\ServiceExtensions.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"AbstractReader.cs"
/>
<Compile
Include=
"AbstractReader.cs"
/>
<Compile
Include=
"AbstractTextReader.cs"
/>
<Compile
Include=
"AbstractTextReader.cs"
/>
...
...
src/ProtocolBuffers.Serialization/ProtocolBuffersLite.Serialization.csproj
View file @
4ad55269
...
@@ -101,7 +101,6 @@
...
@@ -101,7 +101,6 @@
<Compile
Include=
"Http\FormUrlEncodedReader.cs"
/>
<Compile
Include=
"Http\FormUrlEncodedReader.cs"
/>
<Compile
Include=
"Http\MessageFormatFactory.cs"
/>
<Compile
Include=
"Http\MessageFormatFactory.cs"
/>
<Compile
Include=
"Http\MessageFormatOptions.cs"
/>
<Compile
Include=
"Http\MessageFormatOptions.cs"
/>
<Compile
Include=
"Http\ServiceExtensions.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"AbstractReader.cs"
/>
<Compile
Include=
"AbstractReader.cs"
/>
<Compile
Include=
"AbstractTextReader.cs"
/>
<Compile
Include=
"AbstractTextReader.cs"
/>
...
...
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