Class FieldMask.Builder
java.lang.Object
com.google.protobuf.AbstractMessageLite.Builder
com.google.protobuf.AbstractMessage.Builder<FieldMask.Builder>
com.google.protobuf.GeneratedMessage.Builder<FieldMask.Builder>
com.google.protobuf.FieldMask.Builder
- All Implemented Interfaces:
FieldMaskOrBuilder, Message.Builder, MessageLite.Builder, MessageLiteOrBuilder, MessageOrBuilder, Cloneable
- Enclosing class:
FieldMask
public static final class FieldMask.Builder
extends GeneratedMessage.Builder<FieldMask.Builder>
implements FieldMaskOrBuilder
`FieldMask` represents a set of symbolic field paths, for example:
paths: "f.a"
paths: "f.b.d"
Here `f` represents a field in some root message, `a` and `b`
fields in the message found in `f`, and `d` a field found in the
message in `f.b`.
Field masks are used to specify a subset of fields that should be
returned by a get operation or modified by an update operation.
Field masks also have a custom JSON encoding (see below).
# Field Masks in Projections
When used in the context of a projection, a response message or
sub-message is filtered by the API to only contain those fields as
specified in the mask. For example, if the mask in the previous
example is applied to a response message as follows:
f {
a : 22
b {
d : 1
x : 2
}
y : 13
}
z: 8
The result will not contain specific values for fields x,y and z
(their value will be set to the default, and omitted in proto text
output):
f {
a : 22
b {
d : 1
}
}
A repeated field is not allowed except at the last position of a
paths string.
If a FieldMask object is not present in a get operation, the
operation applies to all fields (as if a FieldMask of all fields
had been specified).
Note that a field mask does not necessarily apply to the
top-level response message. In case of a REST get operation, the
field mask applies directly to the response, but in case of a REST
list operation, the mask instead applies to each individual message
in the returned resource list. In case of a REST custom method,
other definitions may be used. Where the mask applies will be
clearly documented together with its declaration in the API. In
any case, the effect on the returned resource/resources is required
behavior for APIs.
# Field Masks in Update Operations
A field mask in update operations specifies which fields of the
targeted resource are going to be updated. The API is required
to only change the values of the fields as specified in the mask
and leave the others untouched. If a resource is passed in to
describe the updated values, the API ignores the values of all
fields not covered by the mask.
If a repeated field is specified for an update operation, new values will
be appended to the existing repeated field in the target resource. Note that
a repeated field is only allowed in the last position of a `paths` string.
If a sub-message is specified in the last position of the field mask for an
update operation, then new value will be merged into the existing sub-message
in the target resource.
For example, given the target message:
f {
b {
d: 1
x: 2
}
c: [1]
}
And an update message:
f {
b {
d: 10
}
c: [2]
}
then if the field mask is:
paths: ["f.b", "f.c"]
then the result will be:
f {
b {
d: 10
x: 2
}
c: [1, 2]
}
An implementation may provide options to override this default behavior for
repeated and message fields.
Note that libraries which implement FieldMask resolution have various
different behaviors in the face of empty masks or the special "*" mask.
When implementing a service you should confirm these cases have the
appropriate behavior in the underlying FieldMask library that you desire,
and you may need to special case those cases in your application code if
the underlying field mask library behavior differs from your intended
service semantics.
Update methods implementing https://google.aip.dev/134
- MUST support the special value * meaning "full replace"
- MUST treat an omitted field mask as "replace fields which are present".
Other methods implementing https://google.aip.dev/157
- SHOULD support the special value "*" to mean "get all".
- MUST treat an omitted field mask to mean "get all", unless otherwise
documented.
## Considerations for HTTP REST
The HTTP kind of an update operation which uses a field mask must
be set to PATCH instead of PUT in order to satisfy HTTP semantics
(PUT must only be used for full updates).
# JSON Encoding of Field Masks
In JSON, a field mask is encoded as a single string where paths are
separated by a comma. Fields name in each path are converted
to/from lower-camel naming conventions.
As an example, consider the following message declarations:
message Profile {
User user = 1;
Photo photo = 2;
}
message User {
string display_name = 1;
string address = 2;
}
In proto a field mask for `Profile` may look as such:
mask {
paths: "user.display_name"
paths: "photo"
}
In JSON, the same mask is represented as below:
{
mask: "user.displayName,photo"
}
# Field Masks and Oneof Fields
Field masks treat fields in oneofs just as regular fields. Consider the
following message:
message SampleMessage {
oneof test_oneof {
string name = 4;
SubMessage sub_message = 9;
}
}
The field mask can be:
mask {
paths: "name"
}
Or:
mask {
paths: "sub_message"
}
Note that oneof type names ("test_oneof" in this case) cannot be used in
paths.
## Field Mask Verification
The implementation of any API method which has a FieldMask type field in the
request should verify the included field paths, and return an
`INVALID_ARGUMENT` error if any path is unmappable.
Protobuf type google.protobuf.FieldMask-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractMessageLite.Builder
AbstractMessageLite.Builder.LimitedInputStream -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateBuilder()privateBuilder(AbstractMessage.BuilderParent parent) -
Method Summary
Modifier and TypeMethodDescriptionaddAllPaths(Iterable<String> values) The set of field mask paths.The set of field mask paths.addPathsBytes(ByteString value) The set of field mask paths.build()Constructs the message based on the state of the Builder.LikeMessageLite.Builder.build(), but does not throw an exception if the message is missing required fields.private voidbuildPartial0(FieldMask result) clear()Called by the initialization and clear code paths to allow subclasses to reset any of their builtin fields back to the initial values.The set of field mask paths.private voidGet an instance of the type with no fields set.static final Descriptors.DescriptorGet the message's type's descriptor.getPaths(int index) The set of field mask paths.getPathsBytes(int index) The set of field mask paths.intThe set of field mask paths.The set of field mask paths.protected GeneratedMessage.FieldAccessorTableGet the FieldAccessorTable for this type.final booleanReturns true if all required fields in the message and all embedded messages are set, false otherwise.mergeFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry) LikeMessageLite.Builder.mergeFrom(CodedInputStream), but also parses extensions.Mergeotherinto the message being built.The set of field mask paths.Methods inherited from class GeneratedMessage.Builder
addRepeatedField, clearField, clearOneof, clone, dispose, getAllFields, getField, getFieldBuilder, getOneofFieldDescriptor, getParentForChildren, getRepeatedField, getRepeatedFieldBuilder, getRepeatedFieldCount, getUnknownFields, getUnknownFieldSetBuilder, hasField, hasOneof, internalGetMapField, internalGetMapFieldReflection, internalGetMutableMapField, internalGetMutableMapFieldReflection, isClean, markClean, mergeUnknownFields, mergeUnknownLengthDelimitedField, mergeUnknownVarintField, newBuilderForField, onBuilt, onChanged, parseUnknownField, setField, setRepeatedField, setUnknownFields, setUnknownFieldSetBuilder, setUnknownFieldsProto3Methods inherited from class AbstractMessage.Builder
findInitializationErrors, getInitializationErrorString, internalMergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, mergeFrom, newUninitializedMessageException, toStringMethods inherited from class AbstractMessageLite.Builder
addAll, addAll, mergeDelimitedFrom, mergeDelimitedFrom, mergeFrom, newUninitializedMessageExceptionMethods inherited from class Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Message.Builder
mergeDelimitedFrom, mergeDelimitedFromMethods inherited from interface MessageLite.Builder
mergeFromMethods inherited from interface MessageOrBuilder
findInitializationErrors, getAllFields, getField, getInitializationErrorString, getOneofFieldDescriptor, getRepeatedField, getRepeatedFieldCount, getUnknownFields, hasField, hasOneof
-
Field Details
-
bitField0_
private int bitField0_ -
paths_
-
-
Constructor Details
-
Builder
private Builder() -
Builder
-
-
Method Details
-
getDescriptor
-
internalGetFieldAccessorTable
Description copied from class:GeneratedMessage.BuilderGet the FieldAccessorTable for this type. We can't have the message class pass this in to the constructor because of bootstrapping trouble with DescriptorProtos.- Specified by:
internalGetFieldAccessorTablein classGeneratedMessage.Builder<FieldMask.Builder>
-
clear
Description copied from class:GeneratedMessage.BuilderCalled by the initialization and clear code paths to allow subclasses to reset any of their builtin fields back to the initial values.- Specified by:
clearin interfaceMessage.Builder- Specified by:
clearin interfaceMessageLite.Builder- Overrides:
clearin classGeneratedMessage.Builder<FieldMask.Builder>
-
getDescriptorForType
Description copied from interface:Message.BuilderGet the message's type's descriptor. SeeMessageOrBuilder.getDescriptorForType().- Specified by:
getDescriptorForTypein interfaceMessage.Builder- Specified by:
getDescriptorForTypein interfaceMessageOrBuilder- Overrides:
getDescriptorForTypein classGeneratedMessage.Builder<FieldMask.Builder>
-
getDefaultInstanceForType
Description copied from interface:MessageLiteOrBuilderGet an instance of the type with no fields set. Because no fields are set, all getters for singular fields will return default values and repeated fields will appear empty. This may or may not be a singleton. This differs from thegetDefaultInstance()method of generated message classes in that this method is an abstract method of theMessageLiteinterface whereasgetDefaultInstance()is a static method of a specific class. They return the same thing.- Specified by:
getDefaultInstanceForTypein interfaceMessageLiteOrBuilder- Specified by:
getDefaultInstanceForTypein interfaceMessageOrBuilder
-
build
Description copied from interface:MessageLite.BuilderConstructs the message based on the state of the Builder. Subsequent changes to the Builder will not affect the returned message.- Specified by:
buildin interfaceMessage.Builder- Specified by:
buildin interfaceMessageLite.Builder
-
buildPartial
Description copied from interface:MessageLite.BuilderLikeMessageLite.Builder.build(), but does not throw an exception if the message is missing required fields. Instead, a partial message is returned. Subsequent changes to the Builder will not affect the returned message.- Specified by:
buildPartialin interfaceMessage.Builder- Specified by:
buildPartialin interfaceMessageLite.Builder
-
buildPartial0
-
mergeFrom
Description copied from interface:Message.BuilderMergeotherinto the message being built.othermust have the exact same type asthis(i.e.getDescriptorForType() == other.getDescriptorForType()).Merging occurs as follows. For each field:
* For singular primitive fields, if the field is set inother, thenother's value overwrites the value in this message.
* For singular message fields, if the field is set inother, it is merged into the corresponding sub-message of this message using the same merging rules.
* For repeated fields, the elements inotherare concatenated with the elements in this message.
* For oneof groups, if the other message has one of the fields set, the group of this message is cleared and replaced by the field of the other message, so that the oneof constraint is preserved.This is equivalent to the
Message::MergeFrommethod in C++.- Specified by:
mergeFromin interfaceMessage.Builder- Overrides:
mergeFromin classAbstractMessage.Builder<FieldMask.Builder>
-
mergeFrom
-
isInitialized
public final boolean isInitialized()Description copied from interface:MessageLiteOrBuilderReturns true if all required fields in the message and all embedded messages are set, false otherwise.- Specified by:
isInitializedin interfaceMessageLiteOrBuilder- Overrides:
isInitializedin classGeneratedMessage.Builder<FieldMask.Builder>
-
mergeFrom
public FieldMask.Builder mergeFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry) throws IOException Description copied from interface:MessageLite.BuilderLikeMessageLite.Builder.mergeFrom(CodedInputStream), but also parses extensions. The extensions that you want to be able to parse must be registered inextensionRegistry. Extensions not in the registry will be treated as unknown fields.- Specified by:
mergeFromin interfaceMessage.Builder- Specified by:
mergeFromin interfaceMessageLite.Builder- Overrides:
mergeFromin classAbstractMessage.Builder<FieldMask.Builder>- Throws:
IOException- an I/O error reading from the stream
-
ensurePathsIsMutable
private void ensurePathsIsMutable() -
getPathsList
The set of field mask paths.
repeated string paths = 1;- Specified by:
getPathsListin interfaceFieldMaskOrBuilder- Returns:
- A list containing the paths.
-
getPathsCount
public int getPathsCount()The set of field mask paths.
repeated string paths = 1;- Specified by:
getPathsCountin interfaceFieldMaskOrBuilder- Returns:
- The count of paths.
-
getPaths
The set of field mask paths.
repeated string paths = 1;- Specified by:
getPathsin interfaceFieldMaskOrBuilder- Parameters:
index- The index of the element to return.- Returns:
- The paths at the given index.
-
getPathsBytes
The set of field mask paths.
repeated string paths = 1;- Specified by:
getPathsBytesin interfaceFieldMaskOrBuilder- Parameters:
index- The index of the value to return.- Returns:
- The bytes of the paths at the given index.
-
setPaths
The set of field mask paths.
repeated string paths = 1;- Parameters:
index- The index to set the value at.value- The paths to set.- Returns:
- This builder for chaining.
-
addPaths
The set of field mask paths.
repeated string paths = 1;- Parameters:
value- The paths to add.- Returns:
- This builder for chaining.
-
addAllPaths
The set of field mask paths.
repeated string paths = 1;- Parameters:
values- The paths to add.- Returns:
- This builder for chaining.
-
clearPaths
The set of field mask paths.
repeated string paths = 1;- Returns:
- This builder for chaining.
-
addPathsBytes
The set of field mask paths.
repeated string paths = 1;- Parameters:
value- The bytes of the paths to add.- Returns:
- This builder for chaining.
-