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
819b7154
Commit
819b7154
authored
Sep 09, 2011
by
csharptest
Committed by
rogerk
Sep 09, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added IDisposable to ICodedOutputStream
parent
c2d2c1ad
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
59 additions
and
5 deletions
+59
-5
MessageFormatFactory.cs
...rotocolBuffers.Serialization/Http/MessageFormatFactory.cs
+20
-3
JsonFormatWriter.cs
src/ProtocolBuffers.Serialization/JsonFormatWriter.cs
+13
-0
XmlFormatWriter.cs
src/ProtocolBuffers.Serialization/XmlFormatWriter.cs
+14
-0
CodedOutputStream.cs
src/ProtocolBuffers/CodedOutputStream.cs
+11
-1
ICodedOutputStream.cs
src/ProtocolBuffers/ICodedOutputStream.cs
+1
-1
No files found.
src/ProtocolBuffers.Serialization/Http/MessageFormatFactory.cs
View file @
819b7154
...
...
@@ -62,11 +62,11 @@ namespace Google.ProtocolBuffers.Serialization
/// <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
)
/// <remarks> If you do not dispose of ICodedOutputStream some formats may yield incomplete output </remarks>
public
static
ICodedOutputStream
CreateOutputStream
(
MessageFormatOptions
options
,
string
contentType
,
Stream
output
)
{
FormatType
outputType
=
ContentTypeToFormat
(
contentType
,
options
.
DefaultContentType
);
...
...
@@ -114,13 +114,30 @@ namespace Google.ProtocolBuffers.Serialization
else
throw
new
NotSupportedException
();
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
)
{
using
(
ICodedOutputStream
codedOutput
=
CreateOutputStream
(
options
,
contentType
,
output
))
{
message
.
WriteTo
(
codedOutput
);
// This is effectivly done by Dispose(); however, if you need to finalize a message
// without disposing the underlying stream, this is the only way to do it.
if
(
codedOutput
is
AbstractWriter
)
((
AbstractWriter
)
codedOutput
).
EndMessage
();
((
AbstractWriter
)
codedOutput
).
EndMessage
();
codedOutput
.
Flush
();
}
}
enum
FormatType
{
ProtoBuffer
,
Json
,
Xml
};
...
...
src/ProtocolBuffers.Serialization/JsonFormatWriter.cs
View file @
819b7154
...
...
@@ -239,6 +239,19 @@ namespace Google.ProtocolBuffers.Serialization
/// <summary> Gets or sets the whitespace to use to separate the text, default = empty </summary>
public
string
Whitespace
{
get
;
set
;
}
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
protected
override
void
Dispose
(
bool
disposing
)
{
if
(
disposing
&&
_counter
.
Count
==
1
)
{
EndMessage
();
}
base
.
Dispose
(
disposing
);
}
private
void
Seperator
()
{
if
(
_counter
.
Count
==
0
)
...
...
src/ProtocolBuffers.Serialization/XmlFormatWriter.cs
View file @
819b7154
...
...
@@ -75,8 +75,13 @@ namespace Google.ProtocolBuffers.Serialization
{
if
(
disposing
)
{
if
(
_output
.
WriteState
!=
WriteState
.
Closed
&&
_output
.
WriteState
!=
WriteState
.
Start
)
_output
.
WriteEndDocument
();
_output
.
Close
();
}
base
.
Dispose
(
disposing
);
}
/// <summary>
...
...
@@ -111,6 +116,15 @@ namespace Google.ProtocolBuffers.Serialization
return
(
Options
&
option
)
!=
0
;
}
/// <summary>
/// Completes any pending write operations
/// </summary>
public
override
void
Flush
()
{
_output
.
Flush
();
base
.
Flush
();
}
/// <summary>
/// Used to write the root-message preamble, in xml this is open element for RootElementName,
/// by default "<root>". After this call you can call IMessageLite.MergeTo(...) and
...
...
src/ProtocolBuffers/CodedOutputStream.cs
View file @
819b7154
...
...
@@ -57,7 +57,7 @@ namespace Google.ProtocolBuffers
/// methods are taken from the protocol buffer type names, not .NET types.
/// (Hence WriteFloat instead of WriteSingle, and WriteBool instead of WriteBoolean.)
/// </remarks>
public
sealed
partial
class
CodedOutputStream
:
ICodedOutputStream
public
sealed
partial
class
CodedOutputStream
:
ICodedOutputStream
,
IDisposable
{
/// <summary>
/// The buffer size used by CreateInstance(Stream).
...
...
@@ -126,6 +126,16 @@ namespace Google.ProtocolBuffers
#
endregion
public
void
Dispose
()
{
if
(
output
!=
null
)
{
if
(
position
>
0
)
Flush
();
output
.
Dispose
();
}
}
#
region
Writing
of
unknown
fields
[
Obsolete
]
...
...
src/ProtocolBuffers/ICodedOutputStream.cs
View file @
819b7154
...
...
@@ -49,7 +49,7 @@ namespace Google.ProtocolBuffers
/// in their binary form by creating a instance via the CodedOutputStream.CreateInstance
/// static factory.
/// </summary>
public
interface
ICodedOutputStream
public
interface
ICodedOutputStream
:
IDisposable
{
/// <summary>
/// Indicates that all temporary buffers be written to the final output.
...
...
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