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