1111
1212public class Leb128Serializer {
1313
14- public static List <byte []> deserialize (byte [] serializedUids ) {
15- List <byte []> uids = new ArrayList <byte []>();
14+ public static List <byte []> deserializeList (byte [] serializedUids ) {
15+ List <byte []> result = new ArrayList <byte []>();
1616 ByteArrayByteInput in = new ByteArrayByteInput (serializedUids );
1717 int len = 0 ;
1818 while ((len = Leb128 .readUnsignedLeb128 (in )) >= 0 ) {
1919 if (len == 0 ) {
2020 break ;
2121 }
22- byte [] uid = new byte [len ];
22+ byte [] element = new byte [len ];
2323 for (int i = 0 ; i < len ; i ++) {
24- uid [i ] = in .readByte ();
24+ element [i ] = in .readByte ();
2525 }
26- uids .add (uid );
26+ result .add (element );
2727 }
28- return uids ;
28+ return result ;
2929 }
3030
31- public static byte [] serialize (HashMap <byte [], byte []> uidsAndValues ) {
31+ public static HashMap <byte [], byte []> deserializeHashmap (byte [] serializedUids ) {
32+ HashMap <byte [], byte []> result = new HashMap <byte [], byte []>();
33+ ByteArrayByteInput in = new ByteArrayByteInput (serializedUids );
34+ int len = 0 ;
35+ while ((len = Leb128 .readUnsignedLeb128 (in )) >= 0 ) {
36+ if (len == 0 ) {
37+ break ;
38+ }
39+ byte [] key = new byte [len ];
40+ for (int i = 0 ; i < len ; i ++) {
41+ key [i ] = in .readByte ();
42+ }
43+
44+ len = Leb128 .readUnsignedLeb128 (in );
45+ if (len == 0 ) {
46+ throw new IllegalArgumentException ("HashMap `value` should be serialized after `key`" );
47+ }
48+ byte [] value = new byte [len ];
49+ for (int i = 0 ; i < len ; i ++) {
50+ value [i ] = in .readByte ();
51+ }
52+ result .put (key , value );
53+ }
54+ return result ;
55+ }
56+
57+ public static byte [] serializeHashMap (HashMap <byte [], byte []> uidsAndValues ) {
3258 ByteArrayAnnotatedOutput out = new ByteArrayAnnotatedOutput ();
3359 for (Entry <byte [], byte []> entry : uidsAndValues .entrySet ()) {
3460 byte [] uid = entry .getKey ();
@@ -45,7 +71,7 @@ public static byte[] serialize(HashMap<byte[], byte[]> uidsAndValues) {
4571 return uidsAndValuesBytes ;
4672 }
4773
48- public static byte [] serialize (List <byte []> values ) {
74+ public static byte [] serializeList (List <byte []> values ) {
4975 ByteArrayAnnotatedOutput out = new ByteArrayAnnotatedOutput ();
5076 for (byte [] bs : values ) {
5177 Leb128 .writeUnsignedLeb128 (out , bs .length );
0 commit comments