adding protobuf

This commit is contained in:
2023-11-02 19:14:16 -03:00
parent 2965293bfb
commit ac8bff31f2
12 changed files with 324 additions and 449 deletions

View File

@@ -15,23 +15,6 @@ namespace TCC.Controllers
this.ImageService = imageService;
}
[HttpPost("blur")]
public async Task<IActionResult> BlurImage([FromQuery] int radius)
{
MemoryStream mstream = new MemoryStream();
await HttpContext.Request.Body.CopyToAsync(mstream);
mstream.Position = 0;
var result = ImageService.BoxBlurImage(mstream, radius);
mstream.Close();
var blurredImageStream = new MemoryStream();
result.Write(blurredImageStream);
blurredImageStream.Position = 0;
return File(blurredImageStream, "image/png");
}
[HttpGet("load-small-image")]
public async Task<IActionResult> GetSimpleImage()
{

View File

@@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Mvc;
using TCC.Services;
using ProtoBuf;
using System.IO;
namespace TCC.Controllers
{
@@ -14,7 +15,7 @@ namespace TCC.Controllers
[HttpGet("harmonic-progression")]
public async Task<IActionResult> GetHarmonicProgression([FromQuery] int n)
{
float sum = 0;
double sum = 0;
for (int i = 1; i <= n; i++)
{
sum += 1.0f / i;
@@ -28,5 +29,33 @@ namespace TCC.Controllers
{
return Ok(new { message = "Hello World!" });
}
[HttpPost("protobuf")]
public async Task<IActionResult> PostProtobuf()
{
HelloWorld cliente;
byte[] response;
using (var stream = Request.BodyReader.AsStream())
{
cliente = ProtoBuf.Serializer.Deserialize<HelloWorld>(stream);
}
using (var stream = new MemoryStream())
{
ProtoBuf.Serializer.Serialize(stream, cliente);
response = stream.ToArray();
}
await Response.Body.WriteAsync(response, 0, response.Length);
return new EmptyResult();
}
}
[ProtoContract()]
public class HelloWorld
{
[ProtoMember(1)]
public string Message { get; set; }
}
}