Search in sources :

Example 1 with BserSerializer

use of com.facebook.buck.bser.BserSerializer in project buck by facebook.

the class WatchmanTest method bserSerialized.

private static ByteBuffer bserSerialized(Object obj) throws IOException {
    ByteBuffer buf = ByteBuffer.allocate(256).order(ByteOrder.nativeOrder());
    ByteBuffer result = new BserSerializer().serializeToBuffer(obj, buf);
    // Prepare the buffer for reading.
    result.flip();
    return result;
}
Also used : BserSerializer(com.facebook.buck.bser.BserSerializer) ByteBuffer(java.nio.ByteBuffer)

Example 2 with BserSerializer

use of com.facebook.buck.bser.BserSerializer in project buck by facebook.

the class ProjectBuildFileParserTest method fakeProcessWithBserOutput.

private static FakeProcess fakeProcessWithBserOutput(int returnCode, List<Object> values, Optional<List<Object>> diagnostics, Optional<String> stdout) {
    BserSerializer bserSerializer = new BserSerializer();
    ByteBuffer buffer = ByteBuffer.allocate(512).order(ByteOrder.nativeOrder());
    try {
        Map<String, Object> outputToSerialize = new LinkedHashMap<>();
        outputToSerialize.put("values", values);
        if (diagnostics.isPresent()) {
            outputToSerialize.put("diagnostics", diagnostics.get());
        }
        buffer = bserSerializer.serializeToBuffer(outputToSerialize, buffer);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    buffer.flip();
    return new FakeProcess(returnCode, new ByteArrayOutputStream(), new ByteArrayInputStream(buffer.array()), new ByteArrayInputStream(stdout.orElse("").getBytes(StandardCharsets.UTF_8)));
}
Also used : BserSerializer(com.facebook.buck.bser.BserSerializer) ByteArrayInputStream(java.io.ByteArrayInputStream) FakeProcess(com.facebook.buck.util.FakeProcess) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteBuffer(java.nio.ByteBuffer) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

BserSerializer (com.facebook.buck.bser.BserSerializer)2 ByteBuffer (java.nio.ByteBuffer)2 FakeProcess (com.facebook.buck.util.FakeProcess)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 LinkedHashMap (java.util.LinkedHashMap)1