How to use the google-protobuf/google/protobuf/descriptor_pb.FieldDescriptorProto.Label function in google-protobuf

To help you get started, we’ve selected a few google-protobuf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github agreatfool / grpc_tools_node_protoc_ts / src / lib / format / partial / MessageFormatter.ts View on Github external
// Check for [jstype = JS_STRING] overrides
                const options = field.getOptions();
                if (options && options.hasJstype()) {
                    const jstype = FieldTypesFormatter.getJsTypeName(options.getJstype());
                    if (jstype) {
                        type = jstype;
                    }
                }

                exportType = fieldData.exportType = type;

            }

            fieldData.isOptionalValue = field.getType() === MESSAGE_TYPE;
            fieldData.isRepeatField = field.getLabel() === FieldDescriptorProto.Label.LABEL_REPEATED;
            if (!fieldData.isRepeatField && fieldData.type !== BYTES_TYPE) {
                let fieldObjectType = exportType;
                let canBeUndefined = false;
                if (fieldData.type === MESSAGE_TYPE) {
                    fieldObjectType += ".AsObject";
                    if (!Utility.isProto2(fileDescriptor) || (field.getLabel() === FieldDescriptorProto.Label.LABEL_OPTIONAL)) {
                        canBeUndefined = true;
                    }
                } else {
                    if (Utility.isProto2(fileDescriptor)) {
                        canBeUndefined = true;
                    }
                }
                fieldData.fieldObjectType = fieldObjectType;
                fieldData.canBeUndefined = canBeUndefined;
            }
github improbable-eng / ts-protoc-gen / src / ts / message.ts View on Github external
hasClearMethod = true;
        printer.printIndentedLn(`clear${withUppercase}${field.getLabel() === FieldDescriptorProto.Label.LABEL_REPEATED ? "List" : ""}(): void;`);
      }
    }

    if (hasFieldPresence(field, fileDescriptor)) {
      printer.printIndentedLn(`has${withUppercase}(): boolean;`);
      printClearIfNotPresent();
    }

    function printRepeatedAddMethod(valueType: string) {
      const optionalValue = field.getType() === MESSAGE_TYPE;
      printer.printIndentedLn(`add${withUppercase}(value${optionalValue ? "?" : ""}: ${valueType}, index?: number): ${valueType};`);
    }

    if (field.getLabel() === FieldDescriptorProto.Label.LABEL_REPEATED) {// is repeated
      printClearIfNotPresent();
      if (type === BYTES_TYPE) {
        toObjectType.printIndentedLn(`${camelCaseName}List: Array<Uint8Array | string>,`);
        printer.printIndentedLn(`get${withUppercase}List(): Array<Uint8Array | string>;`);
        printer.printIndentedLn(`get${withUppercase}List_asU8(): Array<Uint8Array>;`);
        printer.printIndentedLn(`get${withUppercase}List_asB64(): Array<string>;`);
        printer.printIndentedLn(`set${withUppercase}List(value: Array<Uint8Array | string>): void;`);
        printRepeatedAddMethod("Uint8Array | string");
      } else {
        toObjectType.printIndentedLn(`${camelCaseName}List: Array<${exportType}${type === MESSAGE_TYPE ? ".AsObject" : ""}>,`);
        printer.printIndentedLn(`get${withUppercase}List(): Array<${exportType}>;`);
        printer.printIndentedLn(`set${withUppercase}List(value: Array<${exportType}>): void;`);
        printRepeatedAddMethod(exportType);
      }
    } else {
      if (type === BYTES_TYPE) {
github anjmao / rn-grpc-bridge / src / lib / gen / TsNativeModuleTypes.ts View on Github external
function genMessageTypesTsInterfaces(messages: DescriptorProto[]) {
    const res: string[] = [];
    const g = (i, val) => res.push(generateIndent(i) + val);
    for (let msg of messages) {
        g(0, `export interface ${msg.getName()}Pb {`);
        for (let field of msg.getFieldList()) {
            let optionalLabel = field.getLabel() === FieldDescriptorProto.Label.LABEL_OPTIONAL ? '?' : '';
            g(1, `${field.getName()}${optionalLabel}: ${getTsType(field)};`);
        }
        g(0, `}`);
    }
    return res.join('\n');
}
github agreatfool / grpc_tools_node_protoc_ts / src / lib / format / partial / MessageFormatter.ts View on Github external
function hasFieldPresence(field: FieldDescriptorProto, descriptor: FileDescriptorProto): boolean {
        if (field.getLabel() === FieldDescriptorProto.Label.LABEL_REPEATED) {
            return false;
        }

        if (field.hasOneofIndex()) {
            return true;
        }

        if (field.getType() === MESSAGE_TYPE) {
            return true;
        }

        return Utility.isProto2(descriptor);
    }
github agreatfool / SASDN / src / proto_plugin / lib / format / partial / MessageFormatter.ts View on Github external
function hasFieldPresence(field: FieldDescriptorProto, descriptor: FileDescriptorProto): boolean {
        if (field.getLabel() === FieldDescriptorProto.Label.LABEL_REPEATED) {
            return false;
        }

        if (field.hasOneofIndex()) {
            return true;
        }

        if (field.getType() === MESSAGE_TYPE) {
            return true;
        }

        return Utility.isProto2(descriptor);
    }
github anjmao / rn-grpc-bridge / src / lib / format / ProtoSvcSwiftFormatter.ts View on Github external
case fType.TYPE_FIXED64:
                cast = 'as? UInt64 ?? 0';
            break;
            case fType.TYPE_FLOAT:
                cast = 'as? Float ?? 0';
            break;
            case fType.TYPE_UINT32:
                cast = 'as? UInt32 ?? 0';
            break;
            case fType.TYPE_UINT64:
                cast = 'as? UInt32 ?? 0';
            break;
            case fType.TYPE_MESSAGE:
                const type = getType(messageTypes, f.getTypeName())
                childDescriptor = type;
                repeated = f.getLabel() === FieldDescriptorProto.Label.LABEL_REPEATED;
            break;
            default:
            throw new Error(`Data type ${f.getType()} is not supported.`);
        }
        fields.push({
            childDescriptor: childDescriptor,
            name: fieldName,
            value: `${to(f)} = ${from(f)} ${cast}`,
            repeated: repeated
        });
    }
    return fields;
}
github stultuss / protoc-gen-grpc-ts / src / lib / descriptor / partial / Message.ts View on Github external
printer.printIndentedLn(`set${fieldData.camelUpperName}List(value: Array<${fieldData.exportType}>): void;`);
                    printRepeatedAddMethod(fieldData.exportType);
                }
            } else {
                if (fieldData.type === BYTES_TYPE) {
                    printerToObjectType.printIndentedLn(`${fieldData.camelCaseName}: Uint8Array | string,`);
                    printer.printIndentedLn(`get${fieldData.camelUpperName}(): Uint8Array | string;`);
                    printer.printIndentedLn(`get${fieldData.camelUpperName}_asU8(): Uint8Array;`);
                    printer.printIndentedLn(`get${fieldData.camelUpperName}_asB64(): string;`);
                    printer.printIndentedLn(`set${fieldData.camelUpperName}(value: Uint8Array | string): void;`);
                } else {
                    let fieldObjectType = fieldData.exportType;
                    let canBeUndefined = false;
                    if (fieldData.type === MESSAGE_TYPE) {
                        fieldObjectType += '.AsObject';
                        if (!Utility.isProto2(fileDescriptor) || (field.getLabel() === FieldDescriptorProto.Label.LABEL_OPTIONAL)) {
                            canBeUndefined = true;
                        }
                    } else {
                        if (Utility.isProto2(fileDescriptor)) {
                            canBeUndefined = true;
                        }
                    }
                    const fieldObjectName = Utility.normaliseFieldObjectName(fieldData.camelCaseName);
                    printerToObjectType.printIndentedLn(`${fieldObjectName}${canBeUndefined ? '?' : ''}: ${fieldObjectType},`);
                    printer.printIndentedLn(`get${fieldData.camelUpperName}(): ${fieldData.exportType}${canBeUndefined ? ' | undefined' : ''};`);
                    printer.printIndentedLn(`set${fieldData.camelUpperName}(value${fieldData.type === MESSAGE_TYPE ? '?' : ''}: ${fieldData.exportType}): void;`);
                }
            }

            printer.printEmptyLn();
        });
github stultuss / protoc-gen-grpc-ts / src / lib / descriptor / partial / Message.ts View on Github external
function printClearIfNotPresent() {
                if (!hasClearMethod) {
                    hasClearMethod = true;
                    printer.printIndentedLn(`clear${fieldData.camelUpperName}${field.getLabel() === FieldDescriptorProto.Label.LABEL_REPEATED ? 'List' : ''}(): void;`);
                }
            }