modificando json e protobuf

This commit is contained in:
2023-11-04 17:05:55 -03:00
parent 1eb02db473
commit 95a85be35d
15 changed files with 163 additions and 65 deletions

View File

@@ -1,6 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using ProtoBuf;
using System.IO;
using tcc_app.Models;
namespace TCC.Controllers
{
@@ -24,25 +23,25 @@ namespace TCC.Controllers
return Ok(sum);
}
[HttpGet("json")]
public async Task<IActionResult> GetJsonResponse()
[HttpPost("json")]
public async Task<IActionResult> PostJson([FromBody] PersonJson person)
{
return Ok(new { message = "Hello World!" });
return Ok(person);
}
[HttpPost("protobuf")]
public async Task<IActionResult> PostProtobuf()
{
HelloWorld cliente;
PersonProto person;
byte[] response;
using (var stream = Request.BodyReader.AsStream())
{
cliente = ProtoBuf.Serializer.Deserialize<HelloWorld>(stream);
person = ProtoBuf.Serializer.Deserialize<PersonProto>(stream);
}
using (var stream = new MemoryStream())
{
ProtoBuf.Serializer.Serialize(stream, cliente);
ProtoBuf.Serializer.Serialize(stream, person);
response = stream.ToArray();
}
@@ -51,11 +50,4 @@ namespace TCC.Controllers
}
}
[ProtoContract()]
public class HelloWorld
{
[ProtoMember(1)]
public string Message { get; set; }
}
}