├── .gitignore ├── AppGrpc ├── .gitignore ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── yc │ │ └── appgrpc │ │ ├── GRPCClient.java │ │ ├── GRPCServer.java │ │ ├── GreeterActivity.java │ │ ├── HelloWorldActivity.java │ │ ├── MainActivity.java │ │ └── ProtoJsonTest.java │ ├── proto │ ├── efficient_test.proto │ ├── greeter.proto │ ├── hello_world.proto │ └── msg_test.proto │ └── res │ ├── drawable │ └── ic_launcher_background.xml │ ├── layout │ ├── activity_greeter.xml │ ├── activity_helloworld.xml │ └── activity_rpc_main.xml │ ├── mipmap-xhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ └── values │ ├── colors.xml │ └── strings.xml ├── CompressServer ├── .gitignore ├── README.md ├── build.gradle ├── src │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── com │ │ │ └── yc │ │ │ └── compress │ │ │ ├── image │ │ │ ├── AppBitmapUtils.java │ │ │ ├── ImageDataSource.java │ │ │ ├── ImageSaveUtils.java │ │ │ ├── NetImageUtils.java │ │ │ ├── PicCalculateUtils.java │ │ │ ├── PicMimeTypeUtils.java │ │ │ └── ViewBitmapUtils.java │ │ │ ├── luban │ │ │ ├── Checker.java │ │ │ ├── CompressionPredicate.java │ │ │ ├── Engine.java │ │ │ ├── InputStreamAdapter.java │ │ │ ├── InputStreamProvider.java │ │ │ ├── Luban.java │ │ │ ├── OnCompressListener.java │ │ │ └── OnRenameListener.java │ │ │ └── utils │ │ │ ├── AppCompress.java │ │ │ ├── CompressConfig.java │ │ │ └── CompressUtils.java │ │ └── res │ │ └── values │ │ └── strings.xml └── 图片README.md ├── EasyBleServer ├── .gitignore ├── README.md ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── yc │ └── easyble │ ├── BleManager.java │ ├── bluetooth │ ├── BleBluetooth.java │ ├── BleConnector.java │ ├── MultipleBluetoothController.java │ └── SplitWriter.java │ ├── callback │ ├── BleBaseCallback.java │ ├── BleGattCallback.java │ ├── BleIndicateCallback.java │ ├── BleMtuChangedCallback.java │ ├── BleNotifyCallback.java │ ├── BleReadCallback.java │ ├── BleRssiCallback.java │ ├── BleScanAndConnectCallback.java │ ├── BleScanCallback.java │ ├── BleWriteCallback.java │ └── IBleScanCallback.java │ ├── config │ ├── BleScanConfig.java │ └── BleScanRuleConfig.java │ ├── data │ ├── BleConnectStateParameter.java │ ├── BleDevice.java │ ├── BleMsg.java │ ├── BleScanState.java │ └── BleWriteState.java │ ├── exception │ ├── BleException.java │ ├── ConnectException.java │ ├── GattException.java │ ├── OtherException.java │ └── TimeoutException.java │ ├── scan │ ├── BleScanPresenter.java │ └── BleScanner.java │ └── utils │ ├── BleHelperUtils.java │ ├── BleLog.java │ ├── BleLruHashMap.java │ └── HexUtil.java ├── GalleryPagerLib ├── .gitignore ├── .idea │ ├── .gitignore │ ├── misc.xml │ ├── modules.xml │ └── runConfigurations.xml ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── yc │ │ └── gallerypager │ │ ├── Constants.java │ │ ├── ImageFragment.java │ │ ├── MediaInfo.java │ │ ├── SafeViewPager.java │ │ ├── ScrollGalleryView.java │ │ ├── SlidePagerAdapter.java │ │ ├── VideoPlayActivity.java │ │ ├── builder │ │ ├── BasicMediaHelper.java │ │ └── GallerySettings.java │ │ ├── impl │ │ ├── GalleryBuilderImpl.java │ │ └── SettingsBuilderImpl.java │ │ ├── inter │ │ ├── IGalleryBuilder.java │ │ ├── IMediaHelper.java │ │ ├── IMediaLoader.java │ │ └── ISettingsBuilder.java │ │ └── loader │ │ ├── DefaultImageLoader.java │ │ └── DefaultVideoLoader.java │ └── res │ ├── drawable-hdpi │ ├── placeholder_image.png │ └── placeholder_video.png │ ├── drawable-xhdpi │ ├── placeholder_image.png │ └── placeholder_video.png │ ├── drawable-xxhdpi │ ├── placeholder_image.png │ └── placeholder_video.png │ ├── drawable-xxxhdpi │ ├── placeholder_image.png │ └── placeholder_video.png │ ├── layout │ ├── image_fragment.xml │ ├── scroll_gallery_view.xml │ └── video_fragment.xml │ ├── values-ru │ └── strings.xml │ └── values │ └── strings.xml ├── GalleryViewLib ├── .gitignore ├── README_CH.md ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── yc │ │ └── gallerylib │ │ ├── gallery │ │ ├── GalleryFragment.java │ │ ├── GalleryImageView.java │ │ ├── GalleryViewPager.java │ │ └── ViewPagerAdapter.java │ │ └── recyclerView │ │ ├── GalleryLayoutManager.java │ │ ├── GalleryRecyclerView.java │ │ └── OnGalleryListener.java │ └── res │ ├── layout │ ├── fragment_image_gallery.xml │ ├── view_scroll_gallery.xml │ └── view_zoom_load.xml │ └── values │ └── strings.xml ├── GrpcServer ├── .gitignore ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── yc │ └── grpcserver │ ├── BaseRequest.java │ ├── BaseResponse.java │ ├── ChannelHelper.java │ ├── GrpcCallback.java │ ├── GrpcChannelBuilder.java │ ├── GrpcHelper.java │ ├── GrpcStubManager.java │ ├── GrpcToolUtils.java │ ├── LoggingInterceptor.java │ ├── RequestInterceptor.java │ └── Tls12SocketFactory.java ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── assets │ └── yc.png │ ├── java │ └── com │ │ └── yc │ │ └── cn │ │ └── ycgallery │ │ ├── FirstActivity.java │ │ ├── FiveActivity.java │ │ ├── FourActivity.java │ │ ├── MainActivity.java │ │ ├── PicassoImageLoader.java │ │ ├── PicassoMediaHelper.java │ │ ├── SecondActivity.java │ │ ├── SnapAdapter.java │ │ ├── ThirdActivity.java │ │ └── animations │ │ ├── EnterScreenAnimations.java │ │ ├── ExitScreenAnimations.java │ │ ├── MatrixEvaluator.java │ │ ├── MatrixUtils.java │ │ ├── ScreenAnimation.java │ │ └── SimpleAnimationListener.java │ └── res │ ├── anim │ ├── screen_zoom_in.xml │ ├── screen_zoom_out.xml │ ├── slide_in_left.xml │ ├── slide_in_right.xml │ ├── slide_in_top.xml │ ├── slide_out_left.xml │ └── slide_out_right.xml │ ├── drawable-xhdpi │ ├── image1.jpg │ ├── image2.jpg │ ├── image3.png │ ├── image4.png │ ├── image5.png │ ├── image6.png │ ├── image7.png │ └── image8.png │ ├── drawable-xxhdpi │ ├── beauty1.jpg │ ├── beauty10.jpg │ ├── beauty11.jpg │ ├── beauty12.jpg │ ├── beauty13.jpg │ ├── beauty2.jpg │ ├── beauty3.jpg │ ├── beauty4.jpg │ ├── beauty5.jpg │ ├── beauty6.jpg │ ├── beauty7.jpg │ ├── beauty8.jpg │ └── beauty9.jpg │ ├── drawable │ └── shape_b3666666_bg_3.xml │ ├── layout │ ├── activity_first.xml │ ├── activity_five.xml │ ├── activity_four.xml │ ├── activity_main.xml │ ├── activity_second.xml │ ├── activity_third.xml │ └── item_snap.xml │ ├── menu │ └── menu_main.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ ├── default_video.png │ └── ic_launcher.png │ ├── transition │ └── activity_explode.xml │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── array.xml │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── yc.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # Intellij 36 | *.iml 37 | .idea/workspace.xml 38 | .idea/tasks.xml 39 | .idea/gradle.xml 40 | .idea/dictionaries 41 | .idea/libraries 42 | 43 | # Keystore files 44 | *.jks 45 | 46 | # External native build folder generated in Android Studio 2.2 and later 47 | .externalNativeBuild 48 | 49 | # Google Services (e.g. APIs or Firebase) 50 | google-services.json 51 | 52 | # Freeline 53 | freeline.py 54 | freeline/ 55 | freeline_project_description.json 56 | .idea/ 57 | .gradle/ 58 | -------------------------------------------------------------------------------- /AppGrpc/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /AppGrpc/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'com.google.protobuf' 3 | //apply from: rootProject.projectDir.absolutePath + "/yc.gradle" 4 | 5 | android { 6 | compileSdkVersion rootProject.ext.android["compileSdkVersion"] 7 | //buildToolsVersion rootProject.ext.android["buildToolsVersion"] 8 | defaultConfig { 9 | minSdkVersion rootProject.ext.android["minSdkVersion"] 10 | targetSdkVersion rootProject.ext.android["targetSdkVersion"] 11 | versionCode rootProject.ext.android["versionCode"] 12 | versionName rootProject.ext.android["versionName"] 13 | applicationId "com.yc.appgrpc" 14 | // dex突破65535的限制 15 | multiDexEnabled true 16 | } 17 | 18 | buildTypes { 19 | debug { minifyEnabled false } 20 | release { 21 | minifyEnabled true 22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | lintOptions { 26 | disable 'GoogleAppIndexingWarning', 'HardcodedText', 'InvalidPackage' 27 | textReport true 28 | textOutput "stdout" 29 | } 30 | 31 | compileOptions { 32 | sourceCompatibility JavaVersion.VERSION_1_8 33 | targetCompatibility JavaVersion.VERSION_1_8 34 | } 35 | 36 | packagingOptions { 37 | exclude 'META-INF/*******' 38 | exclude 'META-INF/INDEX.LIST' 39 | } 40 | } 41 | 42 | protobuf { 43 | protoc { 44 | // 相当于proto编译器 45 | artifact = 'com.google.protobuf:protoc:3.22.3' 46 | } 47 | plugins { 48 | // grpc单独的编译器 49 | grpc { 50 | artifact = 'io.grpc:protoc-gen-grpc-java:1.19.0' 51 | } 52 | // 官方推荐的方法,Android 适用javalite,相较于java插件,生成的代码更轻量化 53 | //javalite {artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'} 54 | } 55 | generateProtoTasks { 56 | all().each { task -> 57 | task.builtins { 58 | java { option 'lite' } 59 | } 60 | task.plugins { 61 | grpc { // Options added to --grpc_out 62 | option 'lite' 63 | } 64 | } 65 | } 66 | } 67 | } 68 | 69 | 70 | dependencies { 71 | implementation fileTree(dir: 'libs', include: ['*.jar']) 72 | implementation rootProject.ext.dependencies["appcompat"] 73 | implementation rootProject.ext.dependencies["annotation"] 74 | implementation(rootProject.ext.dependencies["constraintlayout"]) 75 | implementation rootProject.ext.dependencies["gson"] 76 | implementation 'com.github.yangchong211.YCWidgetLib:RoundCorners:1.0.6' 77 | implementation project(path: ':GrpcServer') 78 | implementation 'com.github.yangchong211.YCDialog:ToastUtils:3.6.9' 79 | //工具类utils 80 | implementation 'com.github.yangchong211.YCCommonLib:ToolUtilsLib:1.4.9' 81 | 82 | //protobuf 83 | implementation 'io.grpc:grpc-netty:1.33.0' 84 | implementation 'io.grpc:grpc-okhttp:1.33.0' 85 | implementation 'io.grpc:grpc-protobuf-lite:1.33.0' 86 | implementation 'io.grpc:grpc-stub:1.33.0' 87 | implementation 'org.apache.tomcat:annotations-api:6.0.53' 88 | } 89 | -------------------------------------------------------------------------------- /AppGrpc/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /AppGrpc/src/main/java/com/yc/appgrpc/GreeterActivity.java: -------------------------------------------------------------------------------- 1 | package com.yc.appgrpc; 2 | 3 | import android.content.BroadcastReceiver; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.content.IntentFilter; 7 | import android.os.Bundle; 8 | import android.text.method.ScrollingMovementMethod; 9 | import android.util.Log; 10 | import android.view.View; 11 | import android.widget.Button; 12 | import android.widget.TextView; 13 | 14 | import androidx.appcompat.app.AppCompatActivity; 15 | 16 | public class GreeterActivity extends AppCompatActivity { 17 | 18 | private final String TAG = MainActivity.class.toString(); 19 | private TextView text_info; 20 | // 服务端和客户端 21 | private GRPCClient grpcClient; 22 | 23 | public static void startActivity(Context context) { 24 | try { 25 | Intent target = new Intent(); 26 | target.setClass(context, GreeterActivity.class); 27 | target.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 28 | context.startActivity(target); 29 | } catch (Exception e) { 30 | e.printStackTrace(); 31 | } 32 | } 33 | 34 | @Override 35 | protected void onCreate(Bundle savedInstanceState) { 36 | super.onCreate(savedInstanceState); 37 | setContentView(R.layout.activity_greeter); 38 | // 初始化控件 39 | initView(); 40 | // 注册广播接收器 41 | register(); 42 | // 初始化服务端和客户端 43 | grpcClient = new GRPCClient(GreeterActivity.this); 44 | GRPCServer grpcServer = new GRPCServer(GreeterActivity.this); 45 | } 46 | 47 | // 初始化控件 48 | private void initView() { 49 | Button button1 = findViewById(R.id.button1); 50 | button1.setOnClickListener(v -> grpcClient.simpleHello()); 51 | Button button2 = findViewById(R.id.button2); 52 | button2.setOnClickListener(v -> grpcClient.clientStream()); 53 | Button button3 = findViewById(R.id.button3); 54 | button3.setOnClickListener(v -> grpcClient.serverStream()); 55 | Button button4 = findViewById(R.id.button4); 56 | button4.setOnClickListener(v -> grpcClient.bothFlowStream()); 57 | text_info = findViewById(R.id.text_info); 58 | text_info.setMovementMethod(new ScrollingMovementMethod()); 59 | } 60 | 61 | // 注册广播更新ui 62 | private void register() { 63 | // 注册一个广播用于更新ui 64 | BroadcastReceiver broadcastReceiver = new BroadcastReceiver() { 65 | @Override 66 | public void onReceive(Context context, Intent intent) { 67 | Log.d(TAG, "广播收到消息" + intent.getStringExtra("info")); 68 | text_info.append(intent.getStringExtra("info") + "\n"); 69 | } 70 | }; 71 | IntentFilter filter = new IntentFilter("main.info"); 72 | registerReceiver(broadcastReceiver, filter); 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /AppGrpc/src/main/java/com/yc/appgrpc/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.yc.appgrpc; 2 | 3 | import androidx.appcompat.app.AppCompatActivity; 4 | 5 | import android.os.Bundle; 6 | import android.view.View; 7 | 8 | import com.yc.roundcorner.view.RoundTextView; 9 | import com.yc.toastutils.ToastUtils; 10 | 11 | public class MainActivity extends AppCompatActivity { 12 | 13 | private RoundTextView tvRpc1; 14 | private RoundTextView tvRpc2; 15 | 16 | @Override 17 | protected void onCreate(Bundle savedInstanceState) { 18 | super.onCreate(savedInstanceState); 19 | setContentView(R.layout.activity_rpc_main); 20 | tvRpc1 = findViewById(R.id.tv_rpc_1); 21 | tvRpc2 = findViewById(R.id.tv_rpc_2); 22 | tvRpc1.setOnClickListener(new View.OnClickListener() { 23 | @Override 24 | public void onClick(View v) { 25 | GreeterActivity.startActivity(MainActivity.this); 26 | } 27 | }); 28 | tvRpc2.setOnClickListener(new View.OnClickListener() { 29 | @Override 30 | public void onClick(View v) { 31 | ToastUtils.showRoundRectToast("效率测试"); 32 | new ProtoJsonTest.JsonProtoTest().gson(); 33 | new ProtoJsonTest.JsonProtoTest().protoTest(); 34 | new ProtoJsonTest.JsonProtoTest().testSearchRequest(); 35 | } 36 | }); 37 | } 38 | } -------------------------------------------------------------------------------- /AppGrpc/src/main/proto/efficient_test.proto: -------------------------------------------------------------------------------- 1 | //版本:默认为proto2,也可以为proto3 2 | syntax = "proto3"; 3 | 4 | //相当于命名空间 5 | package tutorial; 6 | 7 | option java_package = "com.yc.appgrpc"; 8 | //java_package 就是生成我们.java文件的包名 9 | option java_outer_classname = "AddressBookProto"; 10 | //java_outer_classname也就是我们把.proto编译成.java后的名字(即AddressBookProto.java) 11 | 12 | //Person 类,消息结构 13 | message Person { 14 | string name = 1; 15 | //这里的required 的修饰符表示候name必须赋值(没有默认值) 16 | int32 id = 2; 17 | string email = 3; 18 | //optional 也就是可不赋值, proto3中已移除该关键字 19 | //当然optional string email = 3;[default = 0]默认值是0 20 | //required和optional可以有默认值 21 | 22 | //枚举定义 23 | enum PhoneType { 24 | MOBILE = 0; 25 | HOME = 1; 26 | WORK = 2; 27 | } 28 | 29 | //结构体、类,统一定义为 message实际上是嵌套类 30 | message PhoneNumber { 31 | string number = 1; 32 | PhoneType type = 2; 33 | } 34 | 35 | //repeated 表示词字段可以出现多次 36 | repeated PhoneNumber phones = 4; 37 | } 38 | 39 | //AddressBook 类 40 | message AddressBook { 41 | repeated Person people = 1; 42 | } 43 | 44 | message SearchRequest { 45 | string query = 1; 46 | int32 page_number = 2; 47 | int32 result_per_page = 3; 48 | } -------------------------------------------------------------------------------- /AppGrpc/src/main/proto/greeter.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The gRPC Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | 16 | 17 | //protobuf 有2个版本,语法不同,默认版本是 proto2 18 | //如果需要 proto3,则需要在非空非注释第一行使用 syntax = "proto3" 标明版本。现在推荐使用proto3版本。 19 | syntax = "proto3"; 20 | option java_multiple_files = true; 21 | //这指定了我们要用于生成的 Java 类的包。如果java_package.proto 文件中没有给出明确的选项,那么默认情况下将使用 proto 包(使用“package”关键字指定)。 22 | //但是,proto 包通常不会成为好的 Java 包,因为 proto 包不应该以反向域名开头。如果我们从这个 .proto 生成另一种语言的代码,则该java_package选项无效。 23 | option java_package = "com.yc.appgrpc"; 24 | option java_outer_classname = "GreeterProto"; 25 | option objc_class_prefix = "HLW"; 26 | 27 | //proto文件上方定义了package,调用方不可以更改此路径!!! 28 | package greeter; 29 | 30 | //这个是定义的服务接口 31 | //当您构建示例时,构建过程会重新生成GreeterGrpc.java,其中包含生成的 gRPC 客户端和服务器类。 32 | //这也会重新生成用于填充、序列化和检索我们的请求和响应类型的类。 33 | service Greeter { 34 | // 简单一元模式 35 | // 一个简单的 RPC,其中客户端使用存根向服务器发送请求并等待响应返回,就像普通的函数调用一样。 36 | rpc simpleHello (Request) returns (Reply) {} 37 | // 客户端流模式 38 | // 客户端流式 RPC,客户端写入一系列消息并将它们发送到服务器,再次使用提供的流。 39 | // 客户端写完消息后,它会等待服务器读取所有消息并返回响应。您可以通过将关键字放在请求stream类型之前来指定客户端流式传输方法。 40 | rpc clientStream (stream Request) returns (Reply) {} 41 | // 服务端流模式 42 | // 服务器端流式 RPC,客户端向服务器发送请求并获取流以读取一系列消息。 43 | // 客户端从返回的流中读取,直到没有更多消息为止。正如您在我们的示例中看到的,您通过将关键字放在响应stream类型 之前来指定服务器端流式传输方法。 44 | rpc serverStream (Request) returns (stream Reply) {} 45 | // 双向流模式 46 | // 双向流式 RPC,双方使用读写流发送一系列消息。 47 | // 这两个流独立运行,因此客户端和服务器可以按照他们喜欢的任何顺序读取和写入: 48 | // 例如,服务器可以在写入响应之前等待接收所有客户端消息,或者它可以交替读取一条消息然后写入一条消息,或其他一些读写组合。 49 | // 保留每个流中消息的顺序。stream 您可以通过将关键字放在请求和响应之前来指定这种类型的方法。 50 | rpc bothFlowStream (stream Request) returns (stream Reply) {} 51 | } 52 | 53 | message Request { 54 | string reqInfo = 1; 55 | } 56 | 57 | message Reply { 58 | string repInfo = 1; 59 | } 60 | -------------------------------------------------------------------------------- /AppGrpc/src/main/proto/hello_world.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The gRPC Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | 16 | 17 | //protobuf 有2个版本,语法不同,默认版本是 proto2 18 | //如果需要 proto3,则需要在非空非注释第一行使用 syntax = "proto3" 标明版本。现在推荐使用proto3版本。 19 | syntax = "proto3"; 20 | option java_multiple_files = true; 21 | //这指定了我们要用于生成的 Java 类的包。如果java_package.proto 文件中没有给出明确的选项,那么默认情况下将使用 proto 包(使用“package”关键字指定)。 22 | //但是,proto 包通常不会成为好的 Java 包,因为 proto 包不应该以反向域名开头。如果我们从这个 .proto 生成另一种语言的代码,则该java_package选项无效。 23 | option java_package = "com.yc.appgrpc"; 24 | option java_outer_classname = "HelloWorldProto"; 25 | option objc_class_prefix = "HLW"; 26 | 27 | //proto文件上方定义了package,调用方不可以更改此路径!!! 28 | package helloworld; 29 | 30 | //这个是定义的服务接口 31 | //当您构建示例时,构建过程会重新生成GreeterGrpc.java,其中包含生成的 gRPC 客户端和服务器类。 32 | //这也会重新生成用于填充、序列化和检索我们的请求和响应类型的类。 33 | service HelloWorld { 34 | rpc SayHello (HelloRequest) returns (HelloReply) {} 35 | } 36 | 37 | 38 | //关键字message: 代表了实体结构,由多个消息字段(field)组成。 39 | //这个是发送的request 40 | message HelloRequest { 41 | //消息字段(field): 包括数据类型、字段名、字段规则、字段唯一标识、默认值 42 | //数据类型:常见的原子类型都支持(在FieldDescriptor::kTypeToName中有定义) 43 | //字段规则:(在FieldDescriptor::kLabelToName中定义) 44 | //required:必须初始化字段,如果没有赋值,在数据序列化时会抛出异常 45 | //optional:可选字段,可以不必初始化。 46 | //repeated:数据可以重复(相当于java 中的Array或List) 47 | //字段唯一标识:序列化和反序列化将会使用到。 48 | //默认值:在定义消息字段时可以给出默认值。 49 | string name = 1; 50 | } 51 | 52 | //这个是收到的respond 53 | message HelloReply { 54 | string message = 1; 55 | } 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /AppGrpc/src/main/proto/msg_test.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package msg; 3 | option java_package = "com.yc.appgrpc"; 4 | option java_outer_classname = "MsgProto"; 5 | 6 | message Msg { 7 | string text = 1; 8 | } -------------------------------------------------------------------------------- /AppGrpc/src/main/res/layout/activity_greeter.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 11 |