com.github.os72.protobuf.dynamic.OneofDefinition.xxx Maven / Gradle / Ivy
/*
* Copyright 2015 protobuf-dynamic developers
*
* 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
*
* http://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.github.os72.protobuf.dynamic;
import com.google.protobuf.DescriptorProtos.FieldDescriptorProto;
import com.google.protobuf.DescriptorProtos.OneofDescriptorProto;
import com.google.protobuf.Descriptors.FieldDescriptor;
/**
* OneofDefinition
*/
public class OneofDefinition
{
// --- public static ---
public static Builder newBuilder(String oneofName, MessageDefinition.Builder msgBuilder, int oneofIdx) {
return new Builder(oneofName, msgBuilder, oneofIdx);
}
// --- public ---
public String toString() {
return mOneofType.toString();
}
// --- package ---
OneofDescriptorProto getOneofType() {
return mOneofType;
}
// --- private ---
private OneofDefinition(OneofDescriptorProto oneofType) {
mOneofType = oneofType;
}
private OneofDescriptorProto mOneofType;
/**
* OneofDefinition.Builder
*/
public static class Builder
{
// --- public ---
public Builder addField(String type, String name, int num) {
return addField(type, name, num, null);
}
public Builder addField(String type, String name, int num, String defaultVal) {
//mMsgBuilder.addOneofField(type, name, num, defaultVal, this);
return this;
}
public MessageDefinition.Builder getMessageBuilder() {
return mMsgBuilder;
}
public MessageDefinition.Builder builder() {
return mMsgBuilder;
}
public int getOneofIdx() {
return mOneofIdx;
}
public OneofDefinition build() {
return new OneofDefinition(mOneofTypeBuilder.build());
}
// --- private ---
private Builder(String oneofName, MessageDefinition.Builder msgBuilder, int oneofIdx) {
mOneofTypeBuilder = OneofDescriptorProto.newBuilder();
mOneofTypeBuilder.setName(oneofName);
mMsgBuilder = msgBuilder;
mOneofIdx = oneofIdx;
}
private OneofDescriptorProto.Builder mOneofTypeBuilder;
private MessageDefinition.Builder mMsgBuilder;
private int mOneofIdx;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy