Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions wire-runtime/api/wire-runtime.api
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ public final class com/squareup/wire/FieldEncoding : java/lang/Enum {
public final class com/squareup/wire/FieldEncoding$Companion {
}

public final class com/squareup/wire/FieldMask {
public fun <init> ()V
public fun <init> (Ljava/util/List;)V
public synthetic fun <init> (Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun copy (Ljava/util/List;)Lcom/squareup/wire/FieldMask;
public static synthetic fun copy$default (Lcom/squareup/wire/FieldMask;Ljava/util/List;ILjava/lang/Object;)Lcom/squareup/wire/FieldMask;
public fun equals (Ljava/lang/Object;)Z
public final fun getPaths ()Ljava/util/List;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class com/squareup/wire/InstantKt {
public static final fun ofEpochSecond (JJ)Ljava/time/Instant;
}
Expand Down
37 changes: 37 additions & 0 deletions wire-runtime/src/commonMain/kotlin/com/squareup/wire/FieldMask.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (C) 2026 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.squareup.wire

/**
* A set of symbolic field paths.
*
* Field masks are used to specify a subset of fields on a target message. Each path uses proto
* field names, separated by dots for nested fields.
*/
class FieldMask(paths: List<String> = emptyList()) {
val paths: List<String> = paths.toList()

fun copy(paths: List<String> = this.paths): FieldMask = FieldMask(paths)

override fun equals(other: Any?): Boolean {
if (other === this) return true
return other is FieldMask && paths == other.paths
}

override fun hashCode(): Int = paths.hashCode()

override fun toString(): String = "FieldMask{paths=$paths}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2026 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.squareup.wire

import assertk.assertThat
import assertk.assertions.containsExactly
import assertk.assertions.isEqualTo
import kotlin.test.Test

class FieldMaskTest {
@Test fun storesPaths() {
val fieldMask = FieldMask(listOf("user.display_name", "photo"))

assertThat(fieldMask.paths).containsExactly("user.display_name", "photo")
}

@Test fun defaultPathsIsEmpty() {
assertThat(FieldMask().paths).isEqualTo(emptyList())
}

@Test fun pathsAreImmutableCopy() {
val paths = mutableListOf("user.display_name")
val fieldMask = FieldMask(paths)

paths += "photo"

assertThat(fieldMask.paths).containsExactly("user.display_name")
}

@Test fun copy() {
val fieldMask = FieldMask(listOf("user.display_name"))

assertThat(fieldMask.copy(paths = listOf("photo"))).isEqualTo(FieldMask(listOf("photo")))
}
}
1 change: 1 addition & 0 deletions wire-schema/api/wire-schema.api
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ public final class com/squareup/wire/schema/ProtoType {
public static final field DOUBLE_VALUE Lcom/squareup/wire/schema/ProtoType;
public static final field DURATION Lcom/squareup/wire/schema/ProtoType;
public static final field EMPTY Lcom/squareup/wire/schema/ProtoType;
public static final field FIELD_MASK Lcom/squareup/wire/schema/ProtoType;
public static final field FIXED32 Lcom/squareup/wire/schema/ProtoType;
public static final field FIXED64 Lcom/squareup/wire/schema/ProtoType;
public static final field FLOAT Lcom/squareup/wire/schema/ProtoType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ class ProtoType {

@JvmField val EMPTY = ProtoType(false, "google.protobuf.Empty")

@JvmField val FIELD_MASK = ProtoType(false, "google.protobuf.FieldMask")

@JvmField val STRUCT_MAP = ProtoType(false, "google.protobuf.Struct")

@JvmField val STRUCT_VALUE = ProtoType(false, "google.protobuf.Value")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ class ProtoTypeTest {
assertThat(phoneType.toString()).isEqualTo("squareup.protos.person.Person.PhoneType")
}

@Test
fun fieldMask() {
assertThat(ProtoType.FIELD_MASK).isEqualTo(ProtoType.get("google.protobuf.FieldMask"))
assertThat(ProtoType.FIELD_MASK.typeUrl).isEqualTo("type.googleapis.com/google.protobuf.FieldMask")
}

@Test
fun enclosingTypeOrPackage() {
assertThat(ProtoType.STRING.enclosingTypeOrPackage).isNull()
Expand Down
Loading