File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed
main/kotlin/com/google/protobuf
test/kotlin/com/google/protobuf Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -34,15 +34,18 @@ import com.google.protobuf.ByteString
34
34
import java.nio.ByteBuffer
35
35
36
36
/* * Encodes this String into a sequence of UTF-8 bytes and returns the result as a [ByteString]. */
37
- fun String.toByteStringUtf8 (): ByteString = ByteString .copyFromUtf8( this )
38
- // symmetric from ByteString.toStringUtf8()
37
+ fun String.toByteStringUtf8 (): ByteString =
38
+ ByteString .copyFromUtf8( this ) // symmetric from ByteString.toStringUtf8()
39
39
40
40
/* * Concatenates the given [ByteString] to this one. */
41
41
operator fun ByteString.plus (other : ByteString ): ByteString = concat(other)
42
42
43
43
/* * Gets the byte at [index]. */
44
44
operator fun ByteString.get (index : Int ): Byte = byteAt(index)
45
45
46
+ /* * Checks if this is not empty. */
47
+ fun ByteString.isNotEmpty (): Boolean = ! isEmpty()
48
+
46
49
/* * Returns a copy of this [ByteArray] as an immutable [ByteString]. */
47
50
fun ByteArray.toByteString (): ByteString = ByteString .copyFrom(this )
48
51
Original file line number Diff line number Diff line change @@ -62,6 +62,16 @@ class ByteStringsTest {
62
62
assertThat(str[2 ]).isEqualTo(' c' .toByte())
63
63
}
64
64
65
+ @Test
66
+ fun isNotEmpty_returnsTrue_whenNotEmpty () {
67
+ assertThat(" abc" .toByteStringUtf8().isNotEmpty()).isTrue()
68
+ }
69
+
70
+ @Test
71
+ fun isNotEmpty_returnsFalse_whenEmpty () {
72
+ assertThat(ByteString .EMPTY .isNotEmpty()).isFalse()
73
+ }
74
+
65
75
@Test
66
76
fun byteAtBelowZero () {
67
77
val str = " abc" .toByteStringUtf8()
You can’t perform that action at this time.
0 commit comments