DCCL v5
Loading...
Searching...
No Matches
test.proto
1// Copyright 2024:
2// GobySoft, LLC (2013-)
3// Community contributors (see AUTHORS file)
4// File authors:
5// Toby Schneider <toby@gobysoft.org>
6//
7//
8// This file is part of the Dynamic Compact Control Language Library
9// ("DCCL").
10//
11// DCCL is free software: you can redistribute it and/or modify
12// it under the terms of the GNU Lesser General Public License as published by
13// the Free Software Foundation, either version 2.1 of the License, or
14// (at your option) any later version.
15//
16// DCCL is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU Lesser General Public License for more details.
20//
21// You should have received a copy of the GNU Lesser General Public License
22// along with DCCL. If not, see <http://www.gnu.org/licenses/>.
23syntax = "proto2";
24import "dccl/option_extensions.proto";
25package dccl.test;
26
27// Tests for min_length with VarBytesCodec (bytes fields and v4 strings)
28message MinLengthMsg
29{
30 option (dccl.msg) = {
31 id: 20
32 max_bytes: 64
33 codec_version: 4
34 };
35
36 // required bytes with min_length=4, max_length=10
37 required bytes req_bytes = 1
38 [(dccl.field) = { min_length: 4 max_length: 10 codec: "dccl.var_bytes" }];
39 // optional bytes with min_length=2, max_length=8
40 optional bytes opt_bytes = 2
41 [(dccl.field) = { min_length: 2 max_length: 8 codec: "dccl.var_bytes" }];
42
43 // v4 string field uses VarBytesCodec — min_length savings apply
44 optional string str_field = 3
45 [(dccl.field) = { min_length: 3 max_length: 10 }];
46}
47
48// min_length == max_length (fixed-size bytes)
49message FixedLengthMsg
50{
51 option (dccl.msg) = {
52 id: 21
53 max_bytes: 32
54 codec_version: 4
55 };
56
57 required bytes fixed_bytes = 1
58 [(dccl.field) = { min_length: 5 max_length: 5 codec: "dccl.var_bytes" }];
59}
60
61// Invalid: min_length > max_length — should fail to load
62message InvalidMinLengthMsg
63{
64 option (dccl.msg) = {
65 id: 22
66 max_bytes: 32
67 codec_version: 4
68 };
69
70 required bytes bad_bytes = 1
71 [(dccl.field) = { min_length: 10 max_length: 5 codec: "dccl.var_bytes" }];
72}