You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: fieldmask/README.md
+12-1
Original file line number
Diff line number
Diff line change
@@ -59,7 +59,6 @@ $ | the root object,every path must start with it.
59
59
</byte-sheet-html-origin><!--EndFragment-->
60
60
61
61
#### Agreement Of Implementation
62
-
- A field in mask means "PASS" (**will be** serialized/deserialized), and the other field not in mask means "Filtered" ((**won't be** serialized/deserialized))
63
62
- A empty mask means "PASS ALL" (all field is "PASS")
64
63
- For map of neither-string-nor-integer typed key, only syntax token of all '*' (see above) is allowed in.
65
64
- For safty, required fields which are not in mask ("Filtered") will still be written into message:
@@ -68,6 +67,10 @@ $ | the root object,every path must start with it.
68
67
- FieldMask settings must start from the root object.
69
68
- Tips: If you want to set FieldMask from a non-root object and make it effective, you need to add `field_mask_halfway` option and regenerate the codes. However, there is a latent risk: if different parent objects reference the same child object, and these two parent objects set different fieldmasks, only one parent object's fieldmask relative to this child object will be effective.
70
69
70
+
#### Visibility
71
+
By default, a field in mask means "PASS" (**will be** serialized/deserialized), and the other fields not in mask means "REJECT" (**won't be** serialized/deserialized) -- which is so-called **"White List"**
72
+
However, we allow user to use fieldmask as a **"Black List"**, as long as enable option `Options.BlackList` mode. Under such mode, a field in the mask means "REJECT", and the other fields means "PASS". See [main_test.go](https://github.com/cloudwego/kitex-tests/blob/feat/fieldmask_test/thriftrpc/fieldmask/main_test.go) for detailed usage.
73
+
71
74
### Type Descriptor
72
75
Type descriptor is the runtime representation of a message definition, in aligned with [Protobuf Descriptor](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto). To get a type descriptor, you must enable thrift reflection feature first, which was introduced in thriftgo [v0.3.0](https://github.com/cloudwego/thriftgo/pull/83). you can generate related codes for this feature using option `with_reflection`.
73
76
@@ -102,6 +105,13 @@ func init() {
102
105
fieldmaskCache.Store("Mask1ForBase", fm)
103
106
}
104
107
```
108
+
- If you want to enable black-list mode of fieldmask, you can create fieldmask like this:
109
+
```go
110
+
fm, err:= fieldmask.Options{
111
+
BlackListMode: true,
112
+
}.NewFieldMask(desc, "$.Addr")
113
+
```
114
+
105
115
3. Now you can use fieldmask in either client-side or server-side
106
116
- For server-side, you can set fieldmask with generated API `Set_FieldMask()` on your response object. Then the object itself will notice the fieldmask and using it during its serialization
107
117
```go
@@ -123,6 +133,7 @@ func init() {
123
133
```
124
134
- For client-side: related to the deserialization process of framework. For kitex, it's WIP.
125
135
136
+
126
137
## How to pass fieldmask between programs?
127
138
Generally, you can add one binary field on your request definition to carry fieldmask, and explicitly serialize/deserialize the fieldmask you are using into/from this field. We provide two encapsulated API for serialization/deserialization:
0 commit comments