Make c# api friendlier to immutable types. Rename Result.result to Result.value
This commit is contained in:
1 parent
b7b3cbb59d
commit
eafa6ed68d
18 files changed
+221
-189
No files matched your search
@@ -0,0 +1,32 @@
|
||||
using Google.Protobuf;
|
||||
using Google.Protobuf.Reflection;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace bts.api {
|
||||
internal interface IImmutableMessage {
|
||||
MessageDescriptor Descriptor { get; }
|
||||
int CalculateSize();
|
||||
void WriteTo(CodedOutputStream output);
|
||||
}
|
||||
|
||||
internal static class ImmutableProtoExtensions {
|
||||
public static void WriteTo(this IImmutableMessage message, Stream output) {
|
||||
var stream = new CodedOutputStream(output);
|
||||
message.WriteTo(stream);
|
||||
stream.Flush();
|
||||
}
|
||||
|
||||
public static byte[] ToByteArray(this IImmutableMessage message) {
|
||||
var result = new byte[message.CalculateSize()];
|
||||
var output = new CodedOutputStream(result);
|
||||
message.WriteTo(output);
|
||||
output.CheckNoSpaceLeft();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user