Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support deprecatedOnly option to make deprecated fields optional #1010

Merged
merged 3 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions integration/use-optionals-deprecated-only/optionals-test.ts
Original file line number Diff line number Diff line change
@@ -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],
repStateV2: [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: [],
repStateV2: [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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
useOptionals=deprecatedOnly
Binary file not shown.
35 changes: 35 additions & 0 deletions integration/use-optionals-deprecated-only/test.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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 StateEnum rep_state_v2 = 9;
repeated int64 rep_long = 10;
repeated bool rep_truth = 11;
repeated string rep_description = 12;
repeated bytes rep_data = 13;

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

map<string, string> translations = 20;
}

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