You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the problem you are trying to solve.
Trying to manually marshall a message from a buffer, but unlike Java, several parsing primitives from CodedInputStream such as ReadRawVarint32 are not public. This significantly limits the utility of the new high-performance API's (e.g. IBufferWriter<byte>) or requires poor code hygiene (see the alternatives section below).
Describe the solution you'd like
At a very bare minimum, having some of the the same Java members available in dotnet, including:
CodedInputStream
public static int readRawVarint32(final InputStream input)
public static int readRawVarint32(final int firstByte, final InputStream input)
public static int decodeZigZag32(final int n)
public static long decodeZigZag64(final long n)
CodedOutputStream
public static int encodeZigZag32(final int n)
public static long encodeZigZag64(final long n)
Much, much, more practically for those using IBufferWriter<byte> to do custom (zero/minimal-copy) marshaling, it would be ideal to have access to many of the members of ReadingPrimitives and WritingPrimitives.
Describe alternatives you've considered
Copy-and-pasting Protobuf source into my application. 😞
Hand-rolling varint code.
Casting IBufferWriter<byte> to ArrayBufferWriter<byte>, pinning the array, and then passing an UnmanagedMemoryStream to CodedOutputStream. This works, but is violating abstractions, requires an unsafe block, and breaks if you call SerializationContext.SetPayloadLength which causes SerializationContext.GetBufferWriter to return a HttpResponsePipeWriter instead of a ArrayBufferWriter.
I have a related but perhaps more easily encountered problem: providing a BytesBuffer object to satisfy a bytes field requires copying the data.[1] ByteString as well. A private constructor exists which does no copying. This constructor or another API should be exposed to elide the copies. This could be taken further and the C++ API mimicked so a pointer and length could be submitted to avoid copying in data via Marshal.
The latter was claimed to be problematic but this concern was not clearly articulated. Certainly C# is deficient in that all safe types must be constructed with copying but a workaround is worthwhile. Either 2 (unsafe) or 3 (safe) copies are needed before protobuf has the data.
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.
This issue is labeled inactive because the last activity was over 90 days ago.
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please reopen it.
This issue was closed and archived because there has been no new activity in the 14 days since the inactive label was added.
What language does this apply to?
C#
Describe the problem you are trying to solve.
Trying to manually marshall a message from a buffer, but unlike Java, several parsing primitives from
CodedInputStream
such asReadRawVarint32
are not public. This significantly limits the utility of the new high-performance API's (e.g.IBufferWriter<byte>
) or requires poor code hygiene (see the alternatives section below).Describe the solution you'd like
At a very bare minimum, having some of the the same Java members available in dotnet, including:
CodedInputStream
public static int readRawVarint32(final InputStream input)
public static int readRawVarint32(final int firstByte, final InputStream input)
public static int decodeZigZag32(final int n)
public static long decodeZigZag64(final long n)
CodedOutputStream
public static int encodeZigZag32(final int n)
public static long encodeZigZag64(final long n)
Much, much, more practically for those using
IBufferWriter<byte>
to do custom (zero/minimal-copy) marshaling, it would be ideal to have access to many of the members ofReadingPrimitives
andWritingPrimitives
.Describe alternatives you've considered
IBufferWriter<byte>
toArrayBufferWriter<byte>
, pinning the array, and then passing anUnmanagedMemoryStream
toCodedOutputStream
. This works, but is violating abstractions, requires anunsafe
block, and breaks if you callSerializationContext.SetPayloadLength
which causesSerializationContext.GetBufferWriter
to return aHttpResponsePipeWriter
instead of aArrayBufferWriter
.Additional context
Related to:
The text was updated successfully, but these errors were encountered: