|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +// Fory Options for FDL (Fory Definition Language) |
| 19 | +// |
| 20 | +// This file defines custom options that can be used in FDL schemas |
| 21 | +// to control Fory serialization behavior. Copy this file into your |
| 22 | +// project to use these options. |
| 23 | +// |
| 24 | +// Usage Examples: |
| 25 | +// |
| 26 | +// File-level options: |
| 27 | +// option (fory).use_record_for_java_message = true; |
| 28 | +// |
| 29 | +// Message options: |
| 30 | +// message MyMessage { |
| 31 | +// option (fory).id = 100; |
| 32 | +// option (fory).compatible = true; |
| 33 | +// option (fory).use_record_for_java = true; |
| 34 | +// } |
| 35 | +// |
| 36 | +// Enum options: |
| 37 | +// enum Status { |
| 38 | +// option (fory).id = 101; |
| 39 | +// } |
| 40 | +// |
| 41 | +// Field options: |
| 42 | +// message Example { |
| 43 | +// MyType field = 1 [(fory).ref = true, (fory).nullable = true]; |
| 44 | +// } |
| 45 | + |
| 46 | +syntax = "proto3"; |
| 47 | + |
| 48 | +package fory; |
| 49 | + |
| 50 | +import "google/protobuf/descriptor.proto"; |
| 51 | + |
| 52 | +// =========================================================================== |
| 53 | +// File-Level Options |
| 54 | +// =========================================================================== |
| 55 | +// These options apply to the entire FDL file and affect all generated code. |
| 56 | + |
| 57 | +message ForyFileOptions { |
| 58 | + // Generate Java records instead of classes for all messages in this file. |
| 59 | + // Only applies to Java code generation. |
| 60 | + // Default: false (generates traditional POJOs) |
| 61 | + optional bool use_record_for_java_message = 1; |
| 62 | + |
| 63 | + // Enable polymorphism support for all types in this file. |
| 64 | + // When true, type metadata is included in serialization for polymorphic dispatch. |
| 65 | + // Default: false |
| 66 | + optional bool polymorphism = 2; |
| 67 | +} |
| 68 | + |
| 69 | +extend google.protobuf.FileOptions { |
| 70 | + optional ForyFileOptions fory = 50001; |
| 71 | +} |
| 72 | + |
| 73 | +// =========================================================================== |
| 74 | +// Message-Level Options |
| 75 | +// =========================================================================== |
| 76 | +// These options apply to individual message definitions. |
| 77 | + |
| 78 | +message ForyMessageOptions { |
| 79 | + // Unique type ID for cross-language registration. |
| 80 | + // Used for efficient type lookup during deserialization. |
| 81 | + // Must be a positive integer unique within the schema. |
| 82 | + // If not specified, namespace-based registration is used. |
| 83 | + optional int32 id = 1; |
| 84 | + |
| 85 | + // Enable schema compatibility mode for this message. |
| 86 | + // When true, fields can be added/removed without breaking compatibility. |
| 87 | + // Default: false (strict schema matching) |
| 88 | + optional bool compatible = 2; |
| 89 | + |
| 90 | + // Generate a Java record instead of a class for this specific message. |
| 91 | + // Overrides file-level use_record_for_java_message setting. |
| 92 | + // Only applies to Java code generation. |
| 93 | + optional bool use_record_for_java = 3; |
| 94 | + |
| 95 | + // Mark this message as deprecated. |
| 96 | + // Generates appropriate deprecation annotations in target languages. |
| 97 | + optional bool deprecated = 4; |
| 98 | + |
| 99 | + // Custom namespace for type registration. |
| 100 | + // Overrides the default package-based namespace. |
| 101 | + optional string namespace = 5; |
| 102 | +} |
| 103 | + |
| 104 | +extend google.protobuf.MessageOptions { |
| 105 | + optional ForyMessageOptions fory = 50001; |
| 106 | +} |
| 107 | + |
| 108 | +// =========================================================================== |
| 109 | +// Enum-Level Options |
| 110 | +// =========================================================================== |
| 111 | +// These options apply to individual enum definitions. |
| 112 | + |
| 113 | +message ForyEnumOptions { |
| 114 | + // Unique type ID for cross-language registration. |
| 115 | + // Used for efficient type lookup during deserialization. |
| 116 | + // Must be a positive integer unique within the schema. |
| 117 | + optional int32 id = 1; |
| 118 | + |
| 119 | + // Mark this enum as deprecated. |
| 120 | + optional bool deprecated = 2; |
| 121 | +} |
| 122 | + |
| 123 | +extend google.protobuf.EnumOptions { |
| 124 | + optional ForyEnumOptions fory = 50001; |
| 125 | +} |
| 126 | + |
| 127 | +// =========================================================================== |
| 128 | +// Field-Level Options |
| 129 | +// =========================================================================== |
| 130 | +// These options apply to individual field definitions. |
| 131 | + |
| 132 | +message ForyFieldOptions { |
| 133 | + // Enable reference tracking for this field. |
| 134 | + // When true, Fory tracks object references to handle: |
| 135 | + // - Circular references (e.g., tree structures with parent pointers) |
| 136 | + // - Shared references (same object referenced multiple times) |
| 137 | + // Default: false |
| 138 | + optional bool ref = 1; |
| 139 | + |
| 140 | + // Mark this field as nullable. |
| 141 | + // When true, the field can be null/None/nil. |
| 142 | + // Default: false (field must have a value) |
| 143 | + optional bool nullable = 2; |
| 144 | + |
| 145 | + // Mark this field as deprecated. |
| 146 | + optional bool deprecated = 3; |
| 147 | +} |
| 148 | + |
| 149 | +extend google.protobuf.FieldOptions { |
| 150 | + optional ForyFieldOptions fory = 50001; |
| 151 | +} |
0 commit comments