Skip to content

Commit 7d6cd63

Browse files
committed
Added stream serialization for Multihash
1 parent 3749171 commit 7d6cd63

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/main/java/org/ipfs/api/Multihash.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,19 @@ public byte[] toBytes() {
5656
return res;
5757
}
5858

59+
public void serialize(DataOutput dout) throws IOException {
60+
dout.write(toBytes());
61+
}
62+
63+
public static Multihash deserialize(DataInput din) throws IOException {
64+
int type = din.readUnsignedByte();
65+
int len = din.readUnsignedByte();
66+
Type t = Type.lookup(type);
67+
byte[] hash = new byte[len];
68+
din.readFully(hash);
69+
return new Multihash(t, hash);
70+
}
71+
5972
@Override
6073
public String toString() {
6174
return toBase58();

0 commit comments

Comments
 (0)