论坛首页 Java企业应用论坛

结合FastJSON的设计 + protocol buffer协议的 java序列化组件

浏览 3478 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2012-10-16   最后修改:2012-10-16
    由于温少开源的FastJSON非常优秀,但由于JSON本身协议是需要传输属性名等字符串的,这就使得它在java系统间作为通讯或磁盘存储的序列化方案,就显得不合适了。所以,结合FastJSON的设计 + protocol buffer做了个序列化小东西(glowworm)。
1.它的调用非常简单:
  TP tmpTP = new TP();
   … …
  // 序列化
  byte[] tmpBytes = PB.toPBBytes(tmpTP);
  // 反序列化
  TP tmpTP_2 = (TP)PB.parsePBBytes(tmpBytes, TP.class);
2.目前支持的类型包括:
Map, HashMap, LinkedHashMap, TreeMap, ConcurrentMap, ConcurrentHashMap, Collection, List, ArrayList, Object, String,char, Character, byte, Byte, short, Short, int, Integer, float, Float, double, Double, long, Long, boolean, Boolean,byte[], short[], int[], long[].class, float[], double[], boolean[], char[], Object[]
   作为早期版本,目前还不支持循环引用、引用、自定义输出格式等功能,但作为一个基本的二进制序列化工具,还是有它适用的场合。附件是jar包
   发表时间:2012-10-16  
这个和Serializable 有什么区别..???除了他不支持的外
0 请登录后投票
   发表时间:2012-10-17   最后修改:2012-10-17
    目前在项目中实际使用场景是可以非常简单的把普通javaBean放进redis里,一般都能节省60%以上的内存空间。虽然它还不完善,有许多功能需要完善,但对那些需要迫切解决序列化的大小和性能的场合,是有用途的。已经可以序列化像下面这样复杂的类:
public class TP_Magic
{
private String s1;
private Integer i1;
private Double d1;
private String d2;
private Boolean theBn1;
private Boolean theBn2;
private boolean theb2;
private Long l1;
private long l_1_2;
private int[] theI_Array;
private List theList;
private Object[] theObjs;
private HashMap theHMap;
private LinkedHashMap theLinkHMap;
private ConcurrentHashMap theConHMap;
private byte thebyte_b;
private Byte theByte_Byte;
private long[] theLongs;
private char theChar;
private Character theChar_2;
private char[] theChars;
private double[] theDous;
private ArrayList<Double> theDList;
private ArrayList<Integer> theIList;
private ArrayList<String> theSList;
private ArrayList<RuleItem> theRuleItemList;
private LinkedList theRuleItemLinkedList;
private byte[] thebytes;
private HashSet theHSet;
private HashSet<String> theHStringSet;
private TreeSet theTreeSet;
private short[] theShort;
private float[] theFloats;
private boolean[] theBooleans;
private short theShortOne;
private float theFloatOne;
private My_InnerClass theMy_InnerClass;
       
        ...
}

0 请登录后投票
   发表时间:2012-10-22  
源码已经开源在git上,https://github.com/netcomm/glowWorm。如果发现任何bug,请联系我。
0 请登录后投票
   发表时间:2012-10-29  
    增加toPBBytes_Compress和parsePBBytes_Compress两个方法,通过Snappy压缩算法使得byte大小进一步减少,效果明显。
0 请登录后投票
   发表时间:2012-10-29  
还是有市场的
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics