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,5 +1,5 @@
from flask import request, Blueprint, jsonify
import helloworld_pb2
import person_pb2
simulation_blueprint = Blueprint('simulation_blueprint', __name__)
@@ -26,15 +26,16 @@ def return_ok():
return str(sum), 200
@simulation_blueprint.route('/simulation/json', methods=['GET'])
@simulation_blueprint.route('/simulation/json', methods=['POST'])
def return_helloworld():
return simulation_controller.return_helloworld(), 200
data = request.json
return data, 200
@simulation_blueprint.route('/simulation/protobuf', methods=['POST'])
def return_protobuf():
bytes_data = request.data
helloworld = helloworld_pb2.MyObj()
helloworld = person_pb2.Person()
helloworld.ParseFromString(bytes_data)
return helloworld.SerializeToString(), 200

View File

@@ -1,5 +0,0 @@
syntax = "proto3";
message MyObj {
string message = 1;
}

9
FlaskAPI/person.proto Normal file
View File

@@ -0,0 +1,9 @@
syntax = "proto3";
message Person {
string name = 1;
int32 age = 2;
repeated string friends = 3;
string email = 4;
string phone = 5;
}

View File

@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: helloworld.proto
# source: person.proto
# Protobuf Python Version: 4.25.0
"""Generated protocol buffer code."""
from google.protobuf import descriptor as _descriptor
@@ -14,13 +14,13 @@ _sym_db = _symbol_database.Default()
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x10helloworld.proto\"\x18\n\x05MyObj\x12\x0f\n\x07message\x18\x01 \x01(\tb\x06proto3')
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0cperson.proto\"R\n\x06Person\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0b\n\x03\x61ge\x18\x02 \x01(\x05\x12\x0f\n\x07\x66riends\x18\x03 \x03(\t\x12\r\n\x05\x65mail\x18\x04 \x01(\t\x12\r\n\x05phone\x18\x05 \x01(\tb\x06proto3')
_globals = globals()
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'helloworld_pb2', _globals)
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'person_pb2', _globals)
if _descriptor._USE_C_DESCRIPTORS == False:
DESCRIPTOR._options = None
_globals['_MYOBJ']._serialized_start=20
_globals['_MYOBJ']._serialized_end=44
_globals['_PERSON']._serialized_start=16
_globals['_PERSON']._serialized_end=98
# @@protoc_insertion_point(module_scope)