aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/csharp/GrpcCore/IMarshaller.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/csharp/GrpcCore/IMarshaller.cs')
-rw-r--r--src/csharp/GrpcCore/IMarshaller.cs31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/csharp/GrpcCore/IMarshaller.cs b/src/csharp/GrpcCore/IMarshaller.cs
new file mode 100644
index 0000000000..eb08d8d386
--- /dev/null
+++ b/src/csharp/GrpcCore/IMarshaller.cs
@@ -0,0 +1,31 @@
+using System;
+
+namespace Google.GRPC.Core
+{
+ /// <summary>
+ /// For serializing and deserializing messages.
+ /// </summary>
+ public interface IMarshaller<T>
+ {
+ byte[] Serialize(T value);
+
+ T Deserialize(byte[] payload);
+ }
+
+ /// <summary>
+ /// UTF-8 Marshalling for string. Useful for testing.
+ /// </summary>
+ internal class StringMarshaller : IMarshaller<string> {
+
+ public byte[] Serialize(string value)
+ {
+ return System.Text.Encoding.UTF8.GetBytes(value);
+ }
+
+ public string Deserialize(byte[] payload)
+ {
+ return System.Text.Encoding.UTF8.GetString(payload);
+ }
+ }
+}
+