本文整理汇总了Java中com.google.protobuf.Descriptors类的典型用法代码示例。如果您正苦于以下问题:Java Descriptors类的具体用法?Java Descriptors怎么用?Java Descriptors使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Descriptors类属于com.google.protobuf包,在下文中一共展示了Descriptors类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: batchCoprocessorService
import com.google.protobuf.Descriptors; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public <R extends Message> Map<byte[], R> batchCoprocessorService(
Descriptors.MethodDescriptor methodDescriptor, Message request,
byte[] startKey, byte[] endKey, R responsePrototype) throws ServiceException, Throwable {
final Map<byte[], R> results = Collections.synchronizedMap(new TreeMap<byte[], R>(
Bytes.BYTES_COMPARATOR));
batchCoprocessorService(methodDescriptor, request, startKey, endKey, responsePrototype,
new Callback<R>() {
@Override
public void update(byte[] region, byte[] row, R result) {
if (region != null) {
results.put(region, result);
}
}
});
return results;
}
示例2: decodeProtobuf
import com.google.protobuf.Descriptors; //导入依赖的package包/类
/**
* Handle all the logic leading to the decoding of a Protobuf-encoded binary given a schema file path.
* @param schema Schema used to decode the binary data
* @param messageType Type of Protobuf Message
* @param encodedData Encoded data source
* @return A JSON representation of the data, contained in a Java String
* @throws InvalidProtocolBufferException Thrown when an error occurs during the encoding of the decoded data into JSON
* @throws Descriptors.DescriptorValidationException Thrown when the schema is invalid
* @throws UnknownMessageTypeException Thrown when the given message type is not contained in the schema
* @throws MessageDecodingException Thrown when an error occurs during the binary decoding
* @throws SchemaLoadingException Thrown when an error occurs while reading the schema file
*/
public static String decodeProtobuf(DynamicSchema schema, String messageType, InputStream encodedData) throws InvalidProtocolBufferException, Descriptors.DescriptorValidationException, UnknownMessageTypeException, MessageDecodingException, SchemaLoadingException {
Descriptors.Descriptor descriptor;
DynamicMessage message;
descriptor = schema.getMessageDescriptor(messageType);
if (descriptor == null) {
throw new UnknownMessageTypeException(messageType);
}
try {
message = DynamicMessage.parseFrom(descriptor, encodedData);
} catch (IOException e) {
throw new MessageDecodingException(e);
}
return JSONMapper.toJSON(message);
}
示例3: registerService
import com.google.protobuf.Descriptors; //导入依赖的package包/类
@Override
public boolean registerService(Service instance) {
/*
* No stacking of instances is allowed for a single service name
*/
Descriptors.ServiceDescriptor serviceDesc = instance.getDescriptorForType();
if (coprocessorServiceHandlers.containsKey(serviceDesc.getFullName())) {
LOG.error("Coprocessor service "+serviceDesc.getFullName()+
" already registered, rejecting request from "+instance
);
return false;
}
coprocessorServiceHandlers.put(serviceDesc.getFullName(), instance);
if (LOG.isDebugEnabled()) {
LOG.debug("Registered master coprocessor service: service="+serviceDesc.getFullName());
}
return true;
}
示例4: registerService
import com.google.protobuf.Descriptors; //导入依赖的package包/类
@Override public boolean registerService(Service instance) {
/*
* No stacking of instances is allowed for a single service name
*/
Descriptors.ServiceDescriptor serviceDesc = instance.getDescriptorForType();
if (coprocessorServiceHandlers.containsKey(serviceDesc.getFullName())) {
LOG.error("Coprocessor service " + serviceDesc.getFullName()
+ " already registered, rejecting request from " + instance);
return false;
}
coprocessorServiceHandlers.put(serviceDesc.getFullName(), instance);
if (LOG.isDebugEnabled()) {
LOG.debug(
"Registered regionserver coprocessor service: service=" + serviceDesc.getFullName());
}
return true;
}
示例5: registerService
import com.google.protobuf.Descriptors; //导入依赖的package包/类
@Override public boolean registerService(Service instance) {
/*
* No stacking of instances is allowed for a single service name
*/
Descriptors.ServiceDescriptor serviceDesc = instance.getDescriptorForType();
if (coprocessorServiceHandlers.containsKey(serviceDesc.getFullName())) {
LOG.error("Coprocessor service " + serviceDesc.getFullName()
+ " already registered, rejecting request from " + instance);
return false;
}
coprocessorServiceHandlers.put(serviceDesc.getFullName(), instance);
if (LOG.isDebugEnabled()) {
LOG.debug("Registered coprocessor service: region=" + Bytes
.toStringBinary(getRegionInfo().getRegionName()) + " service=" + serviceDesc
.getFullName());
}
return true;
}
示例6: AsyncCall
import com.google.protobuf.Descriptors; //导入依赖的package包/类
/**
* Constructor
*
* @param eventLoop for call
* @param connectId connection id
* @param md the method descriptor
* @param param parameters to send to Server
* @param controller controller for response
* @param responseDefaultType the default response type
*/
public AsyncCall(EventLoop eventLoop, int connectId, Descriptors.MethodDescriptor md, Message
param, PayloadCarryingRpcController controller, Message responseDefaultType,
MetricsConnection.CallStats callStats) {
super(eventLoop);
this.id = connectId;
this.method = md;
this.param = param;
this.controller = controller;
this.responseDefaultType = responseDefaultType;
this.startTime = EnvironmentEdgeManager.currentTime();
this.rpcTimeout = controller.hasCallTimeout() ? controller.getCallTimeout() : 0;
this.callStats = callStats;
}
示例7: callMethod
import com.google.protobuf.Descriptors; //导入依赖的package包/类
@Override
public void callMethod(Descriptors.MethodDescriptor md, RpcController controller,
Message param, Message returnType, RpcCallback<Message> done) {
PayloadCarryingRpcController pcrc;
if (controller != null) {
pcrc = (PayloadCarryingRpcController) controller;
if (!pcrc.hasCallTimeout()) {
pcrc.setCallTimeout(channelOperationTimeout);
}
} else {
pcrc = new PayloadCarryingRpcController();
pcrc.setCallTimeout(channelOperationTimeout);
}
this.rpcClient.callMethod(md, pcrc, param, returnType, this.ticket, this.isa, done);
}
示例8: callBlockingMethod
import com.google.protobuf.Descriptors; //导入依赖的package包/类
@Override
public Message callBlockingMethod(Descriptors.MethodDescriptor md, RpcController controller,
Message param, Message returnType) throws ServiceException {
PayloadCarryingRpcController pcrc;
if (controller != null && controller instanceof PayloadCarryingRpcController) {
pcrc = (PayloadCarryingRpcController) controller;
if (!pcrc.hasCallTimeout()) {
pcrc.setCallTimeout(channelOperationTimeout);
}
} else {
pcrc = new PayloadCarryingRpcController();
pcrc.setCallTimeout(channelOperationTimeout);
}
return this.rpcClient.callBlockingMethod(md, pcrc, param, returnType, this.ticket, this.isa);
}
示例9: callMethod
import com.google.protobuf.Descriptors; //导入依赖的package包/类
@Override
@InterfaceAudience.Private
public void callMethod(Descriptors.MethodDescriptor method,
RpcController controller,
Message request, Message responsePrototype,
RpcCallback<Message> callback) {
Message response = null;
try {
response = callExecService(controller, method, request, responsePrototype);
} catch (IOException ioe) {
LOG.warn("Call failed on IOException", ioe);
ResponseConverter.setControllerException(controller, ioe);
}
if (callback != null) {
callback.run(response);
}
}
示例10: testUnpack
import com.google.protobuf.Descriptors; //导入依赖的package包/类
@Test
public void testUnpack() throws InvalidProtocolBufferException {
for (Descriptors.ServiceDescriptor serviceDescriptor : FyChessSi.getDescriptor().getServices()) {
MethodDescriptor methodByName = serviceDescriptor.findMethodByName("onEnterRoom");
if (methodByName != null) {
GpbMessageDesc method = new GpbMessageDesc(methodByName);
//
VoEnterRoom message = VoEnterRoom.newBuilder()
.setRoomId(999)
.setSeat(8)
.build();
Message unpack = method.unpack(message.toByteString());
Message pack = method.pack(new Object[]{
999, 8, 10001L, "xx"
});
System.out.println();
}
}
}
示例11: requireAllFieldsExcept
import com.google.protobuf.Descriptors; //导入依赖的package包/类
private static void requireAllFieldsExcept(AbstractMessage message, int... fieldNumbersNotRequired) {
Collection<Descriptors.FieldDescriptor> required = new ArrayList<>(message.getDescriptorForType().getFields());
Collection<Descriptors.FieldDescriptor> actual = message.getAllFields().keySet();
required.removeAll(actual);
if(fieldNumbersNotRequired != null) {
for(int fieldNumber : fieldNumbersNotRequired) {
required.remove(message.getDescriptorForType().findFieldByNumber(fieldNumber));
}
}
if(!required.isEmpty()) {
Collection<String> names = new ArrayList<>(required.size());
for(Descriptors.FieldDescriptor desc : required) {
names.add(desc.getName());
}
throw new ProtobufReadException(message.getDescriptorForType().getFullName(),
"Missing required fields: " + names.toString());
}
}
示例12: messageForFilter
import com.google.protobuf.Descriptors; //导入依赖的package包/类
private static <M extends Message, B extends Message.Builder> M messageForFilter(
ProtocolStringList filter,
Constructor<B> builderConstructor, Message wholeMessage)
throws InstantiationException,
IllegalAccessException,
InvocationTargetException {
final B builder = builderConstructor.newInstance();
final List<Descriptors.FieldDescriptor> fields = wholeMessage.getDescriptorForType()
.getFields();
for (Descriptors.FieldDescriptor field : fields) {
if (filter.contains(field.getFullName())) {
builder.setField(field, wholeMessage.getField(field));
}
}
@SuppressWarnings("unchecked")
// It's fine as the constructor is of {@code MessageCls.Builder} type.
final M result = (M) builder.build();
return result;
}
示例13: testDefaultValues
import com.google.protobuf.Descriptors; //导入依赖的package包/类
@Test
public void testDefaultValues() throws Exception {
Assert.assertEquals(9, defaultValueMap.size());
Assert.assertEquals(
"HOME",
((Descriptors.EnumValueDescriptor)defaultValueMap.get("util.Person.PhoneNumber.type")).getName()
);
Assert.assertEquals("engineering", defaultValueMap.get("util.Engineer.depName"));
Assert.assertEquals("NY", defaultValueMap.get("util.Employee.stringField"));
Assert.assertEquals(43243, defaultValueMap.get("util.Employee.intField"));
Assert.assertEquals(3534.234, defaultValueMap.get("util.Employee.doubleField"));
Assert.assertEquals(true, defaultValueMap.get("util.Employee.boolField"));
Assert.assertEquals(343.34f, defaultValueMap.get("util.Employee.floatField"));
Assert.assertEquals(2343254354L, defaultValueMap.get("util.Employee.longField"));
Assert.assertTrue(
Arrays.equals(
"NewYork".getBytes(),
((ByteString) defaultValueMap.get("util.Employee.bytesField")).toByteArray()
)
);
}
示例14: read_single_record_with_mask
import com.google.protobuf.Descriptors; //导入依赖的package包/类
@SuppressWarnings("ConstantConditions") // Converter nullability issues
@Test
public void read_single_record_with_mask() {
final I id = newId();
final EntityRecord record = newStorageRecord(id);
final RecordStorage<I> storage = getStorage();
storage.write(id, record);
final Descriptors.Descriptor descriptor = newState(id).getDescriptorForType();
final FieldMask idMask = FieldMasks.maskOf(descriptor, 1);
final RecordReadRequest<I> readRequest = new RecordReadRequest<>(id);
final Optional<EntityRecord> optional = storage.read(readRequest, idMask);
assertTrue(optional.isPresent());
final EntityRecord entityRecord = optional.get();
final Message unpacked = unpack(entityRecord.getState());
assertFalse(isDefault(unpacked));
}
示例15: register_aggregate_repositories
import com.google.protobuf.Descriptors; //导入依赖的package包/类
@Test
public void register_aggregate_repositories() {
final BoundedContext boundedContext = BoundedContext.newBuilder()
.build();
final Stand stand = boundedContext.getStand();
checkTypesEmpty(stand);
final CustomerAggregateRepository customerAggregateRepo =
new CustomerAggregateRepository();
stand.registerTypeSupplier(customerAggregateRepo);
final Descriptors.Descriptor customerEntityDescriptor = Customer.getDescriptor();
checkHasExactlyOne(stand.getExposedTypes(), customerEntityDescriptor);
checkHasExactlyOne(stand.getExposedAggregateTypes(), customerEntityDescriptor);
@SuppressWarnings("LocalVariableNamingConvention")
final CustomerAggregateRepository anotherCustomerAggregateRepo =
new CustomerAggregateRepository();
stand.registerTypeSupplier(anotherCustomerAggregateRepo);
checkHasExactlyOne(stand.getExposedTypes(), customerEntityDescriptor);
checkHasExactlyOne(stand.getExposedAggregateTypes(), customerEntityDescriptor);
}