Toggle navigation
VA伐木累
社区
VA伐木累
Proxy
JSON
BASE64
MyGit
登录
注册
×
登录
邮箱
密码
忘记密码?
ProtoBuf和LomBox
•发布于
•作者
liuzy
•2119 次浏览
•最后一次编辑是
•来自
资讯
## ProtoBuf - 1.下载`protoc.exe`可执行程序直接解压到windows目录,[https://github.com/google/protobuf/releases](https://github.com/google/protobuf/releases) - 2.下载Eclipse插件`protobuf-dt` - 3.下载Eclipse插件`proto file editor`,高亮`proto文件`语法 - 4.在`src/main/java`下使用`protoc com/example/demo/proto/UserProto.proto --java_out=.`生成JAVA类 - 5.项目添加依赖,导入 ```xml
com.google.protobuf
protobuf-java
3.5.1
``` ## LomBox - 1.下载`lombox.jar`放入Eclipse目录,配置`eclipse.ini` ```ini -Xbootclasspath/a:lombok.jar -javaagent:lombok.jar ``` - 2.项目添加依赖使用lombox注解,导入 ```xml
org.projectlombok
lombok
``` ### xxx ```java package com.example.demo; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.nio.charset.StandardCharsets; import org.springframework.http.HttpInputMessage; import org.springframework.http.HttpOutputMessage; import org.springframework.http.MediaType; import org.springframework.http.converter.AbstractHttpMessageConverter; import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.http.converter.HttpMessageNotWritableException; import com.google.protobuf.GeneratedMessage; public class PBMessageConverter extends AbstractHttpMessageConverter
{ public PBMessageConverter() { super(new MediaType("application", "x-protobuf", StandardCharsets.UTF_8)); } @Override protected boolean supports(Class> clazz) { return GeneratedMessage.class.isAssignableFrom(clazz); } @Override protected GeneratedMessage readInternal(Class extends GeneratedMessage> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { try { Method parseMethod = clazz.getDeclaredMethod("parseFrom", InputStream.class); return (GeneratedMessage) parseMethod.invoke(clazz, inputMessage.getBody()); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } return null; } @Override protected void writeInternal(GeneratedMessage t, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { OutputStream os = outputMessage.getBody(); t.writeTo(os); os.flush(); os.close(); } @Override protected Long getContentLength(GeneratedMessage t, MediaType contentType) { return Long.valueOf(t.toByteArray().length); } } ```
0 回复
作者
liuzy
积分: 841
“ 黑眼圈圈男 ”
无人回复话题
SonarQube 9.4 + PostgreSQL
shell倒计时
日常网络巧技
使用ssh创建socks5代理服务
NodeJS集群demo
作者其他话题
SonarQube 9.4 + PostgreSQL
shell倒计时
日常网络巧技
使用ssh创建socks5代理服务
NodeJS集群demo
回到顶部
友情链接:
JFinal
©2015 Powered by
jfinalbbs
沪ICP备15012258号