use of io.protostuff.compiler.model.Message in project incubator-servicecomb-java-chassis by apache.
the class ProtoToStringGenerator method fieldMapToString.
private void fieldMapToString(Field field, StringBuilder sb) {
Message entryMessage = (Message) field.getType();
Field keyField = entryMessage.getField(1);
Field valueField = entryMessage.getField(2);
// map<string, string> name = 1;
appendLine(sb, "map<%s, %s> %s = %d;", keyField.getTypeName(), valueField.getTypeName(), field.getName(), field.getTag());
}
use of io.protostuff.compiler.model.Message in project incubator-servicecomb-java-chassis by apache.
the class ProtoToStringGenerator method protoToString.
public String protoToString() {
StringBuilder sb = new StringBuilder();
appendLine(sb, "syntax = \"%s\";", proto.getSyntax());
for (Import importValue : proto.getImports()) {
appendLine(sb, "import \"%s\";", importValue.getValue());
}
appendLine(sb, "package %s;\n", proto.getPackage().getValue());
for (Message message : proto.getMessages()) {
messageToString(message, sb);
}
for (Enum enumValue : proto.getEnums()) {
enumToString(enumValue, sb);
}
for (Service service : proto.getServices()) {
serviceToString(service, sb);
}
return sb.toString();
}
use of io.protostuff.compiler.model.Message in project incubator-servicecomb-java-chassis by apache.
the class AnyEntrySchema method createEntryWriter.
private SchemaWriter<Object> createEntryWriter(String actualTypeName, Object _value) {
Message message = protoMapper.getProto().getMessage(actualTypeName);
if (message == null) {
// not standard, protobuf can not support or not define this type , just extend
return this::jsonExtend;
}
// standard pack
RootSerializer valueSerializer = protoMapper.createRootSerializer(message, _value.getClass());
String valueCanonicalName = message.getCanonicalName();
return (output, value) -> {
standardPack(output, value, valueCanonicalName, valueSerializer);
};
}
use of io.protostuff.compiler.model.Message in project java-chassis by ServiceComb.
the class AnyEntrySchema method createRootDeserializerFromCanonicaName.
protected RootDeserializer<Object> createRootDeserializerFromCanonicaName(String msgCanonicalName) {
Message message = protoMapper.getMessageFromCanonicaName(msgCanonicalName);
if (message == null) {
throw new IllegalStateException("can not find proto message to create deserializer, name=" + msgCanonicalName);
}
JavaType javaType = protoMapper.getAnyTypes().getOrDefault(msgCanonicalName, constructRuntimeType(ProtoConst.MAP_TYPE));
return protoMapper.createRootDeserializer(message, javaType);
}
use of io.protostuff.compiler.model.Message in project java-chassis by ServiceComb.
the class OperationProtobuf method initResponseCodec.
private void initResponseCodec(ScopedProtobufSchemaManager scopedProtobufSchemaManager, Invocation invocation) {
ProtoMapper mapper = scopedProtobufSchemaManager.getOrCreateProtoMapper(invocation.getSchemaMeta());
Message responseMessage = mapper.getResponseMessage(invocation.getOperationMeta().getOperationId());
JavaType responseType = invocation.findResponseType(Status.OK.getStatusCode());
if (!invocation.isConsumer()) {
initProviderResponseCode(responseMessage, mapper, responseType);
} else {
initConsumerResponseCode(responseMessage, mapper, responseType);
}
anyResponseRootSerializer = new ResponseRootSerializer(mapper.createRootSerializer(ProtoConst.ANY, Object.class), false, true);
anyResponseRootDeserializer = new ResponseRootDeserializer<>(mapper.createRootDeserializer(ProtoConst.ANY, Object.class), false);
}
Aggregations