public void Decode(string path, string messageName) { var proto = File.ReadAllText(Path.Combine(TestContext.CurrentContext.TestDirectory, path)); var schema = new ProtobufSchema <int>(new StringReader(proto), messageName); Assert.NotNull(schema); }
public void DecodeAssign() { var proto = File.ReadAllText(Path.Combine(TestContext.CurrentContext.TestDirectory, "res/Protobuf/Person.proto")); var schema = new ProtobufSchema <Person>(new StringReader(proto), "Person"); schema.DecoderDescriptor.HasField("email", () => string.Empty, (ref Person p, string v) => p.Email = v) .HasValue(); schema.DecoderDescriptor.HasField("id", () => 0, (ref Person p, int v) => p.Id = v).HasValue(); schema.DecoderDescriptor.HasField("name", () => string.Empty, (ref Person p, string v) => p.Name = v) .HasValue(); var decoder = schema.CreateDecoder(() => new Person()); using (var stream = new MemoryStream(new byte[] { 16, 17, 0, 0, 0 })) { using (var decoderStream = decoder.Open(stream)) { Assert.True(decoderStream.TryDecode(out var entity)); Assert.AreEqual(17, entity.Id); } } }