csharp-sdk-upm/Realtime/Realtime.Test/Protobuf.cs

29 lines
1004 B
C#
Raw Normal View History

using NUnit.Framework;
2020-04-28 17:04:46 +08:00
using LeanCloud.Realtime.Internal.Protocol;
2021-03-29 14:56:00 +08:00
using LC.Google.Protobuf;
namespace Realtime.Test {
public class Protobuf {
[Test]
public void Serialize() {
GenericCommand command = new GenericCommand {
Cmd = CommandType.Session,
Op = OpType.Open,
PeerId = "hello"
};
SessionCommand session = new SessionCommand {
Code = 123
};
command.SessionMessage = session;
byte[] bytes = command.ToByteArray();
TestContext.WriteLine($"length: {bytes.Length}");
command = GenericCommand.Parser.ParseFrom(bytes);
Assert.AreEqual(command.Cmd, CommandType.Session);
Assert.AreEqual(command.Op, OpType.Open);
Assert.AreEqual(command.PeerId, "hello");
Assert.NotNull(command.SessionMessage);
Assert.AreEqual(command.SessionMessage.Code, 123);
}
}
}