use of net.morimekta.util.io.CountingOutputStream in project providence by morimekta.
the class JsonSerializer method serialize.
@Override
public <T extends PMessage<T, F>, F extends PField> int serialize(@Nonnull OutputStream output, @Nonnull T message) throws IOException {
CountingOutputStream counter = new CountingOutputStream(output);
JsonWriter jsonWriter = prettyPrint ? new PrettyJsonWriter(counter) : new JsonWriter(counter);
appendMessage(jsonWriter, message);
jsonWriter.flush();
counter.flush();
return counter.getByteCount();
}
use of net.morimekta.util.io.CountingOutputStream in project providence by morimekta.
the class JsonSerializer method serialize.
@Override
public <T extends PMessage<T, F>, F extends PField> int serialize(@Nonnull OutputStream output, @Nonnull PServiceCall<T, F> call) throws IOException {
CountingOutputStream counter = new CountingOutputStream(output);
JsonWriter jsonWriter = prettyPrint ? new PrettyJsonWriter(counter) : new JsonWriter(counter);
jsonWriter.array().value(call.getMethod());
if (enumValueType == IdType.ID) {
jsonWriter.value(call.getType().asInteger());
} else {
jsonWriter.valueUnescaped(call.getType().asString().toLowerCase(Locale.US));
}
jsonWriter.value(call.getSequence());
appendMessage(jsonWriter, call.getMessage());
jsonWriter.endArray().flush();
counter.flush();
return counter.getByteCount();
}
use of net.morimekta.util.io.CountingOutputStream in project providence by morimekta.
the class PrettySerializer method serialize.
@Override
public <Message extends PMessage<Message, Field>, Field extends PField> int serialize(@Nonnull OutputStream out, @Nonnull PServiceCall<Message, Field> call) throws IOException {
CountingOutputStream cout = new CountingOutputStream(out);
IndentedPrintWriter builder = new IndentedPrintWriter(cout, indent, newline);
if (call.getSequence() != 0) {
builder.format("%d: ", call.getSequence());
}
builder.format("%s %s", call.getType().asString().toLowerCase(Locale.US), call.getMethod()).begin(indent + indent);
appendMessage(builder, call.getMessage(), true);
builder.end().newline().flush();
return cout.getByteCount();
}
use of net.morimekta.util.io.CountingOutputStream in project providence by morimekta.
the class TTupleProtocolSerializer method serialize.
@Override
public <Message extends PMessage<Message, Field>, Field extends PField> int serialize(@Nonnull OutputStream output, @Nonnull PServiceCall<Message, Field> call) throws IOException {
CountingOutputStream wrapper = new CountingOutputStream(output);
TTransport transport = new TIOStreamTransport(wrapper);
try {
TTupleProtocol protocol = (TTupleProtocol) protocolFactory.getProtocol(transport);
TMessage tm = new TMessage(call.getMethod(), (byte) call.getType().asInteger(), call.getSequence());
protocol.writeMessageBegin(tm);
writeMessage(call.getMessage(), protocol);
protocol.writeMessageEnd();
transport.flush();
wrapper.flush();
return wrapper.getByteCount();
} catch (TException e) {
throw new SerializerException(e, e.getMessage());
}
}
use of net.morimekta.util.io.CountingOutputStream in project providence by morimekta.
the class PrettySerializer method serialize.
public <Message extends PMessage<Message, Field>, Field extends PField> int serialize(@Nonnull OutputStream out, @Nonnull Message message) {
CountingOutputStream cout = new CountingOutputStream(out);
IndentedPrintWriter builder = new IndentedPrintWriter(cout, indent, newline);
if (prefixWithQualifiedName) {
builder.append(message.descriptor().getQualifiedName()).append(space);
}
appendMessage(builder, message, false);
builder.flush();
return cout.getByteCount();
}
Aggregations