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
d6405f83
Commit
d6405f83
authored
May 20, 2011
by
csharptest
Committed by
rogerk
May 20, 2011
Browse files
Options
Browse Files
Download
Plain Diff
merged from protobuf-csharp-port
parents
157979e1
ba63ad2b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
142 additions
and
94 deletions
+142
-94
AddressBook.csproj
src/AddressBook/AddressBook.csproj
+98
-94
SampleUsage.cs
src/AddressBook/SampleUsage.cs
+44
-0
No files found.
src/AddressBook/AddressBook.csproj
View file @
d6405f83
<?xml version="1.0" encoding="utf-8"?>
<Project
ToolsVersion=
"4.0"
DefaultTargets=
"Build"
xmlns=
"http://schemas.microsoft.com/developer/msbuild/2003"
>
<PropertyGroup>
<Configuration
Condition=
" '$(Configuration)' == '' "
>
Debug
</Configuration>
<Platform
Condition=
" '$(Platform)' == '' "
>
AnyCPU
</Platform>
<ProductVersion>
9.0.30729
</ProductVersion>
<SchemaVersion>
2.0
</SchemaVersion>
<ProjectGuid>
{A31F5FB2-4FF3-432A-B35B-5CD203606311}
</ProjectGuid>
<OutputType>
Exe
</OutputType>
<AppDesignerFolder>
Properties
</AppDesignerFolder>
<RootNamespace>
Google.ProtocolBuffers.Examples.AddressBook
</RootNamespace>
<AssemblyName>
AddressBook
</AssemblyName>
<TargetFrameworkVersion>
v2.0
</TargetFrameworkVersion>
<FileAlignment>
512
</FileAlignment>
<StartupObject>
Google.ProtocolBuffers.Examples.AddressBook.Program
</StartupObject>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>
3.5
</OldToolsVersion>
<PublishUrl>
publish\
</PublishUrl>
<Install>
true
</Install>
<InstallFrom>
Disk
</InstallFrom>
<UpdateEnabled>
false
</UpdateEnabled>
<UpdateMode>
Foreground
</UpdateMode>
<UpdateInterval>
7
</UpdateInterval>
<UpdateIntervalUnits>
Days
</UpdateIntervalUnits>
<UpdatePeriodically>
false
</UpdatePeriodically>
<UpdateRequired>
false
</UpdateRequired>
<MapFileExtensions>
true
</MapFileExtensions>
<ApplicationRevision>
0
</ApplicationRevision>
<ApplicationVersion>
1.0.0.%2a
</ApplicationVersion>
<IsWebBootstrapper>
false
</IsWebBootstrapper>
<UseApplicationTrust>
false
</UseApplicationTrust>
<BootstrapperEnabled>
true
</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "
>
<DebugSymbols>
true
</DebugSymbols>
<DebugType>
full
</DebugType>
<Optimize>
false
</Optimize>
<OutputPath>
bin\Debug\
</OutputPath>
<DefineConstants>
DEBUG;TRACE
</DefineConstants>
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
<CodeAnalysisRuleSet>
AllRules.ruleset
</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "
>
<DebugType>
pdbonly
</DebugType>
<Optimize>
true
</Optimize>
<OutputPath>
bin\Release\
</OutputPath>
<DefineConstants>
TRACE
</DefineConstants>
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
<CodeAnalysisRuleSet>
AllRules.ruleset
</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference
Include=
"mscorlib"
/>
<Reference
Include=
"System"
/>
</ItemGroup>
<ItemGroup>
<Compile
Include=
"AddPerson.cs"
/>
<Compile
Include=
"AddressBookProtos.cs"
/>
<Compile
Include=
"ListPeople.cs"
/>
<Compile
Include=
"Program.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
</ItemGroup>
<ItemGroup>
<ProjectReference
Include=
"..\ProtocolBuffers\ProtocolBuffers.csproj"
>
<Project>
{6908BDCE-D925-43F3-94AC-A531E6DF2591}
</Project>
<Name>
ProtocolBuffers
</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None
Include=
"app.config"
/>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage
Include=
"Microsoft.Net.Client.3.5"
>
<Visible>
False
</Visible>
<ProductName>
.NET Framework 3.5 SP1 Client Profile
</ProductName>
<Install>
false
</Install>
</BootstrapperPackage>
<BootstrapperPackage
Include=
"Microsoft.Net.Framework.3.5.SP1"
>
<Visible>
False
</Visible>
<ProductName>
.NET Framework 3.5 SP1
</ProductName>
<Install>
true
</Install>
</BootstrapperPackage>
<BootstrapperPackage
Include=
"Microsoft.Windows.Installer.3.1"
>
<Visible>
False
</Visible>
<ProductName>
Windows Installer 3.1
</ProductName>
<Install>
true
</Install>
</BootstrapperPackage>
</ItemGroup>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSharp.targets"
/>
<?xml version="1.0" encoding="utf-8"?>
<Project
ToolsVersion=
"4.0"
DefaultTargets=
"Build"
xmlns=
"http://schemas.microsoft.com/developer/msbuild/2003"
>
<PropertyGroup>
<Configuration
Condition=
" '$(Configuration)' == '' "
>
Debug
</Configuration>
<Platform
Condition=
" '$(Platform)' == '' "
>
AnyCPU
</Platform>
<ProductVersion>
9.0.30729
</ProductVersion>
<SchemaVersion>
2.0
</SchemaVersion>
<ProjectGuid>
{A31F5FB2-4FF3-432A-B35B-5CD203606311}
</ProjectGuid>
<OutputType>
Exe
</OutputType>
<AppDesignerFolder>
Properties
</AppDesignerFolder>
<RootNamespace>
Google.ProtocolBuffers.Examples.AddressBook
</RootNamespace>
<AssemblyName>
AddressBook
</AssemblyName>
<TargetFrameworkVersion>
v2.0
</TargetFrameworkVersion>
<FileAlignment>
512
</FileAlignment>
<StartupObject>
Google.ProtocolBuffers.Examples.AddressBook.Program
</StartupObject>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>
3.5
</OldToolsVersion>
<PublishUrl>
publish\
</PublishUrl>
<Install>
true
</Install>
<InstallFrom>
Disk
</InstallFrom>
<UpdateEnabled>
false
</UpdateEnabled>
<UpdateMode>
Foreground
</UpdateMode>
<UpdateInterval>
7
</UpdateInterval>
<UpdateIntervalUnits>
Days
</UpdateIntervalUnits>
<UpdatePeriodically>
false
</UpdatePeriodically>
<UpdateRequired>
false
</UpdateRequired>
<MapFileExtensions>
true
</MapFileExtensions>
<ApplicationRevision>
0
</ApplicationRevision>
<ApplicationVersion>
1.0.0.%2a
</ApplicationVersion>
<IsWebBootstrapper>
false
</IsWebBootstrapper>
<UseApplicationTrust>
false
</UseApplicationTrust>
<BootstrapperEnabled>
true
</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "
>
<DebugSymbols>
true
</DebugSymbols>
<DebugType>
full
</DebugType>
<Optimize>
false
</Optimize>
<OutputPath>
bin\Debug\
</OutputPath>
<DefineConstants>
DEBUG;TRACE
</DefineConstants>
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
<CodeAnalysisRuleSet>
AllRules.ruleset
</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "
>
<DebugType>
pdbonly
</DebugType>
<Optimize>
true
</Optimize>
<OutputPath>
bin\Release\
</OutputPath>
<DefineConstants>
TRACE
</DefineConstants>
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
<CodeAnalysisRuleSet>
AllRules.ruleset
</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference
Include=
"mscorlib"
/>
<Reference
Include=
"System"
/>
<Reference
Include=
"System.Data"
/>
<Reference
Include=
"System.Xml"
/>
</ItemGroup>
<ItemGroup>
<Compile
Include=
"AddPerson.cs"
/>
<Compile
Include=
"AddressBookProtos.cs"
/>
<Compile
Include=
"SampleUsage.cs"
/>
<Compile
Include=
"ListPeople.cs"
/>
<Compile
Include=
"Program.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
</ItemGroup>
<ItemGroup>
<ProjectReference
Include=
"..\ProtocolBuffers\ProtocolBuffers.csproj"
>
<Project>
{6908BDCE-D925-43F3-94AC-A531E6DF2591}
</Project>
<Name>
ProtocolBuffers
</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None
Include=
"app.config"
/>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage
Include=
"Microsoft.Net.Client.3.5"
>
<Visible>
False
</Visible>
<ProductName>
.NET Framework 3.5 SP1 Client Profile
</ProductName>
<Install>
false
</Install>
</BootstrapperPackage>
<BootstrapperPackage
Include=
"Microsoft.Net.Framework.3.5.SP1"
>
<Visible>
False
</Visible>
<ProductName>
.NET Framework 3.5 SP1
</ProductName>
<Install>
true
</Install>
</BootstrapperPackage>
<BootstrapperPackage
Include=
"Microsoft.Windows.Installer.3.1"
>
<Visible>
False
</Visible>
<ProductName>
Windows Installer 3.1
</ProductName>
<Install>
true
</Install>
</BootstrapperPackage>
</ItemGroup>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSharp.targets"
/>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
-->
</Project>
\ No newline at end of file
src/AddressBook/SampleUsage.cs
0 → 100644
View file @
d6405f83
using
System
;
using
System.IO
;
namespace
Google.ProtocolBuffers.Examples.AddressBook
{
class
SampleUsage
{
static
void
Main
()
{
byte
[]
bytes
;
//Create a builder to start building a message
Person
.
Builder
newContact
=
Person
.
CreateBuilder
();
//Set the primitive properties
newContact
.
SetId
(
1
)
.
SetName
(
"Foo"
)
.
SetEmail
(
"foo@bar"
);
//Now add an item to a list (repeating) field
newContact
.
AddPhone
(
//Create the child message inline
Person
.
Types
.
PhoneNumber
.
CreateBuilder
().
SetNumber
(
"555-1212"
).
Build
()
);
//Now build the final message:
Person
person
=
newContact
.
Build
();
//The builder is no longer valid (at least not now, scheduled for 2.4):
newContact
=
null
;
using
(
MemoryStream
stream
=
new
MemoryStream
())
{
//Save the person to a stream
person
.
WriteTo
(
stream
);
bytes
=
stream
.
ToArray
();
}
//Create another builder, merge the byte[], and build the message:
Person
copy
=
Person
.
CreateBuilder
().
MergeFrom
(
bytes
).
Build
();
//A more streamlined approach might look like this:
bytes
=
AddressBook
.
CreateBuilder
().
AddPerson
(
copy
).
Build
().
ToByteArray
();
//And read the address book back again
AddressBook
restored
=
AddressBook
.
CreateBuilder
().
MergeFrom
(
bytes
).
Build
();
//The message performs a deep-comparison on equality:
if
(
restored
.
PersonCount
!=
1
||
!
person
.
Equals
(
restored
.
PersonList
[
0
]))
throw
new
ApplicationException
(
"There is a bad person in here!"
);
}
}
}
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