Editions should not be used to make semantic decisions -- specific helpers (e.g. FieldDescriptor.hasPresence()) should be used instead. FileDescriptorProto can be used to access editions for *non semantic* purposes, incl. with ProtoFileUti. These APIs have not been released yet and are thus non-breaking. PiperOrigin-RevId: 597362543pull/15380/head
parent
592ee9b192
commit
63623a688c
3 changed files with 46 additions and 9 deletions
@ -0,0 +1,21 @@ |
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file or at
|
||||
// https://developers.google.com/open-source/licenses/bsd
|
||||
|
||||
package com.google.protobuf.util; |
||||
|
||||
import com.google.protobuf.DescriptorProtos.Edition; |
||||
|
||||
/** Utility helper functions to work with {@link com.google.protobuf.FileDescriptorProto}. */ |
||||
public final class ProtoFileUtil { |
||||
|
||||
private ProtoFileUtil() {} |
||||
|
||||
/** Converts an Edition to its string representation as specified in ".proto" file. */ |
||||
public static String getEditionString(Edition edition) { |
||||
return edition.toString().substring("EDITION_".length()); |
||||
} |
||||
} |
@ -0,0 +1,24 @@ |
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file or at
|
||||
// https://developers.google.com/open-source/licenses/bsd
|
||||
|
||||
package com.google.protobuf.util; |
||||
|
||||
import static com.google.common.truth.Truth.assertThat; |
||||
|
||||
import com.google.protobuf.DescriptorProtos.Edition; |
||||
import org.junit.Test; |
||||
import org.junit.runner.RunWith; |
||||
import org.junit.runners.JUnit4; |
||||
|
||||
/** Unit tests for {@link ProtoFileUtil}. */ |
||||
@RunWith(JUnit4.class) |
||||
public class ProtoFileUtilTest { |
||||
@Test |
||||
public void testGetEditionFromString() throws Exception { |
||||
assertThat(ProtoFileUtil.getEditionString(Edition.EDITION_2023)).isEqualTo("2023"); |
||||
} |
||||
} |
Loading…
Reference in new issue