Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
DifferentSC committed Sep 19, 2014
2 parents bf714e7 + 9ef476f commit d6e6c42
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.microsoft.tang.implementation.protobuf;

import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -171,19 +172,46 @@ private static ClassHierarchyProto.Node serializeNode(Node n) {
} else {
throw new IllegalStateException("Encountered unknown type of Node: " + n);
}

}

/**
* Serialize a class hierarchy into a protocol buffer object.
* @param classHierarchy
* @return
*/

public static ClassHierarchyProto.Node serialize(ClassHierarchy classHierarchy) {
return serializeNode(classHierarchy.getNamespace());
}

/**
* serialize a class hierarchy into a file
* @param fileName
* @param classHierarchy
* @throws IOException
*/
public static void serialize(final String fileName, final ClassHierarchy classHierarchy) throws IOException {
final ClassHierarchyProto.Node node = serializeNode(classHierarchy.getNamespace());
final FileOutputStream output = new FileOutputStream(fileName);
final DataOutputStream dos = new DataOutputStream(output);
node.writeTo(dos);
dos.close();
output.close();
}

/**
* Deserialize a class hierarchy from a file. The file can be generated from either Java or C#
* @param fileName
* @return
* @throws IOException
*/
public static ClassHierarchy deserialize(final String fileName) throws IOException {
final InputStream stream = new FileInputStream(fileName);

final ClassHierarchyProto.Node root = ClassHierarchyProto.Node.parseFrom(stream);

return new ProtocolBufferClassHierarchy(root);
}

/**
* Deserialize a class hierarchy from a protocol buffer object. The resulting
* object is immutable, and does not make use of reflection to fill in any
Expand Down
Loading

0 comments on commit d6e6c42

Please sign in to comment.