From 3b1c161547d8266e093b871a3ee114999b8e5d69 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Sat, 9 Jul 2022 19:55:38 +0100 Subject: [PATCH] remove protobuf example --- Cargo.toml | 3 - actix-protobuf/Cargo.toml | 2 +- .../examples/prost-example/Cargo.toml | 15 ---- .../examples/prost-example/client.py | 68 ----------------- .../examples/prost-example/src/main.rs | 33 -------- .../examples/prost-example/test.proto | 6 -- .../examples/prost-example/test_pb2.py | 75 ------------------- 7 files changed, 1 insertion(+), 201 deletions(-) delete mode 100644 actix-protobuf/examples/prost-example/Cargo.toml delete mode 100755 actix-protobuf/examples/prost-example/client.py delete mode 100644 actix-protobuf/examples/prost-example/src/main.rs delete mode 100644 actix-protobuf/examples/prost-example/test.proto delete mode 100644 actix-protobuf/examples/prost-example/test_pb2.py diff --git a/Cargo.toml b/Cargo.toml index eaf622615..9a953a3ea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,9 +10,6 @@ members = [ "actix-web-httpauth", ] -# TODO: move this example to examples repo -# "actix-protobuf/examples/prost-example", - [patch.crates-io] actix-cors = { path = "./actix-cors" } actix-identity = { path = "./actix-identity" } diff --git a/actix-protobuf/Cargo.toml b/actix-protobuf/Cargo.toml index f0a9d3e88..439e28592 100644 --- a/actix-protobuf/Cargo.toml +++ b/actix-protobuf/Cargo.toml @@ -6,7 +6,7 @@ authors = [ "kingxsp ", "Yuki Okushi ", ] -description = "Protobuf support for Actix web" +description = "Protobuf support for Actix Web" keywords = ["actix", "web", "protobuf", "protocol", "rpc"] homepage = "https://actix.rs" repository = "https://github.com/actix/actix-extras.git" diff --git a/actix-protobuf/examples/prost-example/Cargo.toml b/actix-protobuf/examples/prost-example/Cargo.toml deleted file mode 100644 index f5baf4bae..000000000 --- a/actix-protobuf/examples/prost-example/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "prost-example" -version = "0.5.1" -edition = "2018" -authors = [ - "kingxsp ", - "Yuki Okushi " -] - -[dependencies] -actix-web = "4" -actix-protobuf = { path = "../../" } - -env_logger = "0.8" -prost = { version = "0.8", default_features = false, features = ["prost-derive"] } diff --git a/actix-protobuf/examples/prost-example/client.py b/actix-protobuf/examples/prost-example/client.py deleted file mode 100755 index 99a93e7d3..000000000 --- a/actix-protobuf/examples/prost-example/client.py +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/env python3 -# just start server and run client.py - -# wget https://github.com/protocolbuffers/protobuf/releases/download/v3.11.2/protobuf-python-3.11.2.zip -# unzip protobuf-python-3.11.2.zip -# cd protobuf-3.11.2/python/ -# python3 setup.py install - -# pip3 install --upgrade pip -# pip3 install aiohttp - -# python3 client.py - -import test_pb2 -import traceback -import sys - -import asyncio -import aiohttp - -def op(): - try: - obj = test_pb2.MyObj() - obj.number = 9 - obj.name = 'USB' - - #Serialize - sendDataStr = obj.SerializeToString() - #print serialized string value - print('serialized string:', sendDataStr) - #------------------------# - # message transmission # - #------------------------# - receiveDataStr = sendDataStr - receiveData = test_pb2.MyObj() - - #Deserialize - receiveData.ParseFromString(receiveDataStr) - print('pares serialize string, return: devId = ', receiveData.number, ', name = ', receiveData.name) - except(Exception, e): - print(Exception, ':', e) - print(traceback.print_exc()) - errInfo = sys.exc_info() - print(errInfo[0], ':', errInfo[1]) - - -async def fetch(session): - obj = test_pb2.MyObj() - obj.number = 9 - obj.name = 'USB' - async with session.post('http://127.0.0.1:8081/', data=obj.SerializeToString(), - headers={"content-type": "application/protobuf"}) as resp: - print(resp.status) - data = await resp.read() - receiveObj = test_pb2.MyObj() - receiveObj.ParseFromString(data) - print(receiveObj) - -async def go(loop): - obj = test_pb2.MyObj() - obj.number = 9 - obj.name = 'USB' - async with aiohttp.ClientSession(loop=loop) as session: - await fetch(session) - -loop = asyncio.get_event_loop() -loop.run_until_complete(go(loop)) -loop.close() \ No newline at end of file diff --git a/actix-protobuf/examples/prost-example/src/main.rs b/actix-protobuf/examples/prost-example/src/main.rs deleted file mode 100644 index 8dab194d7..000000000 --- a/actix-protobuf/examples/prost-example/src/main.rs +++ /dev/null @@ -1,33 +0,0 @@ -use actix_protobuf::*; -use actix_web::*; -use prost::Message; - -#[derive(Clone, PartialEq, Message)] -pub struct MyObj { - #[prost(int32, tag = "1")] - pub number: i32, - - #[prost(string, tag = "2")] - pub name: String, -} - -async fn index(msg: ProtoBuf) -> Result { - println!("model: {:?}", msg); - HttpResponse::Ok().protobuf(msg.0) // <- send response -} - -#[actix_web::main] -async fn main() -> std::io::Result<()> { - std::env::set_var("RUST_LOG", "actix_web=debug,actix_server=info"); - env_logger::init(); - - HttpServer::new(|| { - App::new() - .wrap(middleware::Logger::default()) - .service(web::resource("/").route(web::post().to(index))) - }) - .bind("127.0.0.1:8081")? - .shutdown_timeout(1) - .run() - .await -} diff --git a/actix-protobuf/examples/prost-example/test.proto b/actix-protobuf/examples/prost-example/test.proto deleted file mode 100644 index 8ec278ca4..000000000 --- a/actix-protobuf/examples/prost-example/test.proto +++ /dev/null @@ -1,6 +0,0 @@ -syntax = "proto3"; - -message MyObj { - int32 number = 1; - string name = 2; -} \ No newline at end of file diff --git a/actix-protobuf/examples/prost-example/test_pb2.py b/actix-protobuf/examples/prost-example/test_pb2.py deleted file mode 100644 index ea5a1d9d6..000000000 --- a/actix-protobuf/examples/prost-example/test_pb2.py +++ /dev/null @@ -1,75 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by the protocol buffer compiler. DO NOT EDIT! -# source: test.proto - -from google.protobuf import descriptor as _descriptor -from google.protobuf import message as _message -from google.protobuf import reflection as _reflection -from google.protobuf import symbol_database as _symbol_database -# @@protoc_insertion_point(imports) - -_sym_db = _symbol_database.Default() - - - - -DESCRIPTOR = _descriptor.FileDescriptor( - name='test.proto', - package='', - syntax='proto3', - serialized_options=None, - serialized_pb=b'\n\ntest.proto\"%\n\x05MyObj\x12\x0e\n\x06number\x18\x01 \x01(\x05\x12\x0c\n\x04name\x18\x02 \x01(\tb\x06proto3' -) - - - - -_MYOBJ = _descriptor.Descriptor( - name='MyObj', - full_name='MyObj', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='number', full_name='MyObj.number', index=0, - number=1, type=5, cpp_type=1, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='name', full_name='MyObj.name', index=1, - number=2, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=b"".decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=14, - serialized_end=51, -) - -DESCRIPTOR.message_types_by_name['MyObj'] = _MYOBJ -_sym_db.RegisterFileDescriptor(DESCRIPTOR) - -MyObj = _reflection.GeneratedProtocolMessageType('MyObj', (_message.Message,), { - 'DESCRIPTOR' : _MYOBJ, - '__module__' : 'test_pb2' - # @@protoc_insertion_point(class_scope:MyObj) - }) -_sym_db.RegisterMessage(MyObj) - - -# @@protoc_insertion_point(module_scope)