mirror of
https://github.com/ivanch/tcc.git
synced 2025-09-13 16:01:50 +00:00
modificando json e protobuf
This commit is contained in:
@@ -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; }
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user