private void updateFieldMask(int fieldNumber) { FieldMask newMask = FieldMaskUtil.fromFieldNumbers(com.google.bigtable.admin.v2.AppProfile.class, fieldNumber); proto.setUpdateMask(FieldMaskUtil.union(proto.getUpdateMask(), newMask)); }
@Override public FieldMask deserialize(JsonParser parser, DeserializationContext context) throws IOException { switch (parser.getCurrentToken()) { case VALUE_STRING: return FieldMaskUtil.fromJsonString(parser.getText()); default: throw context.wrongTokenException(parser, JsonToken.VALUE_STRING, wrongTokenMessage(context)); } }
@Override public void serialize( FieldMask fieldMask, JsonGenerator generator, SerializerProvider serializerProvider ) throws IOException { generator.writeString(FieldMaskUtil.toJsonString(fieldMask)); } }
/** * Constructs a FieldMask from the passed field numbers. * * @throws IllegalArgumentException if any of the fields are invalid for the message. */ public static FieldMask fromFieldNumbers(Class<? extends Message> type, int... fieldNumbers) { return fromFieldNumbers(type, Ints.asList(fieldNumbers)); }
/** * Checks whether paths in a given fields mask are valid. */ public static boolean isValid(Descriptor descriptor, FieldMask fieldMask) { for (String path : fieldMask.getPathsList()) { if (!isValid(descriptor, path)) { return false; } } return true; }
/** * Disables the given version of the crypto key. */ public static CryptoKeyVersion disableCryptoKeyVersion( String projectId, String locationId, String keyRingId, String cryptoKeyId, String version) throws IOException { // Create the Cloud KMS client. try (KeyManagementServiceClient client = KeyManagementServiceClient.create()) { // The resource name of the cryptoKey version String versionName = CryptoKeyVersionName.format( projectId, locationId, keyRingId, cryptoKeyId, version); // Retrieve the current state CryptoKeyVersion current = client.getCryptoKeyVersion(versionName); // Build a copy that updates the state to disabled CryptoKeyVersion updated = CryptoKeyVersion.newBuilder() .setName(current.getName()) .setState(CryptoKeyVersionState.DISABLED) .build(); // Create a FieldMask that only allows 'state' to be updated FieldMask fieldMask = FieldMaskUtil.fromString(CryptoKeyVersion.class, "state"); // Update the version state CryptoKeyVersion response = client.updateCryptoKeyVersion(updated, fieldMask); return response; } } // [END kms_disable_cryptokey_version]
/** * Parses from a string to a FieldMask and validates all field paths. * * @throws IllegalArgumentException if any of the field path is invalid. */ public static FieldMask fromString(Class<? extends Message> type, String value) { // TODO(xiaofeng): Consider using com.google.common.base.Splitter here instead. return fromStringList(type, Arrays.asList(value.split(FIELD_PATH_SEPARATOR_REGEX))); }
private void mergeFieldMask(JsonElement json, Message.Builder builder) throws InvalidProtocolBufferException { FieldMask value = FieldMaskUtil.fromJsonString(json.getAsString()); builder.mergeFrom(value.toByteString()); }
/** Prints google.protobuf.FieldMask */ private void printFieldMask(MessageOrBuilder message) throws IOException { FieldMask value = FieldMask.parseFrom(toByteString(message)); generator.print("\"" + FieldMaskUtil.toJsonString(value) + "\""); }
/** * Checks whether paths in a given fields mask are valid. */ public static boolean isValid(Class<? extends Message> type, FieldMask fieldMask) { Descriptor descriptor = Internal.getDefaultInstance(type).getDescriptorForType(); return isValid(descriptor, fieldMask); }
/** * Enables the given version of the crypto key. */ public static CryptoKeyVersion enableCryptoKeyVersion( String projectId, String locationId, String keyRingId, String cryptoKeyId, String version) throws IOException { // Create the Cloud KMS client. try (KeyManagementServiceClient client = KeyManagementServiceClient.create()) { // The resource name of the cryptoKey version String versionName = CryptoKeyVersionName.format( projectId, locationId, keyRingId, cryptoKeyId, version); // Retrieve the current state CryptoKeyVersion current = client.getCryptoKeyVersion(versionName); // Build a copy that updates the state to enabled CryptoKeyVersion updated = CryptoKeyVersion.newBuilder() .setName(current.getName()) .setState(CryptoKeyVersionState.ENABLED) .build(); // Create a FieldMask that only allows 'state' to be updated FieldMask fieldMask = FieldMaskUtil.fromString(CryptoKeyVersion.class, "state"); // Update the version state CryptoKeyVersion response = client.updateCryptoKeyVersion(updated, fieldMask); return response; } } // [END kms_enable_cryptokey_version]
/** * Parses from a string to a FieldMask. */ public static FieldMask fromString(String value) { // TODO(xiaofeng): Consider using com.google.common.base.Splitter here instead. return fromStringList(null, Arrays.asList(value.split(FIELD_PATH_SEPARATOR_REGEX))); }
private void mergeFieldMask(JsonElement json, Message.Builder builder) throws InvalidProtocolBufferException { FieldMask value = FieldMaskUtil.fromJsonString(json.getAsString()); builder.mergeFrom(value.toByteString()); }
/** Prints google.protobuf.FieldMask */ private void printFieldMask(MessageOrBuilder message) throws IOException { FieldMask value = FieldMask.parseFrom(toByteString(message)); generator.print("\"" + FieldMaskUtil.toJsonString(value) + "\""); }
private void updateFieldMask(int fieldNumber) { FieldMask newMask = FieldMaskUtil.fromFieldNumbers(Instance.class, fieldNumber); builder.setUpdateMask(FieldMaskUtil.union(builder.getUpdateMask(), newMask)); }
/** * Checks whether a given field path is valid. */ public static boolean isValid(Class<? extends Message> type, String path) { Descriptor descriptor = Internal.getDefaultInstance(type).getDescriptorForType(); return isValid(descriptor, path); }
private void mergeFieldMask(JsonElement json, Message.Builder builder) throws InvalidProtocolBufferException { FieldMask value = FieldMaskUtil.fromJsonString(json.getAsString()); builder.mergeFrom(value.toByteString()); }
/** Prints google.protobuf.FieldMask */ private void printFieldMask(MessageOrBuilder message) throws IOException { FieldMask value = FieldMask.parseFrom(toByteString(message)); generator.print("\"" + FieldMaskUtil.toJsonString(value) + "\""); }
private void updateFieldMask(int fieldNumber) { FieldMask newMask = FieldMaskUtil.fromFieldNumbers(com.google.bigtable.admin.v2.AppProfile.class, fieldNumber); proto.setUpdateMask(FieldMaskUtil.union(proto.getUpdateMask(), newMask)); }
/** * Constructs a FieldMask for a list of field paths in a certain type. * * @throws IllegalArgumentException if any of the field path is not valid. */ // TODO(xiaofeng): Consider renaming fromStrings() public static FieldMask fromStringList(Class<? extends Message> type, Iterable<String> paths) { FieldMask.Builder builder = FieldMask.newBuilder(); for (String path : paths) { if (path.isEmpty()) { // Ignore empty field paths. continue; } if (type != null && !isValid(type, path)) { throw new IllegalArgumentException(path + " is not a valid path for " + type); } builder.addPaths(path); } return builder.build(); }