1 Star 0 Fork 1

luke757/protobuf-net

forked from vonleen/protobuf-net 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
StartHere.txt 2.30 KB
一键复制 编辑 原始数据 按行查看 历史
What is protobuf-net?
=====================
protobuf-net is a binary serialization engine, along similar lines to BinaryFormatter
but using the "protocol buffers" [PB] specification as laid out by Google.
The core protobuf-net library is a single dll; other projects are presented for
testing and example purposes.
Many PB implementations start with a .proto text file (describing the types), with
the developer running a command-line tool to generate code in their target
language. Deliberately, protobuf-net started the other way around: it is designed
to work with existing .NET types at runtime. This allows you to use your existing
data objects, but still with lots of optimisations to keep things very fast.
There is a C# code generation version (courtesy of Jon Skeet), and a proposed future
extension is to allow generation of protobuf-net classes from a .proto file.
================
How do I use it?
================
These steps are a walkthrough of the QuickStart project.
0: add a reference to protobuf-net
protobuf-net is a runtime engine, and the assembly is required (and should be
deployed with your program).
1: define your data objects ("1 Data Objects.cs")
protobuf-net uses regular .NET classes. The only requirement (in common with
other serializers such as XmlSerializer) is that there must be a public
parameterless constructor, and it must be marked for serialization.
Any properties you want to serialize must have a "getter" and "setter",
and an integer "tag" is required on each (used to uniquely identify each
property when serialized). Collection properties can also be serialized, but
it is not necessary to have a "setter", as items can be added to the
existing list.
2: write objects to a file and read them back ("2 File Access.cs")
This sample shows writing object-graphs to simple streams such as FileStream,
using the Serialize and Deserialize methods.
3: write objects to a socket and read them back ("3 Sockets.cs")
Network IO is more complicated, especially since we can reasonably expect
a conversation between client and server on the same connection, but each
needs to know how much data is part of the current request/response. This
sample shows using the SerializeWithLengthPrefix/DeserializeWithLengthPrefix
methods to communicate over a socket.
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/luke757/protobuf-net.git
git@gitee.com:luke757/protobuf-net.git
luke757
protobuf-net
protobuf-net
master

搜索帮助