PageRenderTime 25ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/java/com/linbox/im/message/ByteCreator.java

https://gitlab.com/Mr.Tomato/linbox_server
Java | 35 lines | 22 code | 8 blank | 5 comment | 2 complexity | fbc224aaf9367e56e342a37f4806c352 MD5 | raw file
  1. package com.linbox.im.message;
  2. import com.alibaba.fastjson.JSON;
  3. import com.linbox.im.exceptions.IMException;
  4. import org.slf4j.Logger;
  5. import org.slf4j.LoggerFactory;
  6. /**
  7. * Created by lrsec on 7/4/15.
  8. *
  9. * 提供了消息体自生成可用于 netty 发送的 byte[] 的共更能
  10. */
  11. public class ByteCreator {
  12. private static Logger logger = LoggerFactory.getLogger(ByteCreator.class);
  13. public MessageWrapper toWrapper() {
  14. MessageWrapper wrapper = new MessageWrapper();
  15. RequestResponseType type = RequestResponseType.parse(this);
  16. if (type == null) {
  17. logger.error("无法解析当前类型 {}", this.getClass().getName());
  18. throw new IMException("无法解析当前类型 " + this.getClass().getName());
  19. }
  20. wrapper.type = type;
  21. wrapper.content = this;
  22. return wrapper;
  23. }
  24. public String toWrapperJson() {
  25. return JSON.toJSONString(toWrapper());
  26. }
  27. }