@@ -285,6 +285,56 @@ defmodule Protobuf do
285285 "version that introduced implicit struct generation"
286286 end
287287
288+ @ doc """
289+ Returns whether a field or oneof is present, not present, or maybe present
290+
291+ `:present` and `:not present` mean that a field is **explicitly** present or not,
292+ respectively.
293+
294+ Some values may be implicitly present. For example, lists in `repeated` fields
295+ always have implicit presence. In these cases, if the presence is ambiguous,
296+ returns `:maybe`.
297+
298+ For more information about field presence tracking rules, refer to the official
299+ [Field Presence docs](https://protobuf.dev/programming-guides/field_presence/).
300+
301+
302+ ## Examples
303+
304+ # Non-optional proto3 field:
305+ Protobuf.field_presence(%MyMessage{foo: 42}, :foo)
306+ #=> :present
307+
308+ Protobuf.field_presence(%MyMessage{foo: 0}, :foo)
309+ #=> :maybe
310+
311+ Protobuf.field_presence(%MyMessage{}, :foo)
312+ #=> :maybe
313+
314+ # Optional proto3 field:
315+ Protobuf.field_presence(%MyMessage{bar: 42}, :bar)
316+ #=> :present
317+
318+ Protobuf.field_presence(%MyMessage{bar: 0}, :bar)
319+ #=> :present
320+
321+ Protobuf.field_presence(%MyMessage{}, :bar)
322+ #=> :not_present
323+
324+ # Lists
325+ Protobuf.field_presence(%MyMessage{repeated_field: []}, :repeated_field)
326+ #=> :maybe
327+
328+ Protobuf.field_presence(%MyMessage{repeated_field: [1}, :repeated_field)
329+ #=> :present
330+
331+ """
332+ @ doc since: "0.15.0"
333+ @ spec field_presence ( message :: struct ( ) , field :: atom ( ) ) :: :present | :not_present | :maybe
334+ def field_presence ( message , field ) do
335+ Protobuf.Presence . field_presence ( message , field )
336+ end
337+
288338 @ doc """
289339 Loads extensions modules.
290340
0 commit comments