Skip to content

Commit

Permalink
Add deprecatedOnly option to make deprecated fields optional
Browse files Browse the repository at this point in the history
  • Loading branch information
tufandevrim committed Feb 28, 2024
1 parent ba97f98 commit cf33875
Show file tree
Hide file tree
Showing 7 changed files with 736 additions and 1 deletion.
56 changes: 56 additions & 0 deletions integration/use-optionals-deprecated-only/optionals-test.ts
@@ -0,0 +1,56 @@
import { OptionalsTest, StateEnum } from './test'

describe('useOptionals=deprecatedOnly', () => {
it('has deprecated fields optional members', () => {
const test: OptionalsTest = {
id: 1,
long: 10,

repId: [1, 2],
repState: [StateEnum.ON, StateEnum.OFF],
repLong: [11, 12],
repTruth: [true, false],
repDescription: ["hello", "world"],
repData: [Buffer.alloc(3).fill(0x33), Buffer.alloc(4).fill(0x34), Buffer.alloc(5).fill(0x35)],

optId: 2,
optLong: 13,
optTruth: true,
optDescription: "mumble",
optData: Buffer.alloc(6).fill(0x36),

translations: {
"hello": "hallo",
"world": "wereld",
},
};
const data = OptionalsTest.encode(test).finish();
const test2 = OptionalsTest.decode(data);
expect(test2).toEqual({
id: 1,
state: StateEnum.UNKNOWN,
long: 10,
truth: false,
description: "",
data: new Uint8Array(0),

repId: [1, 2],
repState: [StateEnum.ON, StateEnum.OFF],
repLong: [11, 12],
repTruth: [true, false],
repDescription: ["hello", "world"],
repData: [Buffer.alloc(3).fill(0x33), Buffer.alloc(4).fill(0x34), Buffer.alloc(5).fill(0x35)],

optId: 2,
optLong: 13,
optTruth: true,
optDescription: "mumble",
optData: Buffer.alloc(6).fill(0x36),

translations: {
"hello": "hallo",
"world": "wereld",
},
});
});
})
1 change: 1 addition & 0 deletions integration/use-optionals-deprecated-only/parameters.txt
@@ -0,0 +1 @@
useOptionals=deprecatedOnly
Binary file not shown.
34 changes: 34 additions & 0 deletions integration/use-optionals-deprecated-only/test.proto
@@ -0,0 +1,34 @@
syntax = "proto3";
package optionalstest;

message OptionalsTest {
int32 id = 1;
StateEnum state = 2 [deprecated = true];
int64 long = 3;
bool truth = 4 [deprecated = true];
string description = 5 [deprecated = true];
bytes data = 6 [deprecated = true];

repeated int32 rep_id = 7;
repeated StateEnum rep_state = 8 [deprecated = true];
repeated int64 rep_long = 9;
repeated bool rep_truth = 10;
repeated string rep_description = 11;
repeated bytes rep_data = 12;

optional int32 opt_id = 13;
optional StateEnum opt_state = 14 [deprecated = true];
optional int64 opt_long = 15;
optional bool opt_truth = 16;
optional string opt_description = 17;
optional bytes opt_data = 18;

map<string, string> translations = 19;
}

enum StateEnum {
option deprecated = true;
UNKNOWN = 0;
ON = 1;
OFF = 2;
}

0 comments on commit cf33875

Please sign in to comment.