protobuf-net | Clone of the protobuf-net SVN repository | Serialization library
kandi X-RAY | protobuf-net Summary
kandi X-RAY | protobuf-net Summary
Clone of the protobuf-net SVN repository
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of protobuf-net
protobuf-net Key Features
protobuf-net Examples and Code Snippets
Community Discussions
Trending Discussions on protobuf-net
QUESTION
I'm trying to do something that I think should be simple: Convert a List into a
stream
.
...
ANSWER
Answered 2022-Feb-23 at 04:41You have to add ProtoContract to your class like this:
QUESTION
When using protobuf-net, I have a class Data
decorated with [ProtoContract]
attribute, which defines an inner class. Members of that type should be serialized as well.
ANSWER
Answered 2021-Nov-29 at 14:05You just need to annotate NestedData
with [ProtoContract]
:
QUESTION
I built the protobuf-net 2.4.0 project for .Net Standard 2.0 but the portability-analyzer tool shows only 92% of compatibility because of the below details.
Questions are:
...ANSWER
Answered 2021-Nov-17 at 17:47It is, confusingly, impossible to talk about compatibility with .NET Standard, unless you mean "lowest common denominator", which: most people don't. What matters is what you actually run it on. You mention .NET Framework and .NET Core - and it should.work just fine there. If you were using it on Unity or Xamarin (mobile etc), the answer is more complicated.
QUESTION
The documentation seems to indicate this should be possible but I'm not having any luck getting this working as described.
net5.0 project, protobuf-net (3.0.101) and protobuf-net.BuildTools(3.0.101) are the only NuGet references
simple .proto file defined as:
...ANSWER
Answered 2021-Nov-11 at 18:14Short version: there was an error in the tool bundling; I have fixed this, and with an imminent build (currently working through the CI build), this should be resolved; the config in the question now works, with the additional output in the C#:
QUESTION
I did a quick search about the usage of oneof
in Protobuf-net
and it appears it's supported as of v2.3.0, but I can't for the life of me find any examples on exactly how one would use it!
My requirements are pretty simple, and maybe this can also be solved with [ProtoInclude]
but I'm not quite sure exactly how this would work. I've got the following class:
ANSWER
Answered 2021-Oct-20 at 14:33The way to play with this is to take the message from the MS example you cite, and run it through protogen to see what it does - which we can do very conveniently here: https://protogen.marcgravell.com/ (note I'm adding syntax = "proto3";
at the top of the file, which is omitted in the MS example).
This gives us, among other things:
QUESTION
I have 2 applications using protobuf in between. First one (C#) using protobuf-net with serializable object VisualSettings:
...ANSWER
Answered 2021-Oct-20 at 12:13This is happening because of the inheritance, basically; inheritance isn't a concept that protobuf directly supports, so protobuf-net models inheritance via nested sub-objects; to avoid some complexity, when serializing this, protobuf-net always starts by writing the inheritance parts first - so: when serializing BasePaintHolder
, it might serialize field 400 (the sub-type data for BaseSmokePaintHolder
), then field 1 (materialId
). This means that when it comes to deserialize, it has an obvious construction path, i.e. by the time it gets field data, it has already constructed the final concrete type.
This is fine, for protobuf-net to protobuf-net scenarios, but when we work with the same data in Java, it doesn't know or care about this, and elects to serialize in ascending field order, i.e. field 1, then field 400. It is explicit in the specification that fields may be out of order, but Java can choose to do whatever it wants.
So: now we take that data back to protobuf-net, and we see field 1 first; at that point, we have no clue what the final type will be, and nowhere (yet) to stick the data. With no better options, the library tries to use the base type BasePaintHolder
as a placeholder until it can make better decisions, but it turns out that this type is abstract
, so: even that fails.
So: that's the why, and some back-story. What can we do?
Well, the first thing we could try might be to remove the abstract
, making it technically constructable. To prevent external code accidentally creating instances, you might also make the constructors protected
, internal
, or private protected
(which means the intersection of protected
and internal
). We could also try using the SkipConstructor=true
modifier on [ProtoContract]
.
If that doesn't work: it might be necessary to basically work with 2 different object models; one that is simple - essentially more like the Java version, perhaps by running your schema through https://protogen.marcgravell.com/ - and one that has the inheritance; use the simple version for deserialization (and optionally serialization, although that shouldn't matter), and then re-map the data in your own code to the actual model. The other option is for me to figure out a way of doing all this magically and automatically; which: isn't a small job.
QUESTION
In C++, I'm using the call mentioned in the title to obtain the definition of a message in textual form, similar to what you would write in a .proto file. How would I do this with protobuf-net? The goal is to store message definitions in a kind of message registry. But maybe there are other possibilities to represent a message definition at runtime? (a representation of a definition that can be compared).
...ANSWER
Answered 2021-Oct-05 at 10:06protobuf-net has a Serializer.GetProto
API (or a RuntimeTypeModel.GetSchema
API - they're the same thing with slightly different inputs); however, note that this is only an approximation of any original schema - meaning: if you do start from .proto via protobuf-net's schema parsing tools, we don't currently store the original schema anywhere, so anything we generate is a best-efforts reconstruction only.
QUESTION
Consider the following code example; I want to be able to serialize (which works fine) and deserialize (which doesn't work) the Account
record using protobuf-net:
ANSWER
Answered 2021-Sep-25 at 02:03The properties of a record are, by default, init
-only, and as such can actually be set by reflection by protobuf-net. Thus your Account
record can be deserialized by protobuf-net by bypassing the constructor as explained in this answer by Marc Gravell to Does protobuf-net support C# 9 positional record types?.
Since you are initializing the contract for Account
in runtime, modify your initialization code as to set MetaType.UseConstructor = false
as follows:
QUESTION
When attempting to serialize an object using Google's Protocol Buffers I get the following error:
More DetailType is not expected, and no contract can be inferred:
I have three projects:
- DotNet Standard 2.0 Library project with a *.proto file
- DotNet Framework 4.8 WebAPI
- DotNet 5 Test application
The Library contains a *.proto file. This contains several different message
objects, each with properties that are either strings or int32. There's two "wrapper" objects, one named Request
(and the other Response
). There's nothing obviously complicated.
The NuGet packages for this Library are:
...ANSWER
Answered 2021-Sep-10 at 22:32In protobuf, when working with a .proto, there are two sets of tools involved:
- the schema parser/code generator
- the runtime library
Now, what we also need to know is that there are multiple implementations of protobuf in .NET-land; relevant to this question, there is the Google implementation, and protobuf-net (there are others, but they don't relate to this question).
What I think you've done is: you've used the Google tools for step 1 ("protoc") but protobuf-net for step 2. The tools for 1 and 2 need to match: Google and Google is fine; protobuf-net and protobuf-net is fine - but not crossovers.
So, either:
a. use the Google runtime library instead of protobuf-net ("Google.Protobuf", as a nuget package), or b: use protobuf-net's schema tools and code gen (see https://protobuf-net.github.io/protobuf-net/contract_first.html, including the links at the bottom for other options)
If I'm right in my hunch, please let me know - I'll try to make protobuf-net recognize this scenario and at least offer suitable guidance
QUESTION
I'm trying to get my head around protobuf-net at the moment, and found this article on being able to serialize sub-types: How to Serialize Inherited Class with ProtoBuf-Net
Effectively this suggests that the base type needs to know about the sub-type:
...ANSWER
Answered 2021-Sep-03 at 19:06- Yes, there is a full API for this under RuntimeTypeModel, including callbacks for auto-discovery during runtime rather than ahead of time
However!
No, it can't work with unknown subtypes unless you mean: by ignoring the subtype aspect completely and just treating it as though it were the known type.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install protobuf-net
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page