本文整理匯總了Java中com.google.protobuf.GeneratedMessage.GeneratedExtension方法的典型用法代碼示例。如果您正苦於以下問題:Java GeneratedMessage.GeneratedExtension方法的具體用法?Java GeneratedMessage.GeneratedExtension怎麽用?Java GeneratedMessage.GeneratedExtension使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.protobuf.GeneratedMessage
的用法示例。
在下文中一共展示了GeneratedMessage.GeneratedExtension方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: registerStorageFormat
import com.google.protobuf.GeneratedMessage; //導入方法依賴的package包/類
/** Register a new {@link StorageFormat}.
* @param protobufExtension the extension field that keys use of this format
* @param sqlIdentifier the <code>STORAGE_FORMAT</code> identifier that keys use of this format or <code>null</code>
* @param descriptionClass that specific class used to hold this format
* @param storageFormat the mapping handler
*/
public <T extends StorageDescription> void registerStorageFormat(GeneratedMessage.GeneratedExtension<Storage,?> protobufExtension, String sqlIdentifier, Class<T> descriptionClass, StorageFormat<T> storageFormat) {
int fieldNumber = protobufExtension.getDescriptor().getNumber();
if (formatsByField.containsKey(fieldNumber))
throw new IllegalArgumentException("there is already a StorageFormat registered for field " + fieldNumber);
if ((sqlIdentifier != null) &&
formatsByIdentifier.containsKey(sqlIdentifier))
throw new IllegalArgumentException("there is already a StorageFormat registered for STORAGE_FORMAT " + sqlIdentifier);
if (!isDescriptionClassAllowed(descriptionClass)) {
throw new IllegalArgumentException("description " + descriptionClass + " not allowed for " + getClass().getSimpleName());
}
extensionRegistry.add(protobufExtension);
Format<T> format = new Format<T>(protobufExtension, sqlIdentifier, descriptionClass, storageFormat);
formatsInOrder.add(format);
formatsByField.put(fieldNumber, format);
if (sqlIdentifier != null) {
formatsByIdentifier.put(sqlIdentifier, format);
}
}
示例2: add
import com.google.protobuf.GeneratedMessage; //導入方法依賴的package包/類
public ProtobufExtensionLookup add(Class<?> parent) {
// find all the generated service extensions for the class specified
for (Field field : parent.getFields()) {
// skip anything that isn't a generated extension. should be fine as long as we dont start
// mucking around with class loaders
if (field.getType() != GeneratedMessage.GeneratedExtension.class) {
continue;
}
try {
GeneratedMessage.GeneratedExtension extension =
(GeneratedMessage.GeneratedExtension) field.get(parent);
Message defaultMessageInst = extension.getMessageDefaultInstance();
this.fields.put(defaultMessageInst.getClass(), extension);
} catch (IllegalAccessException e) {
LOG.warn("Could not not access " + field + " for " + parent);
}
}
return this;
}
示例3: Format
import com.google.protobuf.GeneratedMessage; //導入方法依賴的package包/類
public Format(GeneratedMessage.GeneratedExtension<Storage,?> protobufExtension, String sqlIdentifier, Class<T> descriptionClass, StorageFormat<T> storageFormat) {
this.protobufExtension = protobufExtension;
this.sqlIdentifier = sqlIdentifier;
this.descriptionClass = descriptionClass;
this.storageFormat = storageFormat;
}
示例4: getExtension
import com.google.protobuf.GeneratedMessage; //導入方法依賴的package包/類
public GeneratedMessage.GeneratedExtension getExtension(Message message) {
return fields.get(message.getClass());
}
示例5: translate
import com.google.protobuf.GeneratedMessage; //導入方法依賴的package包/類
/**
* Translate from the external RPC message to the actual message embedded as an extension in
* the Rpc message
*
* @param receivedMessage generic RPC received
* @param prototype prototype of the message that we expect to receive
* @return the twice wrapped underlying rpc message
*/
public Message translate(Rpc rpc, Message prototype) {
// unwrap the underlying message, which should be bound to one of the extensions
GeneratedMessage.GeneratedExtension<RpcMessages.Rpc, Message> responseExtension =
extensions.getExtension(prototype);
return rpc.getExtension(responseExtension);
}