Search in sources :

Example 1 with Message

use of io.protostuff.compiler.model.Message in project java-chassis by ServiceComb.

the class OperationProtobuf method initRequestCodec.

private void initRequestCodec(ScopedProtobufSchemaManager scopedProtobufSchemaManager, Invocation invocation) {
    ProtoMapper mapper = scopedProtobufSchemaManager.getOrCreateProtoMapper(invocation.getSchemaMeta());
    Message requestMessage = mapper.getRequestMessage(invocation.getOperationMeta().getOperationId());
    if (!invocation.isConsumer()) {
        initProducerRequestCodec(invocation, requestMessage, mapper);
    } else {
        initConsumerRequestCodec(invocation, requestMessage, mapper);
    }
}
Also used : Message(io.protostuff.compiler.model.Message) ProtoMapper(org.apache.servicecomb.foundation.protobuf.ProtoMapper)

Example 2 with Message

use of io.protostuff.compiler.model.Message in project java-chassis by ServiceComb.

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);
    };
}
Also used : SchemaWriter(io.protostuff.SchemaWriter) WireFormat(io.protostuff.WireFormat) OutputEx(io.protostuff.OutputEx) SchemaEx(io.protostuff.SchemaEx) ProtoMapper(org.apache.servicecomb.foundation.protobuf.ProtoMapper) IOException(java.io.IOException) InputEx(io.protostuff.InputEx) Type(java.lang.reflect.Type) TypeFactory(com.fasterxml.jackson.databind.type.TypeFactory) ProtoConst(org.apache.servicecomb.foundation.protobuf.internal.ProtoConst) Map(java.util.Map) RootDeserializer(org.apache.servicecomb.foundation.protobuf.RootDeserializer) Message(io.protostuff.compiler.model.Message) ConcurrentHashMapEx(org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx) JavaType(com.fasterxml.jackson.databind.JavaType) RootSerializer(org.apache.servicecomb.foundation.protobuf.RootSerializer) PropertyWrapper(org.apache.servicecomb.foundation.protobuf.internal.bean.PropertyWrapper) Message(io.protostuff.compiler.model.Message) RootSerializer(org.apache.servicecomb.foundation.protobuf.RootSerializer)

Example 3 with Message

use of io.protostuff.compiler.model.Message in project java-chassis by ServiceComb.

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();
}
Also used : Enum(io.protostuff.compiler.model.Enum) Import(io.protostuff.compiler.model.Import) Message(io.protostuff.compiler.model.Message) Service(io.protostuff.compiler.model.Service)

Example 4 with Message

use of io.protostuff.compiler.model.Message in project java-chassis by ServiceComb.

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());
}
Also used : Field(io.protostuff.compiler.model.Field) Message(io.protostuff.compiler.model.Message)

Example 5 with Message

use of io.protostuff.compiler.model.Message in project incubator-servicecomb-java-chassis by apache.

the class OperationProtobuf method initRequestCodec.

private void initRequestCodec(ScopedProtobufSchemaManager scopedProtobufSchemaManager, Invocation invocation) {
    ProtoMapper mapper = scopedProtobufSchemaManager.getOrCreateProtoMapper(invocation.getSchemaMeta());
    Message requestMessage = mapper.getRequestMessage(invocation.getOperationMeta().getOperationId());
    if (!invocation.isConsumer()) {
        initProducerRequestCodec(invocation, requestMessage, mapper);
    } else {
        initConsumerRequestCodec(invocation, requestMessage, mapper);
    }
}
Also used : Message(io.protostuff.compiler.model.Message) ProtoMapper(org.apache.servicecomb.foundation.protobuf.ProtoMapper)

Aggregations

Message (io.protostuff.compiler.model.Message)12 JavaType (com.fasterxml.jackson.databind.JavaType)6 ProtoMapper (org.apache.servicecomb.foundation.protobuf.ProtoMapper)6 TypeFactory (com.fasterxml.jackson.databind.type.TypeFactory)2 InputEx (io.protostuff.InputEx)2 OutputEx (io.protostuff.OutputEx)2 SchemaEx (io.protostuff.SchemaEx)2 SchemaWriter (io.protostuff.SchemaWriter)2 WireFormat (io.protostuff.WireFormat)2 Enum (io.protostuff.compiler.model.Enum)2 Field (io.protostuff.compiler.model.Field)2 Import (io.protostuff.compiler.model.Import)2 Service (io.protostuff.compiler.model.Service)2 IOException (java.io.IOException)2 Type (java.lang.reflect.Type)2 Map (java.util.Map)2 ConcurrentHashMapEx (org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx)2 RootDeserializer (org.apache.servicecomb.foundation.protobuf.RootDeserializer)2 RootSerializer (org.apache.servicecomb.foundation.protobuf.RootSerializer)2 ProtoConst (org.apache.servicecomb.foundation.protobuf.internal.ProtoConst)2