├── .devcontainer ├── Dockerfile ├── devcontainer.json └── install-zig.sh ├── .gitattributes ├── .github └── workflows │ ├── scheduled_zig_master.yml │ ├── test_stable.yml │ └── test_zig_master.yml ├── .gitignore ├── LICENSE.md ├── README.md ├── bootstrapped-generator ├── FullName.zig ├── google │ ├── protobuf.pb.zig │ └── protobuf │ │ └── compiler.pb.zig └── main.zig ├── build.zig ├── build.zig.zon ├── src └── protobuf.zig └── tests ├── alltypes.zig ├── fixtures ├── graphics.bin └── vector_tile.bin ├── generated ├── google │ └── protobuf.pb.zig ├── graphics.pb.zig ├── jspb │ └── test.pb.zig ├── oneofselfref.pb.zig ├── opentelemetry │ └── proto │ │ ├── common │ │ └── v1.pb.zig │ │ ├── logs │ │ └── v1.pb.zig │ │ ├── metrics │ │ └── v1.pb.zig │ │ └── resource │ │ └── v1.pb.zig ├── protobuf_test_messages │ └── proto3.pb.zig ├── selfref.pb.zig ├── some │ └── really │ │ └── long │ │ └── name │ │ └── which │ │ └── does │ │ └── not │ │ └── really │ │ └── make │ │ └── any │ │ └── sense │ │ └── but │ │ └── sometimes │ │ └── we │ │ └── still │ │ └── see │ │ └── stuff │ │ └── like │ │ └── this.pb.zig ├── tests.pb.zig ├── tests │ ├── longs.pb.zig │ └── oneof.pb.zig ├── unittest.pb.zig └── vector_tile.pb.zig ├── graphics.zig ├── integration.zig ├── json_data ├── fixed_sizes │ ├── camelCase.json │ ├── camelCase_1.json │ ├── camelCase_2.json │ ├── camelCase_3.json │ └── instance.zig ├── more_bytes │ ├── camelCase.json │ └── instance.zig ├── oneof_container │ ├── message_in_oneof_camelCase.json │ ├── message_in_oneof_instance.zig │ ├── message_in_oneof_mixed_case1.json │ ├── message_in_oneof_mixed_case2.json │ ├── message_in_oneof_snake_case.json │ ├── string_in_oneof_camelCase.json │ ├── string_in_oneof_instance.zig │ ├── string_in_oneof_mixed_case1.json │ ├── string_in_oneof_mixed_case2.json │ └── string_in_oneof_snake_case.json ├── packed │ ├── camelCase.json │ ├── camelCase_1.json │ ├── instance.zig │ ├── mixed_case.json │ └── snake_case.json ├── repeated_enum │ ├── camelCase1.json │ ├── camelCase2.json │ ├── camelCase3.json │ └── instance.zig ├── test_oneof2 │ ├── camelCase.json │ └── instance.zig ├── test_packed_types │ ├── camelCase.json │ └── instance.zig ├── value │ ├── camelCase1.json │ ├── camelCase2.json │ ├── camelCase3.json │ ├── camelCase4.json │ ├── camelCase4_1.json │ ├── camelCase4_2.json │ ├── camelCase4_3.json │ ├── camelCase4_4.json │ ├── camelCase4_5.json │ ├── camelCase4_6.json │ └── instance.zig ├── with_bytes │ ├── camelCase.json │ ├── instance.zig │ └── snake_case.json ├── with_strings │ ├── camelCase.json │ └── instance.zig └── with_submessages │ ├── camelCase.json │ ├── camelCase_enum_as_integer.json │ ├── instance.zig │ └── snake_case.json ├── leaks.zig ├── mapbox.zig ├── oneof.zig ├── optionals.zig ├── protos_for_test ├── all.proto ├── fixedsizes.proto ├── generated_in_ci.proto ├── graphics.proto ├── jspb.proto ├── mapbox.proto ├── msg-long.proto ├── oneof.proto ├── oneofSelfRef.proto ├── opentelemetry │ └── proto │ │ ├── collector │ │ ├── README.md │ │ ├── logs │ │ │ └── v1 │ │ │ │ ├── logs_service.proto │ │ │ │ └── logs_service_http.yaml │ │ ├── metrics │ │ │ └── v1 │ │ │ │ ├── metrics_service.proto │ │ │ │ └── metrics_service_http.yaml │ │ ├── profiles │ │ │ └── v1experimental │ │ │ │ ├── profiles_service.proto │ │ │ │ └── profiles_service_http.yaml │ │ └── trace │ │ │ └── v1 │ │ │ ├── trace_service.proto │ │ │ └── trace_service_http.yaml │ │ ├── common │ │ └── v1 │ │ │ └── common.proto │ │ ├── logs │ │ └── v1 │ │ │ └── logs.proto │ │ ├── metrics │ │ └── v1 │ │ │ └── metrics.proto │ │ ├── profiles │ │ └── v1experimental │ │ │ ├── pprofextended.proto │ │ │ └── profiles.proto │ │ ├── resource │ │ └── v1 │ │ │ └── resource.proto │ │ └── trace │ │ └── v1 │ │ └── trace.proto ├── selfref.proto ├── test_messages_proto3.proto ├── unittest.proto └── whitespace-in-name.proto ├── tests.zig ├── tests_fixedsizes.zig ├── tests_json.zig └── tests_varints.zig /.devcontainer/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mcr.microsoft.com/devcontainers/typescript-node:0-18 2 | RUN git config --global core.autocrlf input 3 | 4 | ADD . . 5 | 6 | RUN bash ./install-zig.sh 0.14.0 7 | 8 | ENV AGREE=true 9 | -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Default Linux Universal", 3 | "build": { 4 | "dockerfile": "Dockerfile" 5 | }, 6 | "customizations": { 7 | "vscode": { 8 | "extensions": [ 9 | "ziglang.vscode-zig", 10 | "zxh404.vscode-proto3" 11 | ], 12 | "settings": { 13 | "zig.zls.enabled": true, 14 | "zig.zigPath": "/usr/local/bin/zig", 15 | "zig.zls.zigLibPath": "/usr/local/lib/zig/lib/", 16 | "zig.zls.path": "/usr/local/bin/zls", 17 | "zig.buildOption": "build" 18 | } 19 | } 20 | }, 21 | "containerEnv": { 22 | "SHELL": "/usr/bin/zsh" 23 | } 24 | } -------------------------------------------------------------------------------- /.devcontainer/install-zig.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | 4 | set -e 5 | set -x 6 | 7 | ZIG_VERSION=$1 8 | echo "v" $ZIG_VERSION 9 | 10 | if [ "$(id -u)" -ne 0 ]; then 11 | echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' 12 | exit 1 13 | fi 14 | 15 | # Clean up 16 | rm -rf /var/lib/apt/lists/* 17 | 18 | ARCH="$(uname -m)" 19 | 20 | # Checks if packages are installed and installs them if not 21 | check_packages() { 22 | if ! dpkg -s "$@" >/dev/null 2>&1; then 23 | if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then 24 | echo "Running apt-get update..." 25 | apt-get update -y 26 | fi 27 | apt-get -y install --no-install-recommends "$@" 28 | fi 29 | } 30 | 31 | check_packages ca-certificates xz-utils 32 | 33 | # remove existing instalations 34 | rm -rf /usr/local/lib/zig 35 | # make sure /usr/local/lib/zig exists 36 | mkdir -p /usr/local/lib/zig 37 | # download binary, untar and ln into /usr/local/bin 38 | 39 | ZIG_DOWNLOAD_URL=https://ziglang.org/download/$ZIG_VERSION/zig-linux-$(arch)-$ZIG_VERSION.tar.xz 40 | case $ZIG_VERSION in 41 | *"+"*) 42 | ZIG_DOWNLOAD_URL=https://ziglang.org/builds/zig-linux-$(arch)-$ZIG_VERSION.tar.xz 43 | ;; 44 | esac 45 | 46 | wget -c $ZIG_DOWNLOAD_URL -O - | tar -xJ --strip-components=1 -C /usr/local/lib/zig 47 | # make binary executable 48 | chmod +x /usr/local/lib/zig/zig 49 | # create symbolic link 50 | rm /usr/local/bin/zig || true 51 | ln -s /usr/local/lib/zig/zig /usr/local/bin/zig 52 | 53 | # install language server 54 | 55 | LATEST_ZLS=$(curl https://zigtools-releases.nyc3.digitaloceanspaces.com/zls/index.json | /usr/bin/jq -r '.latest') 56 | 57 | wget https://zigtools-releases.nyc3.digitaloceanspaces.com/zls/$LATEST_ZLS/$ARCH-linux/zls 58 | 59 | mv zls /usr/local/bin/zls 60 | 61 | # make binary executable 62 | chmod +x /usr/local/bin/zls 63 | 64 | # Clean up 65 | rm -rf /var/lib/apt/lists/* 66 | 67 | echo "Done!" -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | tests/json_data/**/*.json text eol=lf 2 | -------------------------------------------------------------------------------- /.github/workflows/scheduled_zig_master.yml: -------------------------------------------------------------------------------- 1 | name: scheduled_zig_master 2 | on: 3 | schedule: 4 | - cron: "30 1 1,15 * *" 5 | jobs: 6 | test_latest_scheduled: 7 | strategy: 8 | matrix: 9 | os: [ubuntu-latest, macos-latest, windows-latest] 10 | runs-on: ${{matrix.os}} 11 | steps: 12 | - uses: actions/checkout@v2 13 | with: 14 | ref: zig-master 15 | - uses: goto-bus-stop/setup-zig@v1 16 | with: 17 | version: master 18 | - run: zig build 19 | - run: zig build test -------------------------------------------------------------------------------- /.github/workflows/test_stable.yml: -------------------------------------------------------------------------------- 1 | name: test_and_lint_stable 2 | on: 3 | push: 4 | branches: 5 | - master 6 | pull_request: 7 | branches: 8 | - master 9 | jobs: 10 | test_stable: 11 | strategy: 12 | matrix: 13 | os: [ubuntu-latest, macos-latest, windows-latest] 14 | runs-on: ${{matrix.os}} 15 | steps: 16 | - uses: actions/checkout@v2 17 | - uses: goto-bus-stop/setup-zig@v1 18 | with: 19 | version: "0.14.0" 20 | - run: zig build 21 | - run: zig build test 22 | 23 | bootstrap: 24 | runs-on: ubuntu-latest 25 | steps: 26 | - uses: actions/checkout@v2 27 | - uses: goto-bus-stop/setup-zig@v1 28 | with: 29 | version: "0.14.0" 30 | - run: zig build test 31 | - run: zig build bootstrap 32 | - run: zig build test 33 | - run: zig build 34 | - run: git diff 35 | 36 | lint: 37 | runs-on: ubuntu-latest 38 | steps: 39 | - uses: actions/checkout@v2 40 | - uses: goto-bus-stop/setup-zig@v1 41 | with: 42 | version: "0.14.0" 43 | - run: zig fmt --check src/protobuf.zig 44 | -------------------------------------------------------------------------------- /.github/workflows/test_zig_master.yml: -------------------------------------------------------------------------------- 1 | name: test_and_lint_latest_zig 2 | on: 3 | push: 4 | branches: 5 | - zig-master 6 | pull_request: 7 | branches: 8 | - zig-master 9 | jobs: 10 | test_latest: 11 | strategy: 12 | matrix: 13 | os: [ubuntu-latest, macos-latest, windows-latest] 14 | runs-on: ${{matrix.os}} 15 | steps: 16 | - uses: actions/checkout@v2 17 | - uses: goto-bus-stop/setup-zig@v1 18 | with: 19 | version: master 20 | - run: zig build 21 | - run: zig build test 22 | 23 | bootstrap: 24 | runs-on: ubuntu-latest 25 | steps: 26 | - uses: actions/checkout@v2 27 | - uses: goto-bus-stop/setup-zig@v1 28 | with: 29 | version: master 30 | - run: zig build test 31 | - run: zig build bootstrap 32 | - run: zig build test 33 | - run: zig build 34 | - run: git diff 35 | 36 | lint: 37 | runs-on: ubuntu-latest 38 | steps: 39 | - uses: actions/checkout@v2 40 | - uses: goto-bus-stop/setup-zig@v1 41 | with: 42 | version: master 43 | - run: zig fmt --check src/protobuf.zig 44 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | zig-cache 2 | .vscode* 3 | .idea* 4 | *.exe 5 | **/.DS_Store 6 | generator/**/*.zig 7 | generator/**/protoc-gen-zig* 8 | zig-out 9 | generator/protoc-gen-main 10 | dcl 11 | protocol 12 | tests/.generated 13 | debug 14 | .zig-cache 15 | .specstory/* -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2021 Arwalk 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # zig-protobuf 2 | 3 | ------- 4 | 5 | ## Welcome! 6 | 7 | This is an implementation of google Protocol Buffers version 3 in Zig. 8 | 9 | Protocol Buffers is a serialization protocol so systems, from any programming language or platform, can exchange data reliably. 10 | 11 | Protobuf's strength lies in a generic codec paired with user-defined "messages" that will define the true nature of the data encoded. 12 | 13 | Messages are usually mapped to a native language's structure/class definition thanks to a language-specific generator associated with an implementation. 14 | 15 | Zig's compile-time evaluation becomes extremely strong and useful in this context: because the structure (a message) has to be known beforehand, the generic codec can leverage informations, at compile time, of the message and it's nature. This allows optimizations that are hard to get as easily in any other language, as Zig can mix compile-time informations with runtime-only data to optimize the encoding and decoding code paths. 16 | 17 | ## State of the implementation 18 | 19 | This repository, so far, only aims at implementing [protocol buffers version 3](https://developers.google.com/protocol-buffers/docs/proto3#simple). 20 | 21 | The latest version of the zig compiler used for this project is 0.14.0. 22 | 23 | This project is currently able to handle all scalar types for encoding, decoding, and generation through the plugin. 24 | 25 | ## Branches 26 | 27 | There are 2 branches you can use for your development. 28 | 29 | * `master` is the branch with current developments, working with the latest stable release of zig. 30 | * `zig-master` is a branch that merges the developments in master, but works with the latest-ish master version of zig. 31 | 32 | ## How to use 33 | 34 | 1. Add `protobuf` to your `build.zig.zon`. 35 | ```sh 36 | zig fetch --save "git+https://github.com/Arwalk/zig-protobuf#v2.0.0" 37 | ``` 38 | 1. Use the `protobuf` module. In your `build.zig`'s build function, add the dependency as module before 39 | `b.installArtifact(exe)`. 40 | ```zig 41 | pub fn build(b: *std.Build) !void { 42 | // first create a build for the dependency 43 | const protobuf_dep = b.dependency("protobuf", .{ 44 | .target = target, 45 | .optimize = optimize, 46 | }); 47 | 48 | // and lastly use the dependency as a module 49 | exe.root_module.addImport("protobuf", protobuf_dep.module("protobuf")); 50 | } 51 | ``` 52 | 53 | ## Generating .zig files out of .proto definitions 54 | 55 | You can do this programatically as a compilation step for your application. The following snippet shows how to create a `zig build gen-proto` command for your project. 56 | 57 | ```zig 58 | const protobuf = @import("protobuf"); 59 | 60 | pub fn build(b: *std.Build) !void { 61 | // first create a build for the dependency 62 | const protobuf_dep = b.dependency("protobuf", .{ 63 | .target = target, 64 | .optimize = optimize, 65 | }); 66 | 67 | ... 68 | 69 | const gen_proto = b.step("gen-proto", "generates zig files from protocol buffer definitions"); 70 | 71 | const protoc_step = protobuf.RunProtocStep.create(b, protobuf_dep.builder, target, .{ 72 | // out directory for the generated zig files 73 | .destination_directory = b.path("src/proto"), 74 | .source_files = &.{ 75 | "protocol/all.proto", 76 | }, 77 | .include_directories = &.{}, 78 | }); 79 | 80 | gen_proto.dependOn(&protoc_step.step); 81 | } 82 | ``` 83 | 84 | If you're really bored, you can buy me a coffe here. 85 | 86 | [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/N4N7VMS4F) 87 | -------------------------------------------------------------------------------- /bootstrapped-generator/FullName.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | 3 | pub const FullName = struct { 4 | buf: []const u8, 5 | 6 | const Self = @This(); 7 | 8 | /// this function receives a []const u8 "head" and concatenates head + '.' + tail. returns the value 9 | pub fn append(self: Self, allocator: std.mem.Allocator, tail: []const u8) !FullName { 10 | return FullName{ .buf = try std.mem.concat(allocator, u8, &.{ self.buf, ".", tail }) }; 11 | } 12 | 13 | /// Name returns the short name, which is the last identifier segment. 14 | /// A single segment FullName is the Name itself. 15 | pub fn name(self: Self) FullName { 16 | if (std.mem.lastIndexOfLinear(u8, self.buf, ".")) |i| { 17 | return FullName{ .buf = self.buf[i + 1 ..] }; 18 | } 19 | return self; 20 | } 21 | 22 | /// Parent returns the full name with the trailing identifier removed. 23 | /// A single segment FullName has no parent. 24 | pub fn parent(self: Self) ?FullName { 25 | if (std.mem.lastIndexOfLinear(u8, self.buf, ".")) |i| { 26 | return FullName{ .buf = self.buf[0..i] }; 27 | } 28 | return null; 29 | } 30 | 31 | pub fn eql(self: Self, other: FullName) bool { 32 | return std.mem.eql(u8, self.buf, other.buf); 33 | } 34 | 35 | pub fn eqlString(self: Self, other: []const u8) bool { 36 | return std.mem.eql(u8, self.buf, other); 37 | } 38 | }; 39 | 40 | test { 41 | var initial = FullName{ .buf = "aa.bb.cc.dd.ee" }; 42 | 43 | try std.testing.expect(initial.eql(initial)); 44 | try std.testing.expect(initial.eqlString(initial.buf)); 45 | try std.testing.expect(!initial.eqlString("aa")); 46 | 47 | try std.testing.expectEqualSlices(u8, "ee", initial.name().buf); 48 | try std.testing.expectEqualSlices(u8, "aa.bb.cc.dd", initial.parent().?.buf); 49 | try std.testing.expectEqualSlices(u8, "aa.bb.cc", initial.parent().?.parent().?.buf); 50 | try std.testing.expectEqualSlices(u8, "aa.bb", initial.parent().?.parent().?.parent().?.buf); 51 | try std.testing.expectEqualSlices(u8, "aa", initial.parent().?.parent().?.parent().?.parent().?.buf); 52 | try std.testing.expect(initial.parent().?.parent().?.parent().?.parent().?.parent() == null); 53 | 54 | var simple = FullName{ .buf = "ee" }; 55 | try std.testing.expectEqualSlices(u8, "ee", simple.name().buf); 56 | try std.testing.expect(simple.parent() == null); 57 | } 58 | -------------------------------------------------------------------------------- /bootstrapped-generator/google/protobuf/compiler.pb.zig: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-zig 2 | ///! package google.protobuf.compiler 3 | const std = @import("std"); 4 | const Allocator = std.mem.Allocator; 5 | const ArrayList = std.ArrayList; 6 | 7 | const protobuf = @import("protobuf"); 8 | const ManagedString = protobuf.ManagedString; 9 | const fd = protobuf.fd; 10 | /// import package google.protobuf 11 | const google_protobuf = @import("../protobuf.pb.zig"); 12 | 13 | pub const Version = struct { 14 | major: ?i32 = null, 15 | minor: ?i32 = null, 16 | patch: ?i32 = null, 17 | suffix: ?ManagedString = null, 18 | 19 | pub const _desc_table = .{ 20 | .major = fd(1, .{ .Varint = .Simple }), 21 | .minor = fd(2, .{ .Varint = .Simple }), 22 | .patch = fd(3, .{ .Varint = .Simple }), 23 | .suffix = fd(4, .String), 24 | }; 25 | 26 | pub usingnamespace protobuf.MessageMixins(@This()); 27 | }; 28 | 29 | pub const CodeGeneratorRequest = struct { 30 | file_to_generate: ArrayList(ManagedString), 31 | parameter: ?ManagedString = null, 32 | proto_file: ArrayList(google_protobuf.FileDescriptorProto), 33 | compiler_version: ?Version = null, 34 | 35 | pub const _desc_table = .{ 36 | .file_to_generate = fd(1, .{ .List = .String }), 37 | .parameter = fd(2, .String), 38 | .proto_file = fd(15, .{ .List = .{ .SubMessage = {} } }), 39 | .compiler_version = fd(3, .{ .SubMessage = {} }), 40 | }; 41 | 42 | pub usingnamespace protobuf.MessageMixins(@This()); 43 | }; 44 | 45 | pub const CodeGeneratorResponse = struct { 46 | @"error": ?ManagedString = null, 47 | supported_features: ?u64 = null, 48 | file: ArrayList(File), 49 | 50 | pub const _desc_table = .{ 51 | .@"error" = fd(1, .String), 52 | .supported_features = fd(2, .{ .Varint = .Simple }), 53 | .file = fd(15, .{ .List = .{ .SubMessage = {} } }), 54 | }; 55 | 56 | pub const Feature = enum(i32) { 57 | FEATURE_NONE = 0, 58 | FEATURE_PROTO3_OPTIONAL = 1, 59 | _, 60 | }; 61 | 62 | pub const File = struct { 63 | name: ?ManagedString = null, 64 | insertion_point: ?ManagedString = null, 65 | content: ?ManagedString = null, 66 | generated_code_info: ?google_protobuf.GeneratedCodeInfo = null, 67 | 68 | pub const _desc_table = .{ 69 | .name = fd(1, .String), 70 | .insertion_point = fd(2, .String), 71 | .content = fd(15, .String), 72 | .generated_code_info = fd(16, .{ .SubMessage = {} }), 73 | }; 74 | 75 | pub usingnamespace protobuf.MessageMixins(@This()); 76 | }; 77 | 78 | pub usingnamespace protobuf.MessageMixins(@This()); 79 | }; 80 | -------------------------------------------------------------------------------- /build.zig.zon: -------------------------------------------------------------------------------- 1 | .{ 2 | .name = .protobuf, 3 | // This is a [Semantic Version](https://semver.org/). 4 | // In a future version of Zig it will be used for package deduplication. 5 | .version = "2.0.0", 6 | 7 | .fingerprint = 0x99fac5be6a36efd1, 8 | 9 | // This field is optional. 10 | // This is currently advisory only; Zig does not yet do anything 11 | // with this value. 12 | .minimum_zig_version = "0.14.0", 13 | 14 | // This field is optional. 15 | // Each dependency must either provide a `url` and `hash`, or a `path`. 16 | // `zig build --fetch` can be used to fetch all dependencies of a package, recursively. 17 | // Once all dependencies are fetched, `zig build` no longer requires 18 | // internet connectivity. 19 | //.dependencies = .{ 20 | //}, 21 | 22 | // Specifies the set of files and directories that are included in this package. 23 | // Only files and directories listed here are included in the `hash` that 24 | // is computed for this package. 25 | // Paths are relative to the build root. Use the empty string (`""`) to refer to 26 | // the build root itself. 27 | // A directory listed here means that all files within, recursively, are included. 28 | .paths = .{ 29 | // This makes *all* files, recursively, included in this package. It is generally 30 | // better to explicitly list the files and directories instead, to insure that 31 | // fetching from tarballs, file system paths, and version control all result 32 | // in the same contents hash. 33 | "", 34 | // For example... 35 | //"build.zig", 36 | //"build.zig.zon", 37 | //"src", 38 | //"LICENSE", 39 | //"README.md", 40 | "build.zig", 41 | "build.zig.zon", 42 | "LICENSE.md", 43 | "README.md", 44 | ".gitignore", 45 | ".devcontainer", 46 | ".github", 47 | "bootstrapped-generator", 48 | "src", 49 | "tests", 50 | }, 51 | } 52 | -------------------------------------------------------------------------------- /tests/alltypes.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const testing = std.testing; 3 | 4 | const protobuf = @import("protobuf"); 5 | const tests = @import("./generated/tests.pb.zig"); 6 | const proto3 = @import("./generated/protobuf_test_messages/proto3.pb.zig"); 7 | const longs = @import("./generated/tests/longs.pb.zig"); 8 | const jspb = @import("./generated/jspb/test.pb.zig"); 9 | const unittest = @import("./generated/unittest.pb.zig"); 10 | const longName = @import("./generated/some/really/long/name/which/does/not/really/make/any/sense/but/sometimes/we/still/see/stuff/like/this.pb.zig"); 11 | 12 | pub fn printAllDecoded(input: []const u8) !void { 13 | var iterator = protobuf.WireDecoderIterator{ .input = input }; 14 | std.debug.print("Decoding: {s}\n", .{std.fmt.fmtSliceHexUpper(input)}); 15 | while (try iterator.next()) |extracted_data| { 16 | std.debug.print(" {any}\n", .{extracted_data}); 17 | } 18 | } 19 | 20 | test "long package" { 21 | // - this test allocates an object only. used to instruct zig to try to compile the file 22 | // - it also ensures that SubMessage deinit() works 23 | var demo = longName.WouldYouParseThisForMePlease.init(testing.allocator); 24 | demo.field = .{ .field = .{ .Const = "asd" } }; 25 | defer demo.deinit(); 26 | 27 | const obtained = try demo.encode(testing.allocator); 28 | defer testing.allocator.free(obtained); 29 | } 30 | 31 | test "packed int32_list encoding" { 32 | var demo = tests.Packed.init(testing.allocator); 33 | try demo.int32_list.append(0x01); 34 | try demo.int32_list.append(0x02); 35 | try demo.int32_list.append(0x03); 36 | try demo.int32_list.append(0x04); 37 | defer demo.deinit(); 38 | 39 | const obtained = try demo.encode(testing.allocator); 40 | defer testing.allocator.free(obtained); 41 | 42 | try testing.expectEqualSlices(u8, &[_]u8{ 43 | // fieldNumber=1<<3 packetType=2 (LEN) 44 | (1 << 3) + 2, 45 | // 4 bytes 46 | 0x04, 47 | // payload 48 | 0x01, 49 | 0x02, 50 | 0x03, 51 | 0x04, 52 | }, obtained); 53 | 54 | const decoded = try tests.Packed.decode(obtained, testing.allocator); 55 | defer decoded.deinit(); 56 | try testing.expectEqualSlices(i32, demo.int32_list.items, decoded.int32_list.items); 57 | } 58 | 59 | test "unpacked int32_list" { 60 | var demo = tests.UnPacked.init(testing.allocator); 61 | try demo.int32_list.append(0x01); 62 | try demo.int32_list.append(0x02); 63 | try demo.int32_list.append(0x03); 64 | try demo.int32_list.append(0x04); 65 | defer demo.deinit(); 66 | 67 | const obtained = try demo.encode(testing.allocator); 68 | defer testing.allocator.free(obtained); 69 | 70 | try testing.expectEqualSlices(u8, &[_]u8{ 0x08, 0x01, 0x08, 0x02, 0x08, 0x03, 0x08, 0x04 }, obtained); 71 | 72 | const decoded = try tests.UnPacked.decode(obtained, testing.allocator); 73 | defer decoded.deinit(); 74 | try testing.expectEqualSlices(i32, demo.int32_list.items, decoded.int32_list.items); 75 | } 76 | 77 | test "Required.Proto3.ProtobufInput.ValidDataRepeated.BOOL.PackedInput.ProtobufOutput" { 78 | const bytes = "\xda\x02\x28\x00\x01\xff\xff\xff\xff\xff\xff\xff\xff\xff\x01\xce\xc2\xf1\x05\x80\x80\x80\x80\x20\xff\xff\xff\xff\xff\xff\xff\xff\x7f\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01"; 79 | const m = try proto3.TestAllTypesProto3.decode(bytes, testing.allocator); 80 | defer m.deinit(); 81 | 82 | // TODO: try testing.expectEqualSlices(bool, &[_]bool{ false, false, false, false, true, false, false }, m.repeated_bool.items); 83 | } 84 | 85 | test "msg-longs.proto" { 86 | const bytes = &[_]u8{ 17, 255, 255, 255, 255, 255, 255, 255, 255, 24, 128, 128, 128, 128, 128, 128, 128, 128, 128, 1, 32, 255, 255, 255, 255, 255, 255, 255, 255, 127, 41, 0, 0, 0, 0, 0, 0, 0, 128, 49, 255, 255, 255, 255, 255, 255, 255, 127, 56, 255, 255, 255, 255, 255, 255, 255, 255, 255, 1, 64, 254, 255, 255, 255, 255, 255, 255, 255, 255, 1, 80, 255, 255, 255, 255, 255, 255, 255, 255, 255, 1, 97, 255, 255, 255, 255, 255, 255, 255, 255, 104, 128, 128, 128, 128, 128, 128, 128, 128, 128, 1, 112, 255, 255, 255, 255, 255, 255, 255, 255, 127, 121, 0, 0, 0, 0, 0, 0, 0, 128, 129, 1, 255, 255, 255, 255, 255, 255, 255, 127, 136, 1, 255, 255, 255, 255, 255, 255, 255, 255, 255, 1, 144, 1, 254, 255, 255, 255, 255, 255, 255, 255, 255, 1, 160, 1, 255, 255, 255, 255, 255, 255, 255, 255, 255, 1, 177, 1, 255, 255, 255, 255, 255, 255, 255, 255, 184, 1, 128, 128, 128, 128, 128, 128, 128, 128, 128, 1, 192, 1, 255, 255, 255, 255, 255, 255, 255, 255, 127, 201, 1, 0, 0, 0, 0, 0, 0, 0, 128, 209, 1, 255, 255, 255, 255, 255, 255, 255, 127, 216, 1, 255, 255, 255, 255, 255, 255, 255, 255, 255, 1, 224, 1, 254, 255, 255, 255, 255, 255, 255, 255, 255, 1, 240, 1, 255, 255, 255, 255, 255, 255, 255, 255, 255, 1 }; 87 | var decoded = try longs.LongsMessage.decode(bytes, testing.allocator); 88 | defer decoded.deinit(); 89 | 90 | try testing.expectEqual(@as(u64, 0), decoded.fixed64_field_min); 91 | try testing.expectEqual(@as(u64, 18446744073709551615), decoded.fixed64_field_max); 92 | try testing.expectEqual(@as(i64, -9223372036854775808), decoded.int64_field_min); 93 | try testing.expectEqual(@as(i64, 9223372036854775807), decoded.int64_field_max); 94 | try testing.expectEqual(@as(i64, -9223372036854775808), decoded.sfixed64_field_min); 95 | try testing.expectEqual(@as(i64, 9223372036854775807), decoded.sfixed64_field_max); 96 | try testing.expectEqual(@as(i64, -9223372036854775808), decoded.sint64_field_min); 97 | try testing.expectEqual(@as(i64, 9223372036854775807), decoded.sint64_field_max); 98 | try testing.expectEqual(@as(u64, 0), decoded.uint64_field_min); 99 | try testing.expectEqual(@as(u64, 18446744073709551615), decoded.uint64_field_max); 100 | } 101 | 102 | test "TestExtremeDefaultValues" { 103 | var decoded = try unittest.TestExtremeDefaultValues.decode("", testing.allocator); 104 | defer decoded.deinit(); 105 | 106 | try testing.expectEqualSlices(u8, "\\000\\001\\007\\010\\014\\n\\r\\t\\013\\\\\\'\\\"\\376", decoded.escaped_bytes.?.getSlice()); 107 | try testing.expectEqual(@as(u32, 4294967295), decoded.large_uint32.?); 108 | try testing.expectEqual(@as(u64, 18446744073709551615), decoded.large_uint64.?); 109 | try testing.expectEqual(@as(i32, -2147483647), decoded.small_int32.?); 110 | try testing.expectEqual(@as(i64, -9223372036854775807), decoded.small_int64.?); 111 | try testing.expectEqual(@as(i32, -2147483648), decoded.really_small_int32.?); 112 | try testing.expectEqual(@as(i64, -9223372036854775808), decoded.really_small_int64.?); 113 | try testing.expectEqualSlices(u8, "\xE1\x88\xB4", decoded.utf8_string.?.getSlice()); 114 | try testing.expectEqual(@as(f32, 0), decoded.zero_float.?); 115 | try testing.expectEqual(@as(f32, 1), decoded.one_float.?); 116 | try testing.expectEqual(@as(f32, 1.5), decoded.small_float.?); 117 | try testing.expectEqual(@as(f32, -1), decoded.negative_one_float.?); 118 | try testing.expectEqual(@as(f32, -1.5), decoded.negative_float.?); 119 | try testing.expectEqual(@as(f32, 2e+08), decoded.large_float.?); 120 | try testing.expectEqual(@as(f32, -8e-28), decoded.small_negative_float.?); 121 | try testing.expectEqual(@as(f64, std.math.inf(f64)), decoded.inf_double.?); 122 | try testing.expectEqual(@as(f64, -std.math.inf(f64)), decoded.neg_inf_double.?); 123 | try testing.expect(std.math.isNan(decoded.nan_double.?)); 124 | try testing.expectEqual(@as(f32, std.math.inf(f32)), decoded.inf_float.?); 125 | try testing.expectEqual(@as(f32, -std.math.inf(f32)), decoded.neg_inf_float.?); 126 | try testing.expect(std.math.isNan(decoded.nan_float.?)); 127 | try testing.expectEqualSlices(u8, "? ? ?? ?? ??? ??/ ??-", decoded.cpp_trigraph.?.getSlice()); 128 | try testing.expectEqualSlices(u8, "hel\x00lo", decoded.string_with_zero.?.getSlice()); 129 | try testing.expectEqualSlices(u8, "wor\\000ld", decoded.bytes_with_zero.?.getSlice()); 130 | try testing.expectEqualSlices(u8, "ab\x00c", decoded.string_piece_with_zero.?.getSlice()); 131 | try testing.expectEqualSlices(u8, "12\x003", decoded.cord_with_zero.?.getSlice()); 132 | try testing.expectEqualSlices(u8, "${unknown}", decoded.replacement_string.?.getSlice()); 133 | } 134 | -------------------------------------------------------------------------------- /tests/fixtures/graphics.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arwalk/zig-protobuf/77161cbf10625fea90ee3bf6eee47e6b8c587845/tests/fixtures/graphics.bin -------------------------------------------------------------------------------- /tests/fixtures/vector_tile.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Arwalk/zig-protobuf/77161cbf10625fea90ee3bf6eee47e6b8c587845/tests/fixtures/vector_tile.bin -------------------------------------------------------------------------------- /tests/generated/graphics.pb.zig: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-zig 2 | ///! package graphics 3 | const std = @import("std"); 4 | const Allocator = std.mem.Allocator; 5 | const ArrayList = std.ArrayList; 6 | 7 | const protobuf = @import("protobuf"); 8 | const ManagedString = protobuf.ManagedString; 9 | const fd = protobuf.fd; 10 | const ManagedStruct = protobuf.ManagedStruct; 11 | 12 | pub const InventoryItem = struct { 13 | slot: i32 = 0, 14 | name: ManagedString = .Empty, 15 | image: i32 = 0, 16 | quantity: i32 = 0, 17 | description: ManagedString = .Empty, 18 | id: i32 = 0, 19 | 20 | pub const _desc_table = .{ 21 | .slot = fd(1, .{ .Varint = .Simple }), 22 | .name = fd(2, .String), 23 | .image = fd(3, .{ .Varint = .Simple }), 24 | .quantity = fd(4, .{ .Varint = .Simple }), 25 | .description = fd(5, .String), 26 | .id = fd(6, .{ .Varint = .Simple }), 27 | }; 28 | 29 | pub usingnamespace protobuf.MessageMixins(@This()); 30 | }; 31 | 32 | pub const Character = struct { 33 | id: ManagedString = .Empty, 34 | class: i32 = 0, 35 | gender: i32 = 0, 36 | race: i32 = 0, 37 | head: i32 = 0, 38 | body: i32 = 0, 39 | helmet: i32 = 0, 40 | right_hand: i32 = 0, 41 | nick: ManagedString = .Empty, 42 | left_hand: i32 = 0, 43 | color: ManagedString = .Empty, 44 | clan: ManagedString = .Empty, 45 | enabled: bool = false, 46 | 47 | pub const _desc_table = .{ 48 | .id = fd(1, .String), 49 | .class = fd(2, .{ .Varint = .Simple }), 50 | .gender = fd(3, .{ .Varint = .Simple }), 51 | .race = fd(4, .{ .Varint = .Simple }), 52 | .head = fd(5, .{ .Varint = .Simple }), 53 | .body = fd(6, .{ .Varint = .Simple }), 54 | .helmet = fd(7, .{ .Varint = .Simple }), 55 | .right_hand = fd(8, .{ .Varint = .Simple }), 56 | .nick = fd(9, .String), 57 | .left_hand = fd(10, .{ .Varint = .Simple }), 58 | .color = fd(11, .String), 59 | .clan = fd(12, .String), 60 | .enabled = fd(13, .{ .Varint = .Simple }), 61 | }; 62 | 63 | pub usingnamespace protobuf.MessageMixins(@This()); 64 | }; 65 | 66 | pub const Alignment = struct { 67 | id: ManagedString = .Empty, 68 | name: ManagedString = .Empty, 69 | color: ManagedString = .Empty, 70 | 71 | pub const _desc_table = .{ 72 | .id = fd(1, .String), 73 | .name = fd(2, .String), 74 | .color = fd(3, .String), 75 | }; 76 | 77 | pub usingnamespace protobuf.MessageMixins(@This()); 78 | }; 79 | 80 | pub const Index = struct { 81 | id: i32 = 0, 82 | grh: ArrayList(i32), 83 | offset_x: i32 = 0, 84 | offset_y: i32 = 0, 85 | animations: ArrayList(AnimationsEntry), 86 | name: ManagedString = .Empty, 87 | 88 | pub const _desc_table = .{ 89 | .id = fd(1, .{ .Varint = .Simple }), 90 | .grh = fd(2, .{ .PackedList = .{ .Varint = .Simple } }), 91 | .offset_x = fd(3, .{ .Varint = .Simple }), 92 | .offset_y = fd(4, .{ .Varint = .Simple }), 93 | .animations = fd(5, .{ .List = .{ .SubMessage = {} } }), 94 | .name = fd(6, .String), 95 | }; 96 | 97 | pub const AnimationsEntry = struct { 98 | key: ManagedString = .Empty, 99 | value: i32 = 0, 100 | 101 | pub const _desc_table = .{ 102 | .key = fd(1, .String), 103 | .value = fd(2, .{ .Varint = .Simple }), 104 | }; 105 | 106 | pub usingnamespace protobuf.MessageMixins(@This()); 107 | }; 108 | 109 | pub usingnamespace protobuf.MessageMixins(@This()); 110 | }; 111 | 112 | pub const StoredChunk = struct { 113 | chunk_id: i32 = 0, 114 | entities: ArrayList(MapEntity), 115 | 116 | pub const _desc_table = .{ 117 | .chunk_id = fd(1, .{ .Varint = .Simple }), 118 | .entities = fd(2, .{ .List = .{ .SubMessage = {} } }), 119 | }; 120 | 121 | pub usingnamespace protobuf.MessageMixins(@This()); 122 | }; 123 | 124 | pub const MapEntity = struct { 125 | x: i32 = 0, 126 | y: i32 = 0, 127 | light: ?Light = null, 128 | collider: ?Shape = null, 129 | graphic_id: i32 = 0, 130 | entity_id: ManagedString = .Empty, 131 | vertical_graphic: bool = false, 132 | 133 | pub const _desc_table = .{ 134 | .x = fd(1, .{ .Varint = .Simple }), 135 | .y = fd(2, .{ .Varint = .Simple }), 136 | .light = fd(3, .{ .SubMessage = {} }), 137 | .collider = fd(4, .{ .SubMessage = {} }), 138 | .graphic_id = fd(5, .{ .Varint = .Simple }), 139 | .entity_id = fd(6, .String), 140 | .vertical_graphic = fd(7, .{ .Varint = .Simple }), 141 | }; 142 | 143 | pub usingnamespace protobuf.MessageMixins(@This()); 144 | }; 145 | 146 | pub const Light = struct { 147 | hue: f32 = 0, 148 | height: f32 = 0, 149 | radius: f32 = 0, 150 | saturation: f32 = 0, 151 | fall_off: f32 = 0, 152 | 153 | pub const _desc_table = .{ 154 | .hue = fd(1, .{ .FixedInt = .I32 }), 155 | .height = fd(2, .{ .FixedInt = .I32 }), 156 | .radius = fd(3, .{ .FixedInt = .I32 }), 157 | .saturation = fd(4, .{ .FixedInt = .I32 }), 158 | .fall_off = fd(5, .{ .FixedInt = .I32 }), 159 | }; 160 | 161 | pub usingnamespace protobuf.MessageMixins(@This()); 162 | }; 163 | 164 | pub const Point = struct { 165 | x: i32 = 0, 166 | y: i32 = 0, 167 | 168 | pub const _desc_table = .{ 169 | .x = fd(1, .{ .Varint = .Simple }), 170 | .y = fd(2, .{ .Varint = .Simple }), 171 | }; 172 | 173 | pub usingnamespace protobuf.MessageMixins(@This()); 174 | }; 175 | 176 | pub const Shape = struct { 177 | points: ArrayList(Point), 178 | 179 | pub const _desc_table = .{ 180 | .points = fd(1, .{ .List = .{ .SubMessage = {} } }), 181 | }; 182 | 183 | pub usingnamespace protobuf.MessageMixins(@This()); 184 | }; 185 | 186 | pub const Npc = struct { 187 | x: i32 = 0, 188 | y: i32 = 0, 189 | items: ArrayList(InventoryItem), 190 | name: ManagedString = .Empty, 191 | alignment: ManagedString = .Empty, 192 | ai: ManagedString = .Empty, 193 | min_hp: i32 = 0, 194 | max_hp: i32 = 0, 195 | min_mana: i32 = 0, 196 | max_mana: i32 = 0, 197 | min_strenght: i32 = 0, 198 | max_strenght: i32 = 0, 199 | skills: ArrayList(SkillsEntry), 200 | abilities: ArrayList(AbilitiesEntry), 201 | visual: ?Character = null, 202 | 203 | pub const _desc_table = .{ 204 | .x = fd(1, .{ .Varint = .Simple }), 205 | .y = fd(2, .{ .Varint = .Simple }), 206 | .items = fd(3, .{ .List = .{ .SubMessage = {} } }), 207 | .name = fd(4, .String), 208 | .alignment = fd(5, .String), 209 | .ai = fd(6, .String), 210 | .min_hp = fd(7, .{ .Varint = .Simple }), 211 | .max_hp = fd(8, .{ .Varint = .Simple }), 212 | .min_mana = fd(9, .{ .Varint = .Simple }), 213 | .max_mana = fd(10, .{ .Varint = .Simple }), 214 | .min_strenght = fd(11, .{ .Varint = .Simple }), 215 | .max_strenght = fd(12, .{ .Varint = .Simple }), 216 | .skills = fd(13, .{ .List = .{ .SubMessage = {} } }), 217 | .abilities = fd(14, .{ .List = .{ .SubMessage = {} } }), 218 | .visual = fd(15, .{ .SubMessage = {} }), 219 | }; 220 | 221 | pub const SkillsEntry = struct { 222 | key: i32 = 0, 223 | value: i32 = 0, 224 | 225 | pub const _desc_table = .{ 226 | .key = fd(1, .{ .Varint = .Simple }), 227 | .value = fd(2, .{ .Varint = .Simple }), 228 | }; 229 | 230 | pub usingnamespace protobuf.MessageMixins(@This()); 231 | }; 232 | 233 | pub const AbilitiesEntry = struct { 234 | key: i32 = 0, 235 | value: i32 = 0, 236 | 237 | pub const _desc_table = .{ 238 | .key = fd(1, .{ .Varint = .Simple }), 239 | .value = fd(2, .{ .Varint = .Simple }), 240 | }; 241 | 242 | pub usingnamespace protobuf.MessageMixins(@This()); 243 | }; 244 | 245 | pub usingnamespace protobuf.MessageMixins(@This()); 246 | }; 247 | 248 | pub const Tile = struct { 249 | x: i32 = 0, 250 | y: i32 = 0, 251 | tileset_grh: i32 = 0, 252 | tileset: i32 = 0, 253 | flags: i32 = 0, 254 | blocked: i32 = 0, 255 | layer2: i32 = 0, 256 | layer3: i32 = 0, 257 | layer4: i32 = 0, 258 | 259 | pub const _desc_table = .{ 260 | .x = fd(1, .{ .Varint = .Simple }), 261 | .y = fd(2, .{ .Varint = .Simple }), 262 | .tileset_grh = fd(3, .{ .Varint = .Simple }), 263 | .tileset = fd(4, .{ .Varint = .Simple }), 264 | .flags = fd(5, .{ .Varint = .Simple }), 265 | .blocked = fd(6, .{ .Varint = .Simple }), 266 | .layer2 = fd(7, .{ .Varint = .Simple }), 267 | .layer3 = fd(8, .{ .Varint = .Simple }), 268 | .layer4 = fd(9, .{ .Varint = .Simple }), 269 | }; 270 | 271 | pub usingnamespace protobuf.MessageMixins(@This()); 272 | }; 273 | 274 | pub const MapItem = struct { 275 | x: i32 = 0, 276 | y: i32 = 0, 277 | item: i32 = 0, 278 | amount: i32 = 0, 279 | 280 | pub const _desc_table = .{ 281 | .x = fd(1, .{ .Varint = .Simple }), 282 | .y = fd(2, .{ .Varint = .Simple }), 283 | .item = fd(3, .{ .Varint = .Simple }), 284 | .amount = fd(4, .{ .Varint = .Simple }), 285 | }; 286 | 287 | pub usingnamespace protobuf.MessageMixins(@This()); 288 | }; 289 | 290 | pub const GraphicsDB = struct { 291 | textures: ArrayList(Texture), 292 | graphics: ArrayList(Graphic), 293 | bodies: ArrayList(Index), 294 | fxs: ArrayList(Index), 295 | heads: ArrayList(Index), 296 | helmets: ArrayList(Index), 297 | shields: ArrayList(Index), 298 | weapons: ArrayList(Index), 299 | scripts: ArrayList(Script), 300 | spine: ArrayList(Spine), 301 | 302 | pub const _desc_table = .{ 303 | .textures = fd(1, .{ .List = .{ .SubMessage = {} } }), 304 | .graphics = fd(2, .{ .List = .{ .SubMessage = {} } }), 305 | .bodies = fd(4, .{ .List = .{ .SubMessage = {} } }), 306 | .fxs = fd(5, .{ .List = .{ .SubMessage = {} } }), 307 | .heads = fd(6, .{ .List = .{ .SubMessage = {} } }), 308 | .helmets = fd(7, .{ .List = .{ .SubMessage = {} } }), 309 | .shields = fd(8, .{ .List = .{ .SubMessage = {} } }), 310 | .weapons = fd(9, .{ .List = .{ .SubMessage = {} } }), 311 | .scripts = fd(10, .{ .List = .{ .SubMessage = {} } }), 312 | .spine = fd(11, .{ .List = .{ .SubMessage = {} } }), 313 | }; 314 | 315 | pub usingnamespace protobuf.MessageMixins(@This()); 316 | }; 317 | 318 | pub const Script = struct { 319 | path: ManagedString = .Empty, 320 | code: ManagedString = .Empty, 321 | 322 | pub const _desc_table = .{ 323 | .path = fd(1, .String), 324 | .code = fd(2, .String), 325 | }; 326 | 327 | pub usingnamespace protobuf.MessageMixins(@This()); 328 | }; 329 | 330 | pub const SubTexture = struct { 331 | diffuse: ManagedString = .Empty, 332 | normal: ManagedString = .Empty, 333 | emmisive: ManagedString = .Empty, 334 | width: i32 = 0, 335 | height: i32 = 0, 336 | 337 | pub const _desc_table = .{ 338 | .diffuse = fd(1, .String), 339 | .normal = fd(2, .String), 340 | .emmisive = fd(3, .String), 341 | .width = fd(4, .{ .Varint = .Simple }), 342 | .height = fd(5, .{ .Varint = .Simple }), 343 | }; 344 | 345 | pub usingnamespace protobuf.MessageMixins(@This()); 346 | }; 347 | 348 | pub const Texture = struct { 349 | diffuse: ManagedString = .Empty, 350 | normal: ManagedString = .Empty, 351 | emmisive: ManagedString = .Empty, 352 | width: i32 = 0, 353 | height: i32 = 0, 354 | dxt1: ?SubTexture = null, 355 | dxt3: ?SubTexture = null, 356 | dxt5: ?SubTexture = null, 357 | 358 | pub const _desc_table = .{ 359 | .diffuse = fd(1, .String), 360 | .normal = fd(2, .String), 361 | .emmisive = fd(3, .String), 362 | .width = fd(4, .{ .Varint = .Simple }), 363 | .height = fd(5, .{ .Varint = .Simple }), 364 | .dxt1 = fd(6, .{ .SubMessage = {} }), 365 | .dxt3 = fd(7, .{ .SubMessage = {} }), 366 | .dxt5 = fd(8, .{ .SubMessage = {} }), 367 | }; 368 | 369 | pub usingnamespace protobuf.MessageMixins(@This()); 370 | }; 371 | 372 | pub const Graphic = struct { 373 | id: i32 = 0, 374 | name: ManagedString = .Empty, 375 | type: ?type_union, 376 | 377 | pub const _type_case = enum { 378 | sprite, 379 | animation, 380 | }; 381 | pub const type_union = union(_type_case) { 382 | sprite: Sprite, 383 | animation: Animation, 384 | pub const _union_desc = .{ 385 | .sprite = fd(2, .{ .SubMessage = {} }), 386 | .animation = fd(3, .{ .SubMessage = {} }), 387 | }; 388 | }; 389 | 390 | pub const _desc_table = .{ 391 | .id = fd(1, .{ .Varint = .Simple }), 392 | .name = fd(4, .String), 393 | .type = fd(null, .{ .OneOf = type_union }), 394 | }; 395 | 396 | pub usingnamespace protobuf.MessageMixins(@This()); 397 | }; 398 | 399 | pub const Sprite = struct { 400 | texture: i32 = 0, 401 | x: i32 = 0, 402 | y: i32 = 0, 403 | w: i32 = 0, 404 | h: i32 = 0, 405 | pivot_x: i32 = 0, 406 | pivot_y: i32 = 0, 407 | 408 | pub const _desc_table = .{ 409 | .texture = fd(1, .{ .Varint = .Simple }), 410 | .x = fd(2, .{ .Varint = .Simple }), 411 | .y = fd(3, .{ .Varint = .Simple }), 412 | .w = fd(4, .{ .Varint = .Simple }), 413 | .h = fd(5, .{ .Varint = .Simple }), 414 | .pivot_x = fd(6, .{ .Varint = .Simple }), 415 | .pivot_y = fd(7, .{ .Varint = .Simple }), 416 | }; 417 | 418 | pub usingnamespace protobuf.MessageMixins(@This()); 419 | }; 420 | 421 | pub const Animation = struct { 422 | frames: ArrayList(i32), 423 | speed: f32 = 0, 424 | 425 | pub const _desc_table = .{ 426 | .frames = fd(1, .{ .PackedList = .{ .Varint = .Simple } }), 427 | .speed = fd(2, .{ .FixedInt = .I32 }), 428 | }; 429 | 430 | pub usingnamespace protobuf.MessageMixins(@This()); 431 | }; 432 | 433 | pub const Spine = struct { 434 | name: ManagedString = .Empty, 435 | json: ManagedString = .Empty, 436 | atlas: ManagedString = .Empty, 437 | 438 | pub const _desc_table = .{ 439 | .name = fd(1, .String), 440 | .json = fd(2, .String), 441 | .atlas = fd(3, .String), 442 | }; 443 | 444 | pub usingnamespace protobuf.MessageMixins(@This()); 445 | }; 446 | -------------------------------------------------------------------------------- /tests/generated/oneofselfref.pb.zig: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-zig 2 | ///! package oneofselfref 3 | const std = @import("std"); 4 | const Allocator = std.mem.Allocator; 5 | const ArrayList = std.ArrayList; 6 | 7 | const protobuf = @import("protobuf"); 8 | const ManagedString = protobuf.ManagedString; 9 | const fd = protobuf.fd; 10 | const ManagedStruct = protobuf.ManagedStruct; 11 | 12 | pub const Result = struct { 13 | version: i32 = 0, 14 | node: ?Node = null, 15 | 16 | pub const _desc_table = .{ 17 | .version = fd(1, .{ .Varint = .Simple }), 18 | .node = fd(2, .{ .SubMessage = {} }), 19 | }; 20 | 21 | pub usingnamespace protobuf.MessageMixins(@This()); 22 | }; 23 | 24 | pub const Node = struct { 25 | node: ?node_union, 26 | 27 | pub const _node_case = enum { 28 | sub_node, 29 | some_string, 30 | }; 31 | pub const node_union = union(_node_case) { 32 | sub_node: SubNode, 33 | some_string: ManagedString, 34 | pub const _union_desc = .{ 35 | .sub_node = fd(1, .{ .SubMessage = {} }), 36 | .some_string = fd(2, .String), 37 | }; 38 | }; 39 | 40 | pub const _desc_table = .{ 41 | .node = fd(null, .{ .OneOf = node_union }), 42 | }; 43 | 44 | pub usingnamespace protobuf.MessageMixins(@This()); 45 | }; 46 | 47 | pub const SubNode = struct { 48 | sub: ?Node = null, 49 | another_string: ManagedString = .Empty, 50 | 51 | pub const _desc_table = .{ 52 | .sub = fd(1, .{ .SubMessage = {} }), 53 | .another_string = fd(2, .String), 54 | }; 55 | 56 | pub usingnamespace protobuf.MessageMixins(@This()); 57 | }; 58 | -------------------------------------------------------------------------------- /tests/generated/opentelemetry/proto/common/v1.pb.zig: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-zig 2 | ///! package opentelemetry.proto.common.v1 3 | const std = @import("std"); 4 | const Allocator = std.mem.Allocator; 5 | const ArrayList = std.ArrayList; 6 | 7 | const protobuf = @import("protobuf"); 8 | const ManagedString = protobuf.ManagedString; 9 | const fd = protobuf.fd; 10 | const ManagedStruct = protobuf.ManagedStruct; 11 | 12 | pub const AnyValue = struct { 13 | value: ?value_union, 14 | 15 | pub const _value_case = enum { 16 | string_value, 17 | bool_value, 18 | int_value, 19 | double_value, 20 | array_value, 21 | kvlist_value, 22 | bytes_value, 23 | }; 24 | pub const value_union = union(_value_case) { 25 | string_value: ManagedString, 26 | bool_value: bool, 27 | int_value: i64, 28 | double_value: f64, 29 | array_value: ArrayValue, 30 | kvlist_value: KeyValueList, 31 | bytes_value: ManagedString, 32 | pub const _union_desc = .{ 33 | .string_value = fd(1, .String), 34 | .bool_value = fd(2, .{ .Varint = .Simple }), 35 | .int_value = fd(3, .{ .Varint = .Simple }), 36 | .double_value = fd(4, .{ .FixedInt = .I64 }), 37 | .array_value = fd(5, .{ .SubMessage = {} }), 38 | .kvlist_value = fd(6, .{ .SubMessage = {} }), 39 | .bytes_value = fd(7, .Bytes), 40 | }; 41 | }; 42 | 43 | pub const _desc_table = .{ 44 | .value = fd(null, .{ .OneOf = value_union }), 45 | }; 46 | 47 | pub usingnamespace protobuf.MessageMixins(@This()); 48 | }; 49 | 50 | pub const ArrayValue = struct { 51 | values: ArrayList(AnyValue), 52 | 53 | pub const _desc_table = .{ 54 | .values = fd(1, .{ .List = .{ .SubMessage = {} } }), 55 | }; 56 | 57 | pub usingnamespace protobuf.MessageMixins(@This()); 58 | }; 59 | 60 | pub const KeyValueList = struct { 61 | values: ArrayList(KeyValue), 62 | 63 | pub const _desc_table = .{ 64 | .values = fd(1, .{ .List = .{ .SubMessage = {} } }), 65 | }; 66 | 67 | pub usingnamespace protobuf.MessageMixins(@This()); 68 | }; 69 | 70 | pub const KeyValue = struct { 71 | key: ManagedString = .Empty, 72 | value: ?AnyValue = null, 73 | 74 | pub const _desc_table = .{ 75 | .key = fd(1, .String), 76 | .value = fd(2, .{ .SubMessage = {} }), 77 | }; 78 | 79 | pub usingnamespace protobuf.MessageMixins(@This()); 80 | }; 81 | 82 | pub const InstrumentationScope = struct { 83 | name: ManagedString = .Empty, 84 | version: ManagedString = .Empty, 85 | attributes: ArrayList(KeyValue), 86 | dropped_attributes_count: u32 = 0, 87 | 88 | pub const _desc_table = .{ 89 | .name = fd(1, .String), 90 | .version = fd(2, .String), 91 | .attributes = fd(3, .{ .List = .{ .SubMessage = {} } }), 92 | .dropped_attributes_count = fd(4, .{ .Varint = .Simple }), 93 | }; 94 | 95 | pub usingnamespace protobuf.MessageMixins(@This()); 96 | }; 97 | -------------------------------------------------------------------------------- /tests/generated/opentelemetry/proto/logs/v1.pb.zig: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-zig 2 | ///! package opentelemetry.proto.logs.v1 3 | const std = @import("std"); 4 | const Allocator = std.mem.Allocator; 5 | const ArrayList = std.ArrayList; 6 | 7 | const protobuf = @import("protobuf"); 8 | const ManagedString = protobuf.ManagedString; 9 | const fd = protobuf.fd; 10 | const ManagedStruct = protobuf.ManagedStruct; 11 | /// import package opentelemetry.proto.common.v1 12 | const opentelemetry_proto_common_v1 = @import("../common/v1.pb.zig"); 13 | /// import package opentelemetry.proto.resource.v1 14 | const opentelemetry_proto_resource_v1 = @import("../resource/v1.pb.zig"); 15 | 16 | pub const SeverityNumber = enum(i32) { 17 | SEVERITY_NUMBER_UNSPECIFIED = 0, 18 | SEVERITY_NUMBER_TRACE = 1, 19 | SEVERITY_NUMBER_TRACE2 = 2, 20 | SEVERITY_NUMBER_TRACE3 = 3, 21 | SEVERITY_NUMBER_TRACE4 = 4, 22 | SEVERITY_NUMBER_DEBUG = 5, 23 | SEVERITY_NUMBER_DEBUG2 = 6, 24 | SEVERITY_NUMBER_DEBUG3 = 7, 25 | SEVERITY_NUMBER_DEBUG4 = 8, 26 | SEVERITY_NUMBER_INFO = 9, 27 | SEVERITY_NUMBER_INFO2 = 10, 28 | SEVERITY_NUMBER_INFO3 = 11, 29 | SEVERITY_NUMBER_INFO4 = 12, 30 | SEVERITY_NUMBER_WARN = 13, 31 | SEVERITY_NUMBER_WARN2 = 14, 32 | SEVERITY_NUMBER_WARN3 = 15, 33 | SEVERITY_NUMBER_WARN4 = 16, 34 | SEVERITY_NUMBER_ERROR = 17, 35 | SEVERITY_NUMBER_ERROR2 = 18, 36 | SEVERITY_NUMBER_ERROR3 = 19, 37 | SEVERITY_NUMBER_ERROR4 = 20, 38 | SEVERITY_NUMBER_FATAL = 21, 39 | SEVERITY_NUMBER_FATAL2 = 22, 40 | SEVERITY_NUMBER_FATAL3 = 23, 41 | SEVERITY_NUMBER_FATAL4 = 24, 42 | _, 43 | }; 44 | 45 | pub const LogRecordFlags = enum(i32) { 46 | LOG_RECORD_FLAGS_DO_NOT_USE = 0, 47 | LOG_RECORD_FLAGS_TRACE_FLAGS_MASK = 255, 48 | _, 49 | }; 50 | 51 | pub const LogsData = struct { 52 | resource_logs: ArrayList(ResourceLogs), 53 | 54 | pub const _desc_table = .{ 55 | .resource_logs = fd(1, .{ .List = .{ .SubMessage = {} } }), 56 | }; 57 | 58 | pub usingnamespace protobuf.MessageMixins(@This()); 59 | }; 60 | 61 | pub const ResourceLogs = struct { 62 | resource: ?opentelemetry_proto_resource_v1.Resource = null, 63 | scope_logs: ArrayList(ScopeLogs), 64 | schema_url: ManagedString = .Empty, 65 | 66 | pub const _desc_table = .{ 67 | .resource = fd(1, .{ .SubMessage = {} }), 68 | .scope_logs = fd(2, .{ .List = .{ .SubMessage = {} } }), 69 | .schema_url = fd(3, .String), 70 | }; 71 | 72 | pub usingnamespace protobuf.MessageMixins(@This()); 73 | }; 74 | 75 | pub const ScopeLogs = struct { 76 | scope: ?opentelemetry_proto_common_v1.InstrumentationScope = null, 77 | log_records: ArrayList(LogRecord), 78 | schema_url: ManagedString = .Empty, 79 | 80 | pub const _desc_table = .{ 81 | .scope = fd(1, .{ .SubMessage = {} }), 82 | .log_records = fd(2, .{ .List = .{ .SubMessage = {} } }), 83 | .schema_url = fd(3, .String), 84 | }; 85 | 86 | pub usingnamespace protobuf.MessageMixins(@This()); 87 | }; 88 | 89 | pub const LogRecord = struct { 90 | time_unix_nano: u64 = 0, 91 | observed_time_unix_nano: u64 = 0, 92 | severity_number: SeverityNumber = @enumFromInt(0), 93 | severity_text: ManagedString = .Empty, 94 | body: ?opentelemetry_proto_common_v1.AnyValue = null, 95 | attributes: ArrayList(opentelemetry_proto_common_v1.KeyValue), 96 | dropped_attributes_count: u32 = 0, 97 | flags: u32 = 0, 98 | trace_id: ManagedString = .Empty, 99 | span_id: ManagedString = .Empty, 100 | 101 | pub const _desc_table = .{ 102 | .time_unix_nano = fd(1, .{ .FixedInt = .I64 }), 103 | .observed_time_unix_nano = fd(11, .{ .FixedInt = .I64 }), 104 | .severity_number = fd(2, .{ .Varint = .Simple }), 105 | .severity_text = fd(3, .String), 106 | .body = fd(5, .{ .SubMessage = {} }), 107 | .attributes = fd(6, .{ .List = .{ .SubMessage = {} } }), 108 | .dropped_attributes_count = fd(7, .{ .Varint = .Simple }), 109 | .flags = fd(8, .{ .FixedInt = .I32 }), 110 | .trace_id = fd(9, .Bytes), 111 | .span_id = fd(10, .Bytes), 112 | }; 113 | 114 | pub usingnamespace protobuf.MessageMixins(@This()); 115 | }; 116 | -------------------------------------------------------------------------------- /tests/generated/opentelemetry/proto/metrics/v1.pb.zig: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-zig 2 | ///! package opentelemetry.proto.metrics.v1 3 | const std = @import("std"); 4 | const Allocator = std.mem.Allocator; 5 | const ArrayList = std.ArrayList; 6 | 7 | const protobuf = @import("protobuf"); 8 | const ManagedString = protobuf.ManagedString; 9 | const fd = protobuf.fd; 10 | const ManagedStruct = protobuf.ManagedStruct; 11 | /// import package opentelemetry.proto.common.v1 12 | const opentelemetry_proto_common_v1 = @import("../common/v1.pb.zig"); 13 | /// import package opentelemetry.proto.resource.v1 14 | const opentelemetry_proto_resource_v1 = @import("../resource/v1.pb.zig"); 15 | 16 | pub const AggregationTemporality = enum(i32) { 17 | AGGREGATION_TEMPORALITY_UNSPECIFIED = 0, 18 | AGGREGATION_TEMPORALITY_DELTA = 1, 19 | AGGREGATION_TEMPORALITY_CUMULATIVE = 2, 20 | _, 21 | }; 22 | 23 | pub const DataPointFlags = enum(i32) { 24 | DATA_POINT_FLAGS_DO_NOT_USE = 0, 25 | DATA_POINT_FLAGS_NO_RECORDED_VALUE_MASK = 1, 26 | _, 27 | }; 28 | 29 | pub const MetricsData = struct { 30 | resource_metrics: ArrayList(ResourceMetrics), 31 | 32 | pub const _desc_table = .{ 33 | .resource_metrics = fd(1, .{ .List = .{ .SubMessage = {} } }), 34 | }; 35 | 36 | pub usingnamespace protobuf.MessageMixins(@This()); 37 | }; 38 | 39 | pub const ResourceMetrics = struct { 40 | resource: ?opentelemetry_proto_resource_v1.Resource = null, 41 | scope_metrics: ArrayList(ScopeMetrics), 42 | schema_url: ManagedString = .Empty, 43 | 44 | pub const _desc_table = .{ 45 | .resource = fd(1, .{ .SubMessage = {} }), 46 | .scope_metrics = fd(2, .{ .List = .{ .SubMessage = {} } }), 47 | .schema_url = fd(3, .String), 48 | }; 49 | 50 | pub usingnamespace protobuf.MessageMixins(@This()); 51 | }; 52 | 53 | pub const ScopeMetrics = struct { 54 | scope: ?opentelemetry_proto_common_v1.InstrumentationScope = null, 55 | metrics: ArrayList(Metric), 56 | schema_url: ManagedString = .Empty, 57 | 58 | pub const _desc_table = .{ 59 | .scope = fd(1, .{ .SubMessage = {} }), 60 | .metrics = fd(2, .{ .List = .{ .SubMessage = {} } }), 61 | .schema_url = fd(3, .String), 62 | }; 63 | 64 | pub usingnamespace protobuf.MessageMixins(@This()); 65 | }; 66 | 67 | pub const Metric = struct { 68 | name: ManagedString = .Empty, 69 | description: ManagedString = .Empty, 70 | unit: ManagedString = .Empty, 71 | metadata: ArrayList(opentelemetry_proto_common_v1.KeyValue), 72 | data: ?data_union, 73 | 74 | pub const _data_case = enum { 75 | gauge, 76 | sum, 77 | histogram, 78 | exponential_histogram, 79 | summary, 80 | }; 81 | pub const data_union = union(_data_case) { 82 | gauge: Gauge, 83 | sum: Sum, 84 | histogram: Histogram, 85 | exponential_histogram: ExponentialHistogram, 86 | summary: Summary, 87 | pub const _union_desc = .{ 88 | .gauge = fd(5, .{ .SubMessage = {} }), 89 | .sum = fd(7, .{ .SubMessage = {} }), 90 | .histogram = fd(9, .{ .SubMessage = {} }), 91 | .exponential_histogram = fd(10, .{ .SubMessage = {} }), 92 | .summary = fd(11, .{ .SubMessage = {} }), 93 | }; 94 | }; 95 | 96 | pub const _desc_table = .{ 97 | .name = fd(1, .String), 98 | .description = fd(2, .String), 99 | .unit = fd(3, .String), 100 | .metadata = fd(12, .{ .List = .{ .SubMessage = {} } }), 101 | .data = fd(null, .{ .OneOf = data_union }), 102 | }; 103 | 104 | pub usingnamespace protobuf.MessageMixins(@This()); 105 | }; 106 | 107 | pub const Gauge = struct { 108 | data_points: ArrayList(NumberDataPoint), 109 | 110 | pub const _desc_table = .{ 111 | .data_points = fd(1, .{ .List = .{ .SubMessage = {} } }), 112 | }; 113 | 114 | pub usingnamespace protobuf.MessageMixins(@This()); 115 | }; 116 | 117 | pub const Sum = struct { 118 | data_points: ArrayList(NumberDataPoint), 119 | aggregation_temporality: AggregationTemporality = @enumFromInt(0), 120 | is_monotonic: bool = false, 121 | 122 | pub const _desc_table = .{ 123 | .data_points = fd(1, .{ .List = .{ .SubMessage = {} } }), 124 | .aggregation_temporality = fd(2, .{ .Varint = .Simple }), 125 | .is_monotonic = fd(3, .{ .Varint = .Simple }), 126 | }; 127 | 128 | pub usingnamespace protobuf.MessageMixins(@This()); 129 | }; 130 | 131 | pub const Histogram = struct { 132 | data_points: ArrayList(HistogramDataPoint), 133 | aggregation_temporality: AggregationTemporality = @enumFromInt(0), 134 | 135 | pub const _desc_table = .{ 136 | .data_points = fd(1, .{ .List = .{ .SubMessage = {} } }), 137 | .aggregation_temporality = fd(2, .{ .Varint = .Simple }), 138 | }; 139 | 140 | pub usingnamespace protobuf.MessageMixins(@This()); 141 | }; 142 | 143 | pub const ExponentialHistogram = struct { 144 | data_points: ArrayList(ExponentialHistogramDataPoint), 145 | aggregation_temporality: AggregationTemporality = @enumFromInt(0), 146 | 147 | pub const _desc_table = .{ 148 | .data_points = fd(1, .{ .List = .{ .SubMessage = {} } }), 149 | .aggregation_temporality = fd(2, .{ .Varint = .Simple }), 150 | }; 151 | 152 | pub usingnamespace protobuf.MessageMixins(@This()); 153 | }; 154 | 155 | pub const Summary = struct { 156 | data_points: ArrayList(SummaryDataPoint), 157 | 158 | pub const _desc_table = .{ 159 | .data_points = fd(1, .{ .List = .{ .SubMessage = {} } }), 160 | }; 161 | 162 | pub usingnamespace protobuf.MessageMixins(@This()); 163 | }; 164 | 165 | pub const NumberDataPoint = struct { 166 | attributes: ArrayList(opentelemetry_proto_common_v1.KeyValue), 167 | start_time_unix_nano: u64 = 0, 168 | time_unix_nano: u64 = 0, 169 | exemplars: ArrayList(Exemplar), 170 | flags: u32 = 0, 171 | value: ?value_union, 172 | 173 | pub const _value_case = enum { 174 | as_double, 175 | as_int, 176 | }; 177 | pub const value_union = union(_value_case) { 178 | as_double: f64, 179 | as_int: i64, 180 | pub const _union_desc = .{ 181 | .as_double = fd(4, .{ .FixedInt = .I64 }), 182 | .as_int = fd(6, .{ .FixedInt = .I64 }), 183 | }; 184 | }; 185 | 186 | pub const _desc_table = .{ 187 | .attributes = fd(7, .{ .List = .{ .SubMessage = {} } }), 188 | .start_time_unix_nano = fd(2, .{ .FixedInt = .I64 }), 189 | .time_unix_nano = fd(3, .{ .FixedInt = .I64 }), 190 | .exemplars = fd(5, .{ .List = .{ .SubMessage = {} } }), 191 | .flags = fd(8, .{ .Varint = .Simple }), 192 | .value = fd(null, .{ .OneOf = value_union }), 193 | }; 194 | 195 | pub usingnamespace protobuf.MessageMixins(@This()); 196 | }; 197 | 198 | pub const HistogramDataPoint = struct { 199 | attributes: ArrayList(opentelemetry_proto_common_v1.KeyValue), 200 | start_time_unix_nano: u64 = 0, 201 | time_unix_nano: u64 = 0, 202 | count: u64 = 0, 203 | sum: ?f64 = null, 204 | bucket_counts: ArrayList(u64), 205 | explicit_bounds: ArrayList(f64), 206 | exemplars: ArrayList(Exemplar), 207 | flags: u32 = 0, 208 | min: ?f64 = null, 209 | max: ?f64 = null, 210 | 211 | pub const _desc_table = .{ 212 | .attributes = fd(9, .{ .List = .{ .SubMessage = {} } }), 213 | .start_time_unix_nano = fd(2, .{ .FixedInt = .I64 }), 214 | .time_unix_nano = fd(3, .{ .FixedInt = .I64 }), 215 | .count = fd(4, .{ .FixedInt = .I64 }), 216 | .sum = fd(5, .{ .FixedInt = .I64 }), 217 | .bucket_counts = fd(6, .{ .PackedList = .{ .FixedInt = .I64 } }), 218 | .explicit_bounds = fd(7, .{ .PackedList = .{ .FixedInt = .I64 } }), 219 | .exemplars = fd(8, .{ .List = .{ .SubMessage = {} } }), 220 | .flags = fd(10, .{ .Varint = .Simple }), 221 | .min = fd(11, .{ .FixedInt = .I64 }), 222 | .max = fd(12, .{ .FixedInt = .I64 }), 223 | }; 224 | 225 | pub usingnamespace protobuf.MessageMixins(@This()); 226 | }; 227 | 228 | pub const ExponentialHistogramDataPoint = struct { 229 | attributes: ArrayList(opentelemetry_proto_common_v1.KeyValue), 230 | start_time_unix_nano: u64 = 0, 231 | time_unix_nano: u64 = 0, 232 | count: u64 = 0, 233 | sum: ?f64 = null, 234 | scale: i32 = 0, 235 | zero_count: u64 = 0, 236 | positive: ?Buckets = null, 237 | negative: ?Buckets = null, 238 | flags: u32 = 0, 239 | exemplars: ArrayList(Exemplar), 240 | min: ?f64 = null, 241 | max: ?f64 = null, 242 | zero_threshold: f64 = 0, 243 | 244 | pub const _desc_table = .{ 245 | .attributes = fd(1, .{ .List = .{ .SubMessage = {} } }), 246 | .start_time_unix_nano = fd(2, .{ .FixedInt = .I64 }), 247 | .time_unix_nano = fd(3, .{ .FixedInt = .I64 }), 248 | .count = fd(4, .{ .FixedInt = .I64 }), 249 | .sum = fd(5, .{ .FixedInt = .I64 }), 250 | .scale = fd(6, .{ .Varint = .ZigZagOptimized }), 251 | .zero_count = fd(7, .{ .FixedInt = .I64 }), 252 | .positive = fd(8, .{ .SubMessage = {} }), 253 | .negative = fd(9, .{ .SubMessage = {} }), 254 | .flags = fd(10, .{ .Varint = .Simple }), 255 | .exemplars = fd(11, .{ .List = .{ .SubMessage = {} } }), 256 | .min = fd(12, .{ .FixedInt = .I64 }), 257 | .max = fd(13, .{ .FixedInt = .I64 }), 258 | .zero_threshold = fd(14, .{ .FixedInt = .I64 }), 259 | }; 260 | 261 | pub const Buckets = struct { 262 | offset: i32 = 0, 263 | bucket_counts: ArrayList(u64), 264 | 265 | pub const _desc_table = .{ 266 | .offset = fd(1, .{ .Varint = .ZigZagOptimized }), 267 | .bucket_counts = fd(2, .{ .PackedList = .{ .Varint = .Simple } }), 268 | }; 269 | 270 | pub usingnamespace protobuf.MessageMixins(@This()); 271 | }; 272 | 273 | pub usingnamespace protobuf.MessageMixins(@This()); 274 | }; 275 | 276 | pub const SummaryDataPoint = struct { 277 | attributes: ArrayList(opentelemetry_proto_common_v1.KeyValue), 278 | start_time_unix_nano: u64 = 0, 279 | time_unix_nano: u64 = 0, 280 | count: u64 = 0, 281 | sum: f64 = 0, 282 | quantile_values: ArrayList(ValueAtQuantile), 283 | flags: u32 = 0, 284 | 285 | pub const _desc_table = .{ 286 | .attributes = fd(7, .{ .List = .{ .SubMessage = {} } }), 287 | .start_time_unix_nano = fd(2, .{ .FixedInt = .I64 }), 288 | .time_unix_nano = fd(3, .{ .FixedInt = .I64 }), 289 | .count = fd(4, .{ .FixedInt = .I64 }), 290 | .sum = fd(5, .{ .FixedInt = .I64 }), 291 | .quantile_values = fd(6, .{ .List = .{ .SubMessage = {} } }), 292 | .flags = fd(8, .{ .Varint = .Simple }), 293 | }; 294 | 295 | pub const ValueAtQuantile = struct { 296 | quantile: f64 = 0, 297 | value: f64 = 0, 298 | 299 | pub const _desc_table = .{ 300 | .quantile = fd(1, .{ .FixedInt = .I64 }), 301 | .value = fd(2, .{ .FixedInt = .I64 }), 302 | }; 303 | 304 | pub usingnamespace protobuf.MessageMixins(@This()); 305 | }; 306 | 307 | pub usingnamespace protobuf.MessageMixins(@This()); 308 | }; 309 | 310 | pub const Exemplar = struct { 311 | filtered_attributes: ArrayList(opentelemetry_proto_common_v1.KeyValue), 312 | time_unix_nano: u64 = 0, 313 | span_id: ManagedString = .Empty, 314 | trace_id: ManagedString = .Empty, 315 | value: ?value_union, 316 | 317 | pub const _value_case = enum { 318 | as_double, 319 | as_int, 320 | }; 321 | pub const value_union = union(_value_case) { 322 | as_double: f64, 323 | as_int: i64, 324 | pub const _union_desc = .{ 325 | .as_double = fd(3, .{ .FixedInt = .I64 }), 326 | .as_int = fd(6, .{ .FixedInt = .I64 }), 327 | }; 328 | }; 329 | 330 | pub const _desc_table = .{ 331 | .filtered_attributes = fd(7, .{ .List = .{ .SubMessage = {} } }), 332 | .time_unix_nano = fd(2, .{ .FixedInt = .I64 }), 333 | .span_id = fd(4, .Bytes), 334 | .trace_id = fd(5, .Bytes), 335 | .value = fd(null, .{ .OneOf = value_union }), 336 | }; 337 | 338 | pub usingnamespace protobuf.MessageMixins(@This()); 339 | }; 340 | -------------------------------------------------------------------------------- /tests/generated/opentelemetry/proto/resource/v1.pb.zig: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-zig 2 | ///! package opentelemetry.proto.resource.v1 3 | const std = @import("std"); 4 | const Allocator = std.mem.Allocator; 5 | const ArrayList = std.ArrayList; 6 | 7 | const protobuf = @import("protobuf"); 8 | const ManagedString = protobuf.ManagedString; 9 | const fd = protobuf.fd; 10 | const ManagedStruct = protobuf.ManagedStruct; 11 | /// import package opentelemetry.proto.common.v1 12 | const opentelemetry_proto_common_v1 = @import("../common/v1.pb.zig"); 13 | 14 | pub const Resource = struct { 15 | attributes: ArrayList(opentelemetry_proto_common_v1.KeyValue), 16 | dropped_attributes_count: u32 = 0, 17 | 18 | pub const _desc_table = .{ 19 | .attributes = fd(1, .{ .List = .{ .SubMessage = {} } }), 20 | .dropped_attributes_count = fd(2, .{ .Varint = .Simple }), 21 | }; 22 | 23 | pub usingnamespace protobuf.MessageMixins(@This()); 24 | }; 25 | -------------------------------------------------------------------------------- /tests/generated/selfref.pb.zig: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-zig 2 | ///! package selfref 3 | const std = @import("std"); 4 | const Allocator = std.mem.Allocator; 5 | const ArrayList = std.ArrayList; 6 | 7 | const protobuf = @import("protobuf"); 8 | const ManagedString = protobuf.ManagedString; 9 | const fd = protobuf.fd; 10 | const ManagedStruct = protobuf.ManagedStruct; 11 | 12 | pub const SelfRefNode = struct { 13 | version: i32 = 0, 14 | node: ?ManagedStruct(SelfRefNode) = null, 15 | 16 | pub const _desc_table = .{ 17 | .version = fd(1, .{ .Varint = .Simple }), 18 | .node = fd(2, .{ .SubMessage = {} }), 19 | }; 20 | 21 | pub usingnamespace protobuf.MessageMixins(@This()); 22 | }; 23 | -------------------------------------------------------------------------------- /tests/generated/some/really/long/name/which/does/not/really/make/any/sense/but/sometimes/we/still/see/stuff/like/this.pb.zig: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-zig 2 | ///! package some.really.long.name.which.does.not.really.make.any.sense.but.sometimes.we.still.see.stuff.like.this 3 | const std = @import("std"); 4 | const Allocator = std.mem.Allocator; 5 | const ArrayList = std.ArrayList; 6 | 7 | const protobuf = @import("protobuf"); 8 | const ManagedString = protobuf.ManagedString; 9 | const fd = protobuf.fd; 10 | const ManagedStruct = protobuf.ManagedStruct; 11 | 12 | pub const WouldYouParseThisForMePlease = struct { 13 | field: ?Test = null, 14 | 15 | pub const _desc_table = .{ 16 | .field = fd(1, .{ .SubMessage = {} }), 17 | }; 18 | 19 | pub usingnamespace protobuf.MessageMixins(@This()); 20 | }; 21 | 22 | pub const Test = struct { 23 | field: ManagedString = .Empty, 24 | 25 | pub const _desc_table = .{ 26 | .field = fd(1, .String), 27 | }; 28 | 29 | pub usingnamespace protobuf.MessageMixins(@This()); 30 | }; 31 | -------------------------------------------------------------------------------- /tests/generated/tests.pb.zig: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-zig 2 | ///! package tests 3 | const std = @import("std"); 4 | const Allocator = std.mem.Allocator; 5 | const ArrayList = std.ArrayList; 6 | 7 | const protobuf = @import("protobuf"); 8 | const ManagedString = protobuf.ManagedString; 9 | const fd = protobuf.fd; 10 | const ManagedStruct = protobuf.ManagedStruct; 11 | /// import package tests.oneof 12 | const tests_oneof = @import("tests/oneof.pb.zig"); 13 | /// import package graphics 14 | const graphics = @import("graphics.pb.zig"); 15 | /// import package tests.longs 16 | const tests_longs = @import("tests/longs.pb.zig"); 17 | /// import package opentelemetry.proto.metrics.v1 18 | const opentelemetry_proto_metrics_v1 = @import("opentelemetry/proto/metrics/v1.pb.zig"); 19 | /// import package opentelemetry.proto.logs.v1 20 | const opentelemetry_proto_logs_v1 = @import("opentelemetry/proto/logs/v1.pb.zig"); 21 | /// import package protobuf_test_messages.proto3 22 | pub const protobuf_test_messages_proto3 = @import("protobuf_test_messages/proto3.pb.zig"); 23 | /// import package unittest 24 | pub const unittest = @import("unittest.pb.zig"); 25 | /// import package selfref 26 | const selfref = @import("selfref.pb.zig"); 27 | /// import package oneofselfref 28 | const oneofselfref = @import("oneofselfref.pb.zig"); 29 | /// import package jspb.test 30 | pub const jspb_test = @import("jspb/test.pb.zig"); 31 | /// import package vector_tile 32 | pub const vector_tile = @import("vector_tile.pb.zig"); 33 | 34 | pub const FixedSizes = struct { 35 | sfixed64: i64 = 0, 36 | sfixed32: i32 = 0, 37 | fixed32: u32 = 0, 38 | fixed64: u64 = 0, 39 | double: f64 = 0, 40 | float: f32 = 0, 41 | 42 | pub const _desc_table = .{ 43 | .sfixed64 = fd(1, .{ .FixedInt = .I64 }), 44 | .sfixed32 = fd(2, .{ .FixedInt = .I32 }), 45 | .fixed32 = fd(3, .{ .FixedInt = .I32 }), 46 | .fixed64 = fd(4, .{ .FixedInt = .I64 }), 47 | .double = fd(5, .{ .FixedInt = .I64 }), 48 | .float = fd(6, .{ .FixedInt = .I32 }), 49 | }; 50 | 51 | pub usingnamespace protobuf.MessageMixins(@This()); 52 | }; 53 | 54 | pub const TopLevelEnum = enum(i32) { 55 | SE_ZERO = 0, 56 | SE2_ZERO = 3, 57 | SE2_ONE = 4, 58 | _, 59 | }; 60 | 61 | pub const WithEnum = struct { 62 | value: SomeEnum = @enumFromInt(0), 63 | 64 | pub const _desc_table = .{ 65 | .value = fd(1, .{ .Varint = .Simple }), 66 | }; 67 | 68 | pub const SomeEnum = enum(i32) { 69 | SE_ZERO = 0, 70 | SE_ONE = 1, 71 | A = 3, 72 | B = 4, 73 | _, 74 | }; 75 | 76 | pub usingnamespace protobuf.MessageMixins(@This()); 77 | }; 78 | 79 | pub const WithEnumShadow = struct { 80 | value: SomeEnum = @enumFromInt(0), 81 | 82 | pub const _desc_table = .{ 83 | .value = fd(1, .{ .Varint = .Simple }), 84 | }; 85 | 86 | pub const SomeEnum = enum(i32) { 87 | SE_ZERO = 0, 88 | SE2_ZERO = 3, 89 | SE2_ONE = 4, 90 | _, 91 | }; 92 | 93 | pub usingnamespace protobuf.MessageMixins(@This()); 94 | }; 95 | 96 | pub const RepeatedEnum = struct { 97 | value: ArrayList(TopLevelEnum), 98 | 99 | pub const _desc_table = .{ 100 | .value = fd(1, .{ .List = .{ .Varint = .Simple } }), 101 | }; 102 | 103 | pub usingnamespace protobuf.MessageMixins(@This()); 104 | }; 105 | 106 | pub const Packed = struct { 107 | int32_list: ArrayList(i32), 108 | uint32_list: ArrayList(u32), 109 | sint32_list: ArrayList(i32), 110 | float_list: ArrayList(f32), 111 | double_list: ArrayList(f64), 112 | int64_list: ArrayList(i64), 113 | sint64_list: ArrayList(i64), 114 | uint64_list: ArrayList(u64), 115 | bool_list: ArrayList(bool), 116 | enum_list: ArrayList(TopLevelEnum), 117 | 118 | pub const _desc_table = .{ 119 | .int32_list = fd(1, .{ .PackedList = .{ .Varint = .Simple } }), 120 | .uint32_list = fd(2, .{ .PackedList = .{ .Varint = .Simple } }), 121 | .sint32_list = fd(3, .{ .PackedList = .{ .Varint = .ZigZagOptimized } }), 122 | .float_list = fd(4, .{ .PackedList = .{ .FixedInt = .I32 } }), 123 | .double_list = fd(5, .{ .PackedList = .{ .FixedInt = .I64 } }), 124 | .int64_list = fd(6, .{ .PackedList = .{ .Varint = .Simple } }), 125 | .sint64_list = fd(7, .{ .PackedList = .{ .Varint = .ZigZagOptimized } }), 126 | .uint64_list = fd(8, .{ .PackedList = .{ .Varint = .Simple } }), 127 | .bool_list = fd(9, .{ .PackedList = .{ .Varint = .Simple } }), 128 | .enum_list = fd(10, .{ .PackedList = .{ .Varint = .Simple } }), 129 | }; 130 | 131 | pub usingnamespace protobuf.MessageMixins(@This()); 132 | }; 133 | 134 | pub const UnPacked = struct { 135 | int32_list: ArrayList(i32), 136 | uint32_list: ArrayList(u32), 137 | sint32_list: ArrayList(i32), 138 | float_list: ArrayList(f32), 139 | double_list: ArrayList(f64), 140 | int64_list: ArrayList(i64), 141 | sint64_list: ArrayList(i64), 142 | uint64_list: ArrayList(u64), 143 | bool_list: ArrayList(bool), 144 | enum_list: ArrayList(TopLevelEnum), 145 | 146 | pub const _desc_table = .{ 147 | .int32_list = fd(1, .{ .List = .{ .Varint = .Simple } }), 148 | .uint32_list = fd(2, .{ .List = .{ .Varint = .Simple } }), 149 | .sint32_list = fd(3, .{ .List = .{ .Varint = .ZigZagOptimized } }), 150 | .float_list = fd(4, .{ .List = .{ .FixedInt = .I32 } }), 151 | .double_list = fd(5, .{ .List = .{ .FixedInt = .I64 } }), 152 | .int64_list = fd(6, .{ .List = .{ .Varint = .Simple } }), 153 | .sint64_list = fd(7, .{ .List = .{ .Varint = .ZigZagOptimized } }), 154 | .uint64_list = fd(8, .{ .List = .{ .Varint = .Simple } }), 155 | .bool_list = fd(9, .{ .List = .{ .Varint = .Simple } }), 156 | .enum_list = fd(10, .{ .List = .{ .Varint = .Simple } }), 157 | }; 158 | 159 | pub usingnamespace protobuf.MessageMixins(@This()); 160 | }; 161 | 162 | pub const WithSubmessages = struct { 163 | with_enum: ?WithEnum = null, 164 | 165 | pub const _desc_table = .{ 166 | .with_enum = fd(1, .{ .SubMessage = {} }), 167 | }; 168 | 169 | pub usingnamespace protobuf.MessageMixins(@This()); 170 | }; 171 | 172 | pub const WithStrings = struct { 173 | name: ManagedString = .Empty, 174 | 175 | pub const _desc_table = .{ 176 | .name = fd(1, .String), 177 | }; 178 | 179 | pub usingnamespace protobuf.MessageMixins(@This()); 180 | }; 181 | 182 | pub const WithRepeatedStrings = struct { 183 | name: ArrayList(ManagedString), 184 | 185 | pub const _desc_table = .{ 186 | .name = fd(1, .{ .List = .String }), 187 | }; 188 | 189 | pub usingnamespace protobuf.MessageMixins(@This()); 190 | }; 191 | 192 | pub const WithBytes = struct { 193 | byte_field: ManagedString = .Empty, 194 | 195 | pub const _desc_table = .{ 196 | .byte_field = fd(1, .Bytes), 197 | }; 198 | 199 | pub usingnamespace protobuf.MessageMixins(@This()); 200 | }; 201 | 202 | pub const WithRepeatedBytes = struct { 203 | byte_field: ArrayList(ManagedString), 204 | 205 | pub const _desc_table = .{ 206 | .byte_field = fd(1, .{ .List = .Bytes }), 207 | }; 208 | 209 | pub usingnamespace protobuf.MessageMixins(@This()); 210 | }; 211 | -------------------------------------------------------------------------------- /tests/generated/tests/longs.pb.zig: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-zig 2 | ///! package tests.longs 3 | const std = @import("std"); 4 | const Allocator = std.mem.Allocator; 5 | const ArrayList = std.ArrayList; 6 | 7 | const protobuf = @import("protobuf"); 8 | const ManagedString = protobuf.ManagedString; 9 | const fd = protobuf.fd; 10 | const ManagedStruct = protobuf.ManagedStruct; 11 | 12 | pub const LongsMessage = struct { 13 | fixed64_field_min: u64 = 0, 14 | fixed64_field_max: u64 = 0, 15 | int64_field_min: i64 = 0, 16 | int64_field_max: i64 = 0, 17 | sfixed64_field_min: i64 = 0, 18 | sfixed64_field_max: i64 = 0, 19 | sint64_field_min: i64 = 0, 20 | sint64_field_max: i64 = 0, 21 | uint64_field_min: u64 = 0, 22 | uint64_field_max: u64 = 0, 23 | 24 | pub const _desc_table = .{ 25 | .fixed64_field_min = fd(1, .{ .FixedInt = .I64 }), 26 | .fixed64_field_max = fd(2, .{ .FixedInt = .I64 }), 27 | .int64_field_min = fd(3, .{ .Varint = .Simple }), 28 | .int64_field_max = fd(4, .{ .Varint = .Simple }), 29 | .sfixed64_field_min = fd(5, .{ .FixedInt = .I64 }), 30 | .sfixed64_field_max = fd(6, .{ .FixedInt = .I64 }), 31 | .sint64_field_min = fd(7, .{ .Varint = .ZigZagOptimized }), 32 | .sint64_field_max = fd(8, .{ .Varint = .ZigZagOptimized }), 33 | .uint64_field_min = fd(9, .{ .Varint = .Simple }), 34 | .uint64_field_max = fd(10, .{ .Varint = .Simple }), 35 | }; 36 | 37 | pub usingnamespace protobuf.MessageMixins(@This()); 38 | }; 39 | -------------------------------------------------------------------------------- /tests/generated/tests/oneof.pb.zig: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-zig 2 | ///! package tests.oneof 3 | const std = @import("std"); 4 | const Allocator = std.mem.Allocator; 5 | const ArrayList = std.ArrayList; 6 | 7 | const protobuf = @import("protobuf"); 8 | const ManagedString = protobuf.ManagedString; 9 | const fd = protobuf.fd; 10 | const ManagedStruct = protobuf.ManagedStruct; 11 | 12 | pub const Enum = enum(i32) { 13 | UNSPECIFIED = 0, 14 | SOMETHING = 1, 15 | SOMETHING2 = 2, 16 | _, 17 | }; 18 | 19 | pub const Message = struct { 20 | value: i32 = 0, 21 | str: ManagedString = .Empty, 22 | 23 | pub const _desc_table = .{ 24 | .value = fd(1, .{ .Varint = .Simple }), 25 | .str = fd(2, .String), 26 | }; 27 | 28 | pub usingnamespace protobuf.MessageMixins(@This()); 29 | }; 30 | 31 | pub const OneofContainer = struct { 32 | regular_field: ManagedString = .Empty, 33 | enum_field: Enum = @enumFromInt(0), 34 | some_oneof: ?some_oneof_union, 35 | 36 | pub const _some_oneof_case = enum { 37 | string_in_oneof, 38 | message_in_oneof, 39 | a_number, 40 | enum_value, 41 | }; 42 | pub const some_oneof_union = union(_some_oneof_case) { 43 | string_in_oneof: ManagedString, 44 | message_in_oneof: Message, 45 | a_number: i32, 46 | enum_value: Enum, 47 | pub const _union_desc = .{ 48 | .string_in_oneof = fd(1, .String), 49 | .message_in_oneof = fd(2, .{ .SubMessage = {} }), 50 | .a_number = fd(3, .{ .Varint = .Simple }), 51 | .enum_value = fd(6, .{ .Varint = .Simple }), 52 | }; 53 | }; 54 | 55 | pub const _desc_table = .{ 56 | .regular_field = fd(4, .String), 57 | .enum_field = fd(5, .{ .Varint = .Simple }), 58 | .some_oneof = fd(null, .{ .OneOf = some_oneof_union }), 59 | }; 60 | 61 | pub usingnamespace protobuf.MessageMixins(@This()); 62 | }; 63 | -------------------------------------------------------------------------------- /tests/generated/vector_tile.pb.zig: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-zig 2 | ///! package vector_tile 3 | const std = @import("std"); 4 | const Allocator = std.mem.Allocator; 5 | const ArrayList = std.ArrayList; 6 | 7 | const protobuf = @import("protobuf"); 8 | const ManagedString = protobuf.ManagedString; 9 | const fd = protobuf.fd; 10 | const ManagedStruct = protobuf.ManagedStruct; 11 | 12 | pub const Tile = struct { 13 | layers: ArrayList(Layer), 14 | 15 | pub const _desc_table = .{ 16 | .layers = fd(3, .{ .List = .{ .SubMessage = {} } }), 17 | }; 18 | 19 | pub const GeomType = enum(i32) { 20 | UNKNOWN = 0, 21 | POINT = 1, 22 | LINESTRING = 2, 23 | POLYGON = 3, 24 | _, 25 | }; 26 | 27 | pub const Value = struct { 28 | string_value: ?ManagedString = null, 29 | float_value: ?f32 = null, 30 | double_value: ?f64 = null, 31 | int_value: ?i64 = null, 32 | uint_value: ?u64 = null, 33 | sint_value: ?i64 = null, 34 | bool_value: ?bool = null, 35 | 36 | pub const _desc_table = .{ 37 | .string_value = fd(1, .String), 38 | .float_value = fd(2, .{ .FixedInt = .I32 }), 39 | .double_value = fd(3, .{ .FixedInt = .I64 }), 40 | .int_value = fd(4, .{ .Varint = .Simple }), 41 | .uint_value = fd(5, .{ .Varint = .Simple }), 42 | .sint_value = fd(6, .{ .Varint = .ZigZagOptimized }), 43 | .bool_value = fd(7, .{ .Varint = .Simple }), 44 | }; 45 | 46 | pub usingnamespace protobuf.MessageMixins(@This()); 47 | }; 48 | 49 | pub const Feature = struct { 50 | id: ?u64 = 0, 51 | tags: ArrayList(u32), 52 | type: ?Tile.GeomType = .UNKNOWN, 53 | geometry: ArrayList(u32), 54 | 55 | pub const _desc_table = .{ 56 | .id = fd(1, .{ .Varint = .Simple }), 57 | .tags = fd(2, .{ .PackedList = .{ .Varint = .Simple } }), 58 | .type = fd(3, .{ .Varint = .Simple }), 59 | .geometry = fd(4, .{ .PackedList = .{ .Varint = .Simple } }), 60 | }; 61 | 62 | pub usingnamespace protobuf.MessageMixins(@This()); 63 | }; 64 | 65 | pub const Layer = struct { 66 | version: u32 = 1, 67 | name: ManagedString, 68 | features: ArrayList(Tile.Feature), 69 | keys: ArrayList(ManagedString), 70 | values: ArrayList(Tile.Value), 71 | extent: ?u32 = 4096, 72 | 73 | pub const _desc_table = .{ 74 | .version = fd(15, .{ .Varint = .Simple }), 75 | .name = fd(1, .String), 76 | .features = fd(2, .{ .List = .{ .SubMessage = {} } }), 77 | .keys = fd(3, .{ .List = .String }), 78 | .values = fd(4, .{ .List = .{ .SubMessage = {} } }), 79 | .extent = fd(5, .{ .Varint = .Simple }), 80 | }; 81 | 82 | pub usingnamespace protobuf.MessageMixins(@This()); 83 | }; 84 | 85 | pub usingnamespace protobuf.MessageMixins(@This()); 86 | }; 87 | -------------------------------------------------------------------------------- /tests/graphics.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const testing = std.testing; 3 | 4 | const protobuf = @import("protobuf"); 5 | const graphics = @import("./generated/graphics.pb.zig"); 6 | const binary_file = @embedFile("./fixtures/graphics.bin"); 7 | 8 | test "GraphicsDB" { 9 | // first decode the binary 10 | const decoded = try graphics.GraphicsDB.decode(binary_file, testing.allocator); 11 | 12 | // then encode it 13 | const encoded = try decoded.encode(testing.allocator); 14 | defer testing.allocator.free(encoded); 15 | 16 | // dupe the decoded 17 | const decoded_dupe = try decoded.dupe(testing.allocator); 18 | defer decoded_dupe.deinit(); 19 | 20 | { 21 | // encode and assert equality 22 | const encoded_dupe = try decoded_dupe.encode(testing.allocator); 23 | defer testing.allocator.free(encoded_dupe); 24 | 25 | try testing.expectEqualDeep(encoded, encoded_dupe); 26 | } 27 | 28 | // then re-decode it 29 | const decoded2 = try graphics.GraphicsDB.decode(encoded, testing.allocator); 30 | defer decoded2.deinit(); 31 | 32 | // finally assert equal objects 33 | try testing.expectEqualDeep(decoded, decoded2); 34 | 35 | // then clean up the decoded memory of the first object. this should free all string slices 36 | decoded.deinit(); 37 | 38 | { 39 | // encode and assert equality again 40 | const encoded_dupe = try decoded_dupe.encode(testing.allocator); 41 | defer testing.allocator.free(encoded_dupe); 42 | 43 | try testing.expectEqualDeep(encoded, encoded_dupe); 44 | } 45 | 46 | // and equal encodings 47 | const encoded2 = try decoded2.encode(testing.allocator); 48 | defer testing.allocator.free(encoded2); 49 | try testing.expectEqualSlices(u8, encoded, encoded2); 50 | 51 | // var file = try std.fs.cwd().openFile("debug/graphics-out.bin", .{ .mode = .write_only }); 52 | // defer file.close(); 53 | 54 | // _ = try file.write(encoded); 55 | } 56 | -------------------------------------------------------------------------------- /tests/integration.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const testing = std.testing; 3 | const unittest = @import("./generated/unittest.pb.zig"); 4 | 5 | test { 6 | _ = @import("./oneof.zig"); 7 | _ = @import("./mapbox.zig"); 8 | _ = @import("./graphics.zig"); 9 | _ = @import("./leaks.zig"); 10 | _ = @import("./optionals.zig"); 11 | } 12 | -------------------------------------------------------------------------------- /tests/json_data/fixed_sizes/camelCase.json: -------------------------------------------------------------------------------- 1 | { 2 | "sfixed64": 1, 3 | "sfixed32": 2, 4 | "fixed32": 3, 5 | "fixed64": 4, 6 | "double": 5e0, 7 | "float": 6e0 8 | } -------------------------------------------------------------------------------- /tests/json_data/fixed_sizes/camelCase_1.json: -------------------------------------------------------------------------------- 1 | { 2 | "sfixed64": 1, 3 | "sfixed32": 2, 4 | "fixed32": 3, 5 | "fixed64": 4, 6 | "double": "5", 7 | "float": "6.0" 8 | } -------------------------------------------------------------------------------- /tests/json_data/fixed_sizes/camelCase_2.json: -------------------------------------------------------------------------------- 1 | { 2 | "sfixed64": 1, 3 | "sfixed32": 2, 4 | "fixed32": 3, 5 | "fixed64": 4, 6 | "double": "5.0e0", 7 | "float": "6.0E+00" 8 | } -------------------------------------------------------------------------------- /tests/json_data/fixed_sizes/camelCase_3.json: -------------------------------------------------------------------------------- 1 | { 2 | "sfixed64": 1, 3 | "sfixed32": 2, 4 | "fixed32": 3, 5 | "fixed64": 4, 6 | "double": "5e00", 7 | "float": "6E-00" 8 | } -------------------------------------------------------------------------------- /tests/json_data/fixed_sizes/instance.zig: -------------------------------------------------------------------------------- 1 | const FixedSizes = @import("../../generated/tests.pb.zig").FixedSizes; 2 | 3 | pub fn get() FixedSizes { 4 | return FixedSizes{ 5 | .sfixed64 = 1, 6 | .sfixed32 = 2, 7 | .fixed32 = 3, 8 | .fixed64 = 4, 9 | .double = 5.0, 10 | .float = 6.0, 11 | }; 12 | } 13 | -------------------------------------------------------------------------------- /tests/json_data/more_bytes/camelCase.json: -------------------------------------------------------------------------------- 1 | { 2 | "data": [ 3 | "dGhpcyB3aWxsIGJlIGVuY29kZWQ=", 4 | "dGhpcyB3aWxsIGFsc28gYmUgZW5jb2RlZA==", 5 | "dGhpcyBvbmUgYXMgd2VsbA==" 6 | ] 7 | } -------------------------------------------------------------------------------- /tests/json_data/more_bytes/instance.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const ArrayList = std.ArrayList; 3 | const Allocator = std.mem.Allocator; 4 | const ManagedString = @import("protobuf").ManagedString; 5 | const MoreBytes = @import("../../generated/unittest.pb.zig").MoreBytes; 6 | 7 | pub fn get(allocator: Allocator) !MoreBytes { 8 | var instance = MoreBytes.init(allocator); 9 | try instance.data.append(ManagedString.static("this will be encoded")); 10 | try instance.data.append(ManagedString.static("this will also be encoded")); 11 | try instance.data.append(ManagedString.static("this one as well")); 12 | 13 | return instance; 14 | } 15 | -------------------------------------------------------------------------------- /tests/json_data/oneof_container/message_in_oneof_camelCase.json: -------------------------------------------------------------------------------- 1 | { 2 | "regularField": "this field is always the same", 3 | "enumField": "UNSPECIFIED", 4 | "someOneof": { 5 | "messageInOneof": { 6 | "value": -17, 7 | "str": "that's a string inside message_in_oneof" 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /tests/json_data/oneof_container/message_in_oneof_instance.zig: -------------------------------------------------------------------------------- 1 | const ManagedString = @import("protobuf").ManagedString; 2 | const oneof_zig = @import("../../generated/tests/oneof.pb.zig"); 3 | const OneofContainer = oneof_zig.OneofContainer; 4 | const Message = oneof_zig.Message; 5 | 6 | pub fn get() OneofContainer { 7 | return OneofContainer{ 8 | .some_oneof = .{ 9 | .message_in_oneof = Message{ 10 | .str = ManagedString.static( 11 | "that's a string inside message_in_oneof", 12 | ), 13 | .value = -17, 14 | }, 15 | }, 16 | .regular_field = ManagedString.static( 17 | "this field is always the same", 18 | ), 19 | .enum_field = .UNSPECIFIED, 20 | }; 21 | } 22 | -------------------------------------------------------------------------------- /tests/json_data/oneof_container/message_in_oneof_mixed_case1.json: -------------------------------------------------------------------------------- 1 | { 2 | "regularField": "this field is always the same", 3 | "enum_field": "UNSPECIFIED", 4 | "someOneof": { 5 | "message_in_oneof": { 6 | "value": -17, 7 | "str": "that's a string inside message_in_oneof" 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /tests/json_data/oneof_container/message_in_oneof_mixed_case2.json: -------------------------------------------------------------------------------- 1 | { 2 | "regular_field": "this field is always the same", 3 | "enumField": "UNSPECIFIED", 4 | "some_oneof": { 5 | "messageInOneof": { 6 | "value": -17, 7 | "str": "that's a string inside message_in_oneof" 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /tests/json_data/oneof_container/message_in_oneof_snake_case.json: -------------------------------------------------------------------------------- 1 | { 2 | "regular_field": "this field is always the same", 3 | "enum_field": "UNSPECIFIED", 4 | "some_oneof": { 5 | "message_in_oneof": { 6 | "value": -17, 7 | "str": "that's a string inside message_in_oneof" 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /tests/json_data/oneof_container/string_in_oneof_camelCase.json: -------------------------------------------------------------------------------- 1 | { 2 | "regularField": "this field is always the same", 3 | "enumField": "UNSPECIFIED", 4 | "someOneof": { 5 | "stringInOneof": "testing oneof field being the string" 6 | } 7 | } -------------------------------------------------------------------------------- /tests/json_data/oneof_container/string_in_oneof_instance.zig: -------------------------------------------------------------------------------- 1 | const ManagedString = @import("protobuf").ManagedString; 2 | const oneof_zig = @import("../../generated/tests/oneof.pb.zig"); 3 | const OneofContainer = oneof_zig.OneofContainer; 4 | 5 | pub fn get() OneofContainer { 6 | return OneofContainer{ 7 | .some_oneof = .{ 8 | .string_in_oneof = ManagedString.static( 9 | "testing oneof field being the string", 10 | ), 11 | }, 12 | .regular_field = ManagedString.static( 13 | "this field is always the same", 14 | ), 15 | .enum_field = .UNSPECIFIED, 16 | }; 17 | } 18 | -------------------------------------------------------------------------------- /tests/json_data/oneof_container/string_in_oneof_mixed_case1.json: -------------------------------------------------------------------------------- 1 | { 2 | "regularField": "this field is always the same", 3 | "enum_field": "UNSPECIFIED", 4 | "someOneof": { 5 | "string_in_oneof": "testing oneof field being the string" 6 | } 7 | } -------------------------------------------------------------------------------- /tests/json_data/oneof_container/string_in_oneof_mixed_case2.json: -------------------------------------------------------------------------------- 1 | { 2 | "regular_field": "this field is always the same", 3 | "enumField": "UNSPECIFIED", 4 | "some_oneof": { 5 | "stringInOneof": "testing oneof field being the string" 6 | } 7 | } -------------------------------------------------------------------------------- /tests/json_data/oneof_container/string_in_oneof_snake_case.json: -------------------------------------------------------------------------------- 1 | { 2 | "regular_field": "this field is always the same", 3 | "enum_field": "UNSPECIFIED", 4 | "some_oneof": { 5 | "string_in_oneof": "testing oneof field being the string" 6 | } 7 | } -------------------------------------------------------------------------------- /tests/json_data/packed/camelCase.json: -------------------------------------------------------------------------------- 1 | { 2 | "int32List": [ 3 | -1, 4 | 2, 5 | 3 6 | ], 7 | "uint32List": [ 8 | 1, 9 | 2, 10 | 3 11 | ], 12 | "sint32List": [ 13 | 2, 14 | 3, 15 | 4 16 | ], 17 | "floatList": [ 18 | 1e0, 19 | -1e3, 20 | "NaN", 21 | "Infinity" 22 | ], 23 | "doubleList": [ 24 | 2.1e0, 25 | -1e3, 26 | "-Infinity" 27 | ], 28 | "int64List": [ 29 | 3, 30 | -4, 31 | 5 32 | ], 33 | "sint64List": [ 34 | -4, 35 | 5, 36 | -6 37 | ], 38 | "uint64List": [ 39 | 5, 40 | 6, 41 | 7 42 | ], 43 | "boolList": [ 44 | true, 45 | false, 46 | false 47 | ], 48 | "enumList": [ 49 | "SE_ZERO", 50 | "SE2_ONE" 51 | ] 52 | } -------------------------------------------------------------------------------- /tests/json_data/packed/camelCase_1.json: -------------------------------------------------------------------------------- 1 | { 2 | "int32List": [ 3 | "-1", 4 | "2", 5 | "+3" 6 | ], 7 | "uint32List": [], 8 | "sint32List": [], 9 | "floatList": [ 10 | "1.0E-000", 11 | "-1e+3", 12 | "NaN", 13 | "Infinity" 14 | ], 15 | "doubleList": [], 16 | "int64List": [], 17 | "sint64List": [], 18 | "uint64List": [], 19 | "boolList": [], 20 | "enumList": [] 21 | } -------------------------------------------------------------------------------- /tests/json_data/packed/instance.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const Allocator = std.mem.Allocator; 3 | const ArrayList = std.ArrayList; 4 | const Packed = @import("../../generated/tests.pb.zig").Packed; 5 | 6 | 7 | pub fn get(allocator: Allocator) !Packed { 8 | var instance = Packed.init(allocator); 9 | 10 | try instance.int32_list.append(-1); 11 | try instance.int32_list.append(2); 12 | try instance.int32_list.append(3); 13 | 14 | try instance.uint32_list.append(1); 15 | try instance.uint32_list.append(2); 16 | try instance.uint32_list.append(3); 17 | 18 | try instance.sint32_list.append(2); 19 | try instance.sint32_list.append(3); 20 | try instance.sint32_list.append(4); 21 | 22 | try instance.float_list.append(1.0); 23 | try instance.float_list.append(-1_000.0); 24 | try instance.float_list.append(std.math.nan(f32)); 25 | try instance.float_list.append(std.math.inf(f32)); 26 | 27 | try instance.double_list.append(2.1); 28 | try instance.double_list.append(-1_000.0); 29 | try instance.double_list.append(-std.math.inf(f64)); 30 | 31 | try instance.int64_list.append(3); 32 | try instance.int64_list.append(-4); 33 | try instance.int64_list.append(5); 34 | 35 | try instance.sint64_list.append(-4); 36 | try instance.sint64_list.append(5); 37 | try instance.sint64_list.append(-6); 38 | 39 | try instance.uint64_list.append(5); 40 | try instance.uint64_list.append(6); 41 | try instance.uint64_list.append(7); 42 | 43 | try instance.bool_list.append(true); 44 | try instance.bool_list.append(false); 45 | try instance.bool_list.append(false); 46 | 47 | try instance.enum_list.append(.SE_ZERO); 48 | try instance.enum_list.append(.SE2_ONE); 49 | 50 | return instance; 51 | } 52 | 53 | pub fn get2(allocator: Allocator) !Packed { 54 | var instance = Packed.init(allocator); 55 | 56 | try instance.int32_list.append(-1); 57 | try instance.int32_list.append(2); 58 | try instance.int32_list.append(3); 59 | 60 | try instance.float_list.append(1.0); 61 | try instance.float_list.append(-1_000.0); 62 | try instance.float_list.append(std.math.nan(f32)); 63 | try instance.float_list.append(std.math.inf(f32)); 64 | 65 | return instance; 66 | } 67 | -------------------------------------------------------------------------------- /tests/json_data/packed/mixed_case.json: -------------------------------------------------------------------------------- 1 | { 2 | "int32_list": [ 3 | -1, 4 | 2, 5 | 3 6 | ], 7 | "uint32List": [ 8 | 1, 9 | 2, 10 | 3 11 | ], 12 | "sint32_list": [ 13 | 2, 14 | 3, 15 | 4 16 | ], 17 | "floatList": [ 18 | 1e0, 19 | -1e3, 20 | "NaN", 21 | "Infinity" 22 | ], 23 | "double_list": [ 24 | 2.1e0, 25 | -1e3, 26 | "-Infinity" 27 | ], 28 | "int64List": [ 29 | 3, 30 | -4, 31 | 5 32 | ], 33 | "sint64_list": [ 34 | -4, 35 | 5, 36 | -6 37 | ], 38 | "uint64List": [ 39 | 5, 40 | 6, 41 | 7 42 | ], 43 | "bool_list": [ 44 | true, 45 | false, 46 | false 47 | ], 48 | "enumList": [ 49 | "SE_ZERO", 50 | "SE2_ONE" 51 | ] 52 | } -------------------------------------------------------------------------------- /tests/json_data/packed/snake_case.json: -------------------------------------------------------------------------------- 1 | { 2 | "int32_list": [ 3 | -1, 4 | 2, 5 | 3 6 | ], 7 | "uint32_list": [ 8 | 1, 9 | 2, 10 | 3 11 | ], 12 | "sint32_list": [ 13 | 2, 14 | 3, 15 | 4 16 | ], 17 | "float_list": [ 18 | 1e0, 19 | -1e3, 20 | "NaN", 21 | "Infinity" 22 | ], 23 | "double_list": [ 24 | 2.1e0, 25 | -1e3, 26 | "-Infinity" 27 | ], 28 | "int64_list": [ 29 | 3, 30 | -4, 31 | 5 32 | ], 33 | "sint64_list": [ 34 | -4, 35 | 5, 36 | -6 37 | ], 38 | "uint64_list": [ 39 | 5, 40 | 6, 41 | 7 42 | ], 43 | "bool_list": [ 44 | true, 45 | false, 46 | false 47 | ], 48 | "enum_list": [ 49 | "SE_ZERO", 50 | "SE2_ONE" 51 | ] 52 | } -------------------------------------------------------------------------------- /tests/json_data/repeated_enum/camelCase1.json: -------------------------------------------------------------------------------- 1 | { 2 | "value": [ 3 | "SE_ZERO", 4 | "SE2_ZERO" 5 | ] 6 | } -------------------------------------------------------------------------------- /tests/json_data/repeated_enum/camelCase2.json: -------------------------------------------------------------------------------- 1 | { 2 | "value": [ 3 | 0, 4 | "SE2_ZERO" 5 | ] 6 | } -------------------------------------------------------------------------------- /tests/json_data/repeated_enum/camelCase3.json: -------------------------------------------------------------------------------- 1 | { 2 | "value": [ 3 | 0, 4 | 3 5 | ] 6 | } -------------------------------------------------------------------------------- /tests/json_data/repeated_enum/instance.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const ArrayList = std.ArrayList; 3 | const Allocator = std.mem.Allocator; 4 | const tests = @import("../../generated/tests.pb.zig"); 5 | const RepeatedEnum = tests.RepeatedEnum; 6 | const TopLevelEnum = tests.TopLevelEnum; 7 | 8 | pub fn get(allocator: Allocator) !RepeatedEnum { 9 | var enum_array = ArrayList(TopLevelEnum).init(allocator); 10 | try enum_array.append(.SE_ZERO); 11 | try enum_array.append(.SE2_ZERO); 12 | 13 | return RepeatedEnum{ .value = enum_array }; 14 | } 15 | -------------------------------------------------------------------------------- /tests/json_data/test_oneof2/camelCase.json: -------------------------------------------------------------------------------- 1 | { 2 | "bazInt": 15, 3 | "bazString": "we're here to check if oneof.Bytes will be serialized correctly", 4 | "foo": { 5 | "fooBytes": "c29tZSBieXRlcyB0byBjaGVjayBpdA==" 6 | }, 7 | "bar": { 8 | "barInt": 151515 9 | } 10 | } -------------------------------------------------------------------------------- /tests/json_data/test_oneof2/instance.zig: -------------------------------------------------------------------------------- 1 | const math = @import("std").math; 2 | const ManagedString = @import("protobuf").ManagedString; 3 | const TestOneof2 = @import("../../generated/unittest.pb.zig").TestOneof2; 4 | 5 | pub fn get() TestOneof2 { 6 | return TestOneof2{ 7 | .baz_int = 15, 8 | .baz_string = ManagedString.static( 9 | "we're here to check if oneof.Bytes will be serialized correctly", 10 | ), 11 | .foo = .{ .foo_bytes = ManagedString.static("some bytes to check it") }, 12 | .bar = .{ .bar_int = 151515 }, 13 | }; 14 | } 15 | -------------------------------------------------------------------------------- /tests/json_data/test_packed_types/camelCase.json: -------------------------------------------------------------------------------- 1 | { 2 | "packedInt32": [], 3 | "packedInt64": [], 4 | "packedUint32": [], 5 | "packedUint64": [], 6 | "packedSint32": [], 7 | "packedSint64": [], 8 | "packedFixed32": [], 9 | "packedFixed64": [], 10 | "packedSfixed32": [], 11 | "packedSfixed64": [], 12 | "packedFloat": [ 13 | 1e0, 14 | "NaN", 15 | "Infinity", 16 | "-Infinity", 17 | 1e0 18 | ], 19 | "packedDouble": [ 20 | 1e0, 21 | "NaN", 22 | "Infinity", 23 | "-Infinity", 24 | 1e0 25 | ], 26 | "packedBool": [], 27 | "packedEnum": [] 28 | } -------------------------------------------------------------------------------- /tests/json_data/test_packed_types/instance.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const math = std.math; 3 | const ArrayList = std.ArrayList; 4 | const Allocator = std.mem.Allocator; 5 | const TestPackedTypes = @import("../../generated/unittest.pb.zig").TestPackedTypes; 6 | 7 | pub fn get(allocator: Allocator) !TestPackedTypes { 8 | var instance = TestPackedTypes.init(allocator); 9 | try instance.packed_float.append(1.0); 10 | try instance.packed_double.append(1.0); 11 | try instance.packed_float.append(math.nan(f32)); 12 | try instance.packed_double.append(math.nan(f64)); 13 | try instance.packed_float.append(math.inf(f32)); 14 | try instance.packed_double.append(math.inf(f64)); 15 | try instance.packed_float.append(-math.inf(f32)); 16 | try instance.packed_double.append(-math.inf(f64)); 17 | try instance.packed_float.append(1.0); 18 | try instance.packed_double.append(1.0); 19 | 20 | return instance; 21 | } 22 | -------------------------------------------------------------------------------- /tests/json_data/value/camelCase1.json: -------------------------------------------------------------------------------- 1 | { 2 | "kind": { 3 | "numberValue": "NaN" 4 | } 5 | } -------------------------------------------------------------------------------- /tests/json_data/value/camelCase2.json: -------------------------------------------------------------------------------- 1 | { 2 | "kind": { 3 | "numberValue": "-Infinity" 4 | } 5 | } -------------------------------------------------------------------------------- /tests/json_data/value/camelCase3.json: -------------------------------------------------------------------------------- 1 | { 2 | "kind": { 3 | "numberValue": "Infinity" 4 | } 5 | } -------------------------------------------------------------------------------- /tests/json_data/value/camelCase4.json: -------------------------------------------------------------------------------- 1 | { 2 | "kind": { 3 | "numberValue": 1e0 4 | } 5 | } -------------------------------------------------------------------------------- /tests/json_data/value/camelCase4_1.json: -------------------------------------------------------------------------------- 1 | { 2 | "kind": { 3 | "numberValue": "1" 4 | } 5 | } -------------------------------------------------------------------------------- /tests/json_data/value/camelCase4_2.json: -------------------------------------------------------------------------------- 1 | { 2 | "kind": { 3 | "numberValue": "1.0" 4 | } 5 | } -------------------------------------------------------------------------------- /tests/json_data/value/camelCase4_3.json: -------------------------------------------------------------------------------- 1 | { 2 | "kind": { 3 | "numberValue": "1.0e0" 4 | } 5 | } -------------------------------------------------------------------------------- /tests/json_data/value/camelCase4_4.json: -------------------------------------------------------------------------------- 1 | { 2 | "kind": { 3 | "numberValue": "1.0E+00" 4 | } 5 | } -------------------------------------------------------------------------------- /tests/json_data/value/camelCase4_5.json: -------------------------------------------------------------------------------- 1 | { 2 | "kind": { 3 | "numberValue": "1e00" 4 | } 5 | } -------------------------------------------------------------------------------- /tests/json_data/value/camelCase4_6.json: -------------------------------------------------------------------------------- 1 | { 2 | "kind": { 3 | "numberValue": "1E-00" 4 | } 5 | } -------------------------------------------------------------------------------- /tests/json_data/value/instance.zig: -------------------------------------------------------------------------------- 1 | const math = @import("std").math; 2 | const Value = @import("../../generated/google/protobuf.pb.zig").Value; 3 | 4 | pub fn get1() Value { 5 | return Value{ 6 | .kind = .{ 7 | .number_value = math.nan(f64), 8 | }, 9 | }; 10 | } 11 | 12 | pub fn get2() Value { 13 | return Value{ 14 | .kind = .{ 15 | .number_value = -math.inf(f64), 16 | }, 17 | }; 18 | } 19 | 20 | pub fn get3() Value { 21 | return Value{ 22 | .kind = .{ 23 | .number_value = math.inf(f64), 24 | }, 25 | }; 26 | } 27 | 28 | pub fn get4() Value { 29 | return Value{ 30 | .kind = .{ 31 | .number_value = 1.0, 32 | }, 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /tests/json_data/with_bytes/camelCase.json: -------------------------------------------------------------------------------- 1 | { 2 | "byteField": "yv7K/g==" 3 | } -------------------------------------------------------------------------------- /tests/json_data/with_bytes/instance.zig: -------------------------------------------------------------------------------- 1 | const ManagedString = @import("protobuf").ManagedString; 2 | const WithBytes = @import("../../generated/tests.pb.zig").WithBytes; 3 | 4 | pub fn get() WithBytes { 5 | return WithBytes{ 6 | .byte_field = ManagedString.static( 7 | // base64-encoded string is "yv7K/g==" 8 | &[_]u8{ 0xCA, 0xFE, 0xCA, 0xFE }, 9 | ), 10 | }; 11 | } 12 | -------------------------------------------------------------------------------- /tests/json_data/with_bytes/snake_case.json: -------------------------------------------------------------------------------- 1 | { 2 | "byte_field": "yv7K/g==" 3 | } -------------------------------------------------------------------------------- /tests/json_data/with_strings/camelCase.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "test_string" 3 | } -------------------------------------------------------------------------------- /tests/json_data/with_strings/instance.zig: -------------------------------------------------------------------------------- 1 | const ManagedString = @import("protobuf").ManagedString; 2 | const tests = @import("../../generated/tests.pb.zig"); 3 | const WithStrings = tests.WithStrings; 4 | 5 | pub fn get() WithStrings { 6 | return WithStrings{ .name = ManagedString.static("test_string") }; 7 | } 8 | -------------------------------------------------------------------------------- /tests/json_data/with_submessages/camelCase.json: -------------------------------------------------------------------------------- 1 | { 2 | "withEnum": { 3 | "value": "A" 4 | } 5 | } -------------------------------------------------------------------------------- /tests/json_data/with_submessages/camelCase_enum_as_integer.json: -------------------------------------------------------------------------------- 1 | { 2 | "withEnum": { 3 | "value": 3 4 | } 5 | } -------------------------------------------------------------------------------- /tests/json_data/with_submessages/instance.zig: -------------------------------------------------------------------------------- 1 | const tests = @import("../../generated/tests.pb.zig"); 2 | const WithSubmessages = tests.WithSubmessages; 3 | const WithEnum = tests.WithEnum; 4 | 5 | pub fn get() WithSubmessages { 6 | return WithSubmessages{ .with_enum = WithEnum{ .value = .A } }; 7 | } 8 | -------------------------------------------------------------------------------- /tests/json_data/with_submessages/snake_case.json: -------------------------------------------------------------------------------- 1 | { 2 | "with_enum": { 3 | "value": "A" 4 | } 5 | } -------------------------------------------------------------------------------- /tests/leaks.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const testing = std.testing; 3 | 4 | const protobuf = @import("protobuf"); 5 | const tests = @import("./generated/tests.pb.zig"); 6 | const proto3 = @import("./generated/protobuf_test_messages/proto3.pb.zig"); 7 | const longs = @import("./generated/tests/longs.pb.zig"); 8 | const unittest = @import("./generated/unittest.pb.zig"); 9 | const longName = @import("./generated/some/really/long/name/which/does/not/really/make/any/sense/but/sometimes/we/still/see/stuff/like/this.pb.zig"); 10 | 11 | test "leak in allocated string" { 12 | var demo = longName.WouldYouParseThisForMePlease.init(testing.allocator); 13 | defer demo.deinit(); 14 | 15 | // allocate a "dynamic" string 16 | const allocated = try testing.allocator.dupe(u8, "asd"); 17 | // copy the allocated string 18 | demo.field = .{ .field = try protobuf.ManagedString.copy(allocated, testing.allocator) }; 19 | // release the allocated string immediately 20 | testing.allocator.free(allocated); 21 | 22 | const obtained = try demo.encode(testing.allocator); 23 | defer testing.allocator.free(obtained); 24 | 25 | try testing.expectEqualSlices(u8, "asd", demo.field.?.field.getSlice()); 26 | } 27 | 28 | test "leak in list of allocated bytes" { 29 | var my_bytes = std.ArrayList(protobuf.ManagedString).init(testing.allocator); 30 | try my_bytes.append(protobuf.ManagedString { 31 | .Const = "abcdef" 32 | }); 33 | defer my_bytes.deinit(); 34 | 35 | var msg = tests.WithRepeatedBytes { 36 | .byte_field = my_bytes, 37 | }; 38 | 39 | const buffer = try msg.encode(testing.allocator); 40 | defer testing.allocator.free(buffer); 41 | 42 | const msg_copy = try tests.WithRepeatedBytes.decode(buffer, testing.allocator); 43 | msg_copy.deinit(); 44 | } 45 | -------------------------------------------------------------------------------- /tests/mapbox.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const testing = std.testing; 3 | 4 | const protobuf = @import("protobuf"); 5 | const vector_tile = @import("./generated/vector_tile.pb.zig"); 6 | const binary_file = @embedFile("./fixtures/vector_tile.bin"); 7 | 8 | test "mapbox decoding and re-encoding" { 9 | // we will decode a releaseable copy of the binary file. to ensure that string slices are not 10 | // leaked into final string values 11 | const copied_slice = try testing.allocator.dupe(u8, binary_file); 12 | 13 | // first decode the binary 14 | const decoded = try vector_tile.Tile.decode(copied_slice, testing.allocator); 15 | defer decoded.deinit(); 16 | 17 | // then encode it 18 | const encoded = try decoded.encode(testing.allocator); 19 | defer testing.allocator.free(encoded); 20 | 21 | // at this moment, the copied slice will be deallocated, if strings were not copied, the decoded2 value 22 | // should differ 23 | testing.allocator.free(copied_slice); 24 | 25 | // then re-decode it 26 | const decoded2 = try vector_tile.Tile.decode(encoded, testing.allocator); 27 | defer decoded2.deinit(); 28 | 29 | // finally assert 30 | try testing.expectEqualDeep(decoded, decoded2); 31 | 32 | const encoded2 = try decoded2.encode(testing.allocator); 33 | defer testing.allocator.free(encoded2); 34 | try testing.expectEqualSlices(u8, encoded, encoded2); 35 | } 36 | -------------------------------------------------------------------------------- /tests/oneof.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const protobuf = @import("protobuf"); 3 | const mem = std.mem; 4 | const Allocator = mem.Allocator; 5 | const testing = std.testing; 6 | const tests_oneof = @import("./generated/tests/oneof.pb.zig"); 7 | 8 | test "decode empty oneof must be null" { 9 | const decoded = try tests_oneof.OneofContainer.decode("", testing.allocator); 10 | defer decoded.deinit(); 11 | 12 | try testing.expect(decoded.regular_field.isEmpty()); 13 | try testing.expectEqual(decoded.enum_field, .UNSPECIFIED); 14 | try testing.expectEqual(decoded.some_oneof, null); 15 | } 16 | 17 | test "oneof encode/decode int" { 18 | var demo = tests_oneof.OneofContainer.init(testing.allocator); 19 | defer demo.deinit(); 20 | 21 | demo.some_oneof = .{ .a_number = 10 }; 22 | 23 | { 24 | // duplicate the one-of and deep compare 25 | const dupe = try demo.dupe(testing.allocator); 26 | defer dupe.deinit(); 27 | try testing.expectEqualDeep(demo, dupe); 28 | } 29 | 30 | const obtained = try demo.encode(testing.allocator); 31 | defer testing.allocator.free(obtained); 32 | 33 | try testing.expectEqualSlices(u8, &[_]u8{ 34 | 0x18, 10, 35 | }, obtained); 36 | 37 | const decoded = try tests_oneof.OneofContainer.decode(obtained, testing.allocator); 38 | defer decoded.deinit(); 39 | 40 | try testing.expectEqual(demo.some_oneof.?.a_number, decoded.some_oneof.?.a_number); 41 | } 42 | 43 | test "oneof encode/decode enum" { 44 | var demo = tests_oneof.OneofContainer.init(testing.allocator); 45 | defer demo.deinit(); 46 | 47 | demo.some_oneof = .{ .enum_value = .SOMETHING2 }; 48 | 49 | const obtained = try demo.encode(testing.allocator); 50 | defer testing.allocator.free(obtained); 51 | 52 | { 53 | // duplicate the one-of and deep compare 54 | const dupe = try demo.dupe(testing.allocator); 55 | defer dupe.deinit(); 56 | try testing.expectEqualDeep(demo, dupe); 57 | } 58 | 59 | try testing.expectEqualSlices(u8, &[_]u8{ 60 | 0x30, 0x02, 61 | }, obtained); 62 | 63 | const decoded = try tests_oneof.OneofContainer.decode(obtained, testing.allocator); 64 | defer decoded.deinit(); 65 | 66 | try testing.expectEqual(demo.some_oneof.?.enum_value, decoded.some_oneof.?.enum_value); 67 | } 68 | 69 | test "oneof encode/decode string" { 70 | var demo = tests_oneof.OneofContainer.init(testing.allocator); 71 | defer demo.deinit(); 72 | 73 | demo.some_oneof = .{ .string_in_oneof = protobuf.ManagedString.static("123") }; 74 | 75 | { 76 | // duplicate the one-of and deep compare 77 | const dupe = try demo.dupe(testing.allocator); 78 | defer dupe.deinit(); 79 | try testing.expectEqualDeep(demo, dupe); 80 | } 81 | 82 | const obtained = try demo.encode(testing.allocator); 83 | defer testing.allocator.free(obtained); 84 | 85 | try testing.expectEqualSlices(u8, &[_]u8{ 86 | 0x0A, 0x03, 0x31, 0x32, 0x33, 87 | }, obtained); 88 | 89 | const decoded = try tests_oneof.OneofContainer.decode(obtained, testing.allocator); 90 | defer decoded.deinit(); 91 | 92 | try testing.expectEqualSlices(u8, demo.some_oneof.?.string_in_oneof.getSlice(), decoded.some_oneof.?.string_in_oneof.getSlice()); 93 | } 94 | 95 | test "oneof encode/decode submessage" { 96 | var demo = tests_oneof.OneofContainer.init(testing.allocator); 97 | defer demo.deinit(); 98 | 99 | demo.some_oneof = .{ .message_in_oneof = .{ .value = 1, .str = protobuf.ManagedString.static("123") } }; 100 | 101 | { 102 | // duplicate the one-of and deep compare 103 | const dupe = try demo.dupe(testing.allocator); 104 | defer dupe.deinit(); 105 | try testing.expectEqualDeep(demo, dupe); 106 | } 107 | 108 | const obtained = try demo.encode(testing.allocator); 109 | defer testing.allocator.free(obtained); 110 | 111 | try testing.expectEqualSlices(u8, &[_]u8{ 112 | 0x12, 0x07, 0x08, 0x01, 0x12, 0x03, 0x31, 0x32, 0x33, 113 | }, obtained); 114 | 115 | const decoded = try tests_oneof.OneofContainer.decode(obtained, testing.allocator); 116 | defer decoded.deinit(); 117 | 118 | try testing.expectEqualSlices(u8, demo.some_oneof.?.message_in_oneof.str.getSlice(), decoded.some_oneof.?.message_in_oneof.str.getSlice()); 119 | } 120 | 121 | test "decoding multiple messages keeps the last value 123" { 122 | const payload = &[_]u8{ 123 | // 1 some_oneof.?.enum_value 124 | 0x30, 0x02, 125 | // 2 some_oneof.?.string_in_oneof 126 | 0x0A, 0x03, 127 | 0x31, 0x32, 128 | 0x33, 129 | // 3 demo.some_oneof.?.message_in_oneof 130 | 0x12, 131 | 0x07, 0x08, 132 | 0x01, 0x12, 133 | 0x03, 0x31, 134 | 0x32, 0x33, 135 | }; 136 | 137 | const decoded = try tests_oneof.OneofContainer.decode(payload, testing.allocator); 138 | defer decoded.deinit(); 139 | 140 | try testing.expectEqualSlices(u8, "123", decoded.some_oneof.?.message_in_oneof.str.getSlice()); 141 | } 142 | 143 | test "decoding multiple messages keeps the last value 132" { 144 | // this test also ensures that if multiple values are read during decode, previous values are successfuly 145 | // freed from memory preventing leaks 146 | 147 | const payload = &[_]u8{ 148 | // 1 some_oneof.?.enum_value 149 | 0x30, 0x02, 150 | 151 | // 3 demo.some_oneof.?.message_in_oneof 152 | 0x12, 0x07, 153 | 0x08, 0x01, 154 | 0x12, 0x03, 155 | 0x31, 0x32, 156 | 0x33, 157 | 158 | // 2 some_oneof.?.string_in_oneof 159 | 0x0A, 160 | 0x03, 0x31, 161 | 0x32, 0x33, 162 | }; 163 | 164 | const decoded = try tests_oneof.OneofContainer.decode(payload, testing.allocator); 165 | defer decoded.deinit(); 166 | 167 | try testing.expectEqualSlices(u8, "123", decoded.some_oneof.?.string_in_oneof.getSlice()); 168 | } 169 | -------------------------------------------------------------------------------- /tests/optionals.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const testing = std.testing; 3 | 4 | const protobuf = @import("protobuf"); 5 | const tests = @import("./generated/tests.pb.zig"); 6 | const proto3 = @import("./generated/protobuf_test_messages/proto3.pb.zig"); 7 | const longs = @import("./generated/tests/longs.pb.zig"); 8 | const jspb = @import("./generated/jspb/test.pb.zig"); 9 | const unittest = @import("./generated/unittest.pb.zig"); 10 | const longName = @import("./generated/some/really/long/name/which/does/not/really/make/any/sense/but/sometimes/we/still/see/stuff/like/this.pb.zig"); 11 | 12 | test "empty string in optional fields must be serialized over the wire" { 13 | var t = jspb.TestClone.init(testing.allocator); 14 | defer t.deinit(); 15 | 16 | try testing.expect(t.str == null); 17 | 18 | // first encode with NULL 19 | const encodedNull = try t.encode(testing.allocator); 20 | defer testing.allocator.free(encodedNull); 21 | try testing.expectEqualSlices(u8, "", encodedNull); 22 | 23 | // decoded must be null as well 24 | const decodedNull = try jspb.TestClone.decode("", testing.allocator); 25 | defer decodedNull.deinit(); 26 | try testing.expect(decodedNull.str == null); 27 | 28 | // setting a value to "" must serialize the value 29 | t.str = .{ .Const = "" }; 30 | try testing.expect(t.str.?.isEmpty()); 31 | 32 | // then the encoded must be an empty string 33 | const encodedEmpty = try t.encode(testing.allocator); 34 | defer testing.allocator.free(encodedEmpty); 35 | try testing.expectEqualSlices(u8, &[_]u8{ 0x0A, 0x00 }, encodedEmpty); 36 | 37 | // decoded must be null as well 38 | const decodedEmpty = try jspb.TestClone.decode(encodedEmpty, testing.allocator); 39 | defer decodedEmpty.deinit(); 40 | try testing.expect(decodedEmpty.str.?.isEmpty()); 41 | } 42 | 43 | test "unittest.proto parse and re-encode" { 44 | const binary_file = 45 | "\x08\x65\x10\x66\x18\x67\x20\x68\x28\xd2\x01\x30\xd4\x01\x3d\x6b\x00\x00\x00\x41\x6c\x00" ++ 46 | "\x00\x00\x00\x00\x00\x00\x4d\x6d\x00\x00\x00\x51\x6e\x00\x00\x00\x00\x00\x00\x00\x5d\x00" ++ 47 | "\x00\xde\x42\x61\x00\x00\x00\x00\x00\x00\x5c\x40\x68\x01\x72\x03\x31\x31\x35\x7a\x03\x31" ++ 48 | "\x31\x36\x83\x01\x88\x01\x75\x84\x01"; 49 | 50 | // first decode the binary 51 | const decoded = try unittest.TestAllTypes.decode(binary_file, testing.allocator); 52 | defer decoded.deinit(); 53 | 54 | try assert(decoded); 55 | 56 | // then encode it 57 | const encoded = try decoded.encode(testing.allocator); 58 | defer testing.allocator.free(encoded); 59 | 60 | // then re-decode it 61 | const decoded2 = try unittest.TestAllTypes.decode(encoded, testing.allocator); 62 | defer decoded2.deinit(); 63 | const encoded2 = try decoded.encode(testing.allocator); 64 | defer testing.allocator.free(encoded2); 65 | 66 | try assert(decoded2); 67 | 68 | // finally assert blackbox serialization 69 | try testing.expectEqualSlices(u8, encoded, encoded2); 70 | } 71 | 72 | fn assert(decoded: unittest.TestAllTypes) !void { 73 | try testing.expectEqual(decoded.optional_int32, 101); 74 | try testing.expectEqual(decoded.optional_int64, 102); 75 | try testing.expectEqual(decoded.optional_uint32, 103); 76 | try testing.expectEqual(decoded.optional_uint64, 104); 77 | // TODO: review why this zigzag encoding is not working 78 | // TODO: try testing.expectEqual(decoded.optional_sint32, -53); 79 | // TODO: try testing.expectEqual(decoded.optional_sint64, -xxx); 80 | try testing.expectEqual(decoded.optional_fixed32, 107); 81 | try testing.expectEqual(decoded.optional_fixed64, @as(i64, 108)); 82 | try testing.expectEqual(decoded.optional_sfixed32, 109); 83 | try testing.expectEqual(decoded.optional_sfixed64, @as(i64, 110)); 84 | try testing.expectEqual(decoded.optional_float, 111.0); 85 | try testing.expectEqual(decoded.optional_double, 112.0); 86 | try testing.expectEqual(decoded.optional_bool, true); 87 | try testing.expectEqualSlices(u8, decoded.optional_string.?.getSlice(), "115"); 88 | try testing.expectEqualSlices(u8, decoded.optional_bytes.?.getSlice(), "116"); 89 | } 90 | -------------------------------------------------------------------------------- /tests/protos_for_test/all.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package tests; 3 | 4 | import public "fixedsizes.proto"; 5 | import public "mapbox.proto"; 6 | import public "jspb.proto"; 7 | import public "test_messages_proto3.proto"; 8 | import public "unittest.proto"; 9 | import public "graphics.proto"; 10 | import public "oneof.proto"; 11 | import public "msg-long.proto"; 12 | import public "opentelemetry/proto/metrics/v1/metrics.proto"; 13 | import public "opentelemetry/proto/logs/v1/logs.proto"; 14 | import public "oneofSelfRef.proto"; 15 | import public "selfref.proto"; 16 | 17 | enum TopLevelEnum { 18 | SE_ZERO = 0; 19 | SE2_ZERO = 3; 20 | SE2_ONE = 4; 21 | } 22 | 23 | 24 | message WithEnum { 25 | enum SomeEnum { 26 | SE_ZERO = 0; 27 | SE_ONE = 1; 28 | A = 3; 29 | B = 4; 30 | } 31 | SomeEnum value = 1; 32 | } 33 | 34 | // tests shadowing names 35 | message WithEnumShadow { 36 | enum SomeEnum { 37 | SE_ZERO = 0; 38 | SE2_ZERO = 3; 39 | SE2_ONE = 4; 40 | } 41 | SomeEnum value = 1; 42 | } 43 | 44 | message RepeatedEnum { 45 | // TODO: codegen doesn't get this reference which is valid 46 | // repeated WithEnum.SomeEnum value = 1; 47 | 48 | repeated TopLevelEnum value = 1; 49 | } 50 | 51 | message Packed { 52 | repeated int32 int32_list = 1 [packed=true]; 53 | repeated uint32 uint32_list = 2 [packed=true]; 54 | repeated sint32 sint32_list = 3 [packed=true]; 55 | repeated float float_list = 4 [packed=true]; 56 | repeated double double_list = 5 [packed=true]; 57 | repeated int64 int64_list = 6 [packed=true]; 58 | repeated sint64 sint64_list = 7 [packed=true]; 59 | repeated uint64 uint64_list = 8 [packed=true]; 60 | repeated bool bool_list = 9 [packed=true]; 61 | repeated TopLevelEnum enum_list = 10 [packed=true]; 62 | } 63 | 64 | message UnPacked { 65 | repeated int32 int32_list = 1 [packed=false]; 66 | repeated uint32 uint32_list = 2 [packed=false]; 67 | repeated sint32 sint32_list = 3 [packed=false]; 68 | repeated float float_list = 4 [packed=false]; 69 | repeated double double_list = 5 [packed=false]; 70 | repeated int64 int64_list = 6 [packed=false]; 71 | repeated sint64 sint64_list = 7 [packed=false]; 72 | repeated uint64 uint64_list = 8 [packed=false]; 73 | repeated bool bool_list = 9 [packed=false]; 74 | repeated TopLevelEnum enum_list = 10 [packed=false]; 75 | } 76 | 77 | message WithSubmessages { 78 | WithEnum with_enum = 1; 79 | } 80 | 81 | message WithStrings { 82 | string name = 1; 83 | } 84 | 85 | message WithRepeatedStrings { 86 | repeated string name = 1; 87 | } 88 | 89 | message WithBytes { 90 | bytes byte_field = 1; 91 | } 92 | 93 | message WithRepeatedBytes { 94 | repeated bytes byte_field = 1; 95 | } 96 | -------------------------------------------------------------------------------- /tests/protos_for_test/fixedsizes.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package tests; 3 | 4 | message FixedSizes { 5 | sfixed64 sfixed64 = 1; 6 | sfixed32 sfixed32 = 2; 7 | fixed32 fixed32 = 3; 8 | fixed64 fixed64 = 4; 9 | double double = 5; 10 | float float = 6; 11 | } -------------------------------------------------------------------------------- /tests/protos_for_test/generated_in_ci.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package generated_in_ci; 3 | 4 | message Varints { 5 | sint32 sint32 = 1; 6 | sint64 sint64 = 2; 7 | uint32 uint32 = 3; 8 | uint64 uint64 = 4; 9 | bool a_bool = 5; 10 | } 11 | 12 | message TestPacked { 13 | repeated int32 f = 6 [packed=true]; 14 | } 15 | 16 | message TestOptional { 17 | optional string d = 4; 18 | repeated int32 e = 5; 19 | } 20 | 21 | message Demo1 { 22 | uint32 a = 1; 23 | } 24 | 25 | message Demo2 { 26 | uint32 a = 1; 27 | uint32 b = 2; 28 | } 29 | 30 | message WithNegativeIntegers { 31 | sint32 a = 1; 32 | int32 b = 2; 33 | } 34 | 35 | message DemoWithAllVarint { 36 | enum DemoEnum { 37 | SomeValue = 0; 38 | SomeOther = 1; 39 | AndAnother = 2; 40 | Negative = -1; 41 | MaxNeg = -2147483648; 42 | Max = 2147483647; 43 | }; 44 | 45 | sint32 sint32 = 1; 46 | sint64 sint64 = 2; 47 | uint32 uint32 = 3; 48 | uint64 uint64 = 4; 49 | bool a_bool = 5; 50 | DemoEnum a_enum = 6; 51 | int32 pos_int32 = 7; 52 | int64 pos_int64 = 8; 53 | int32 neg_int32 = 9; 54 | int64 neg_int64 = 10; 55 | } 56 | 57 | message WithSubmessages2 { 58 | Demo1 sub_demo1 = 1; 59 | Demo2 sub_demo2 = 2; 60 | } 61 | 62 | message WithIntsNotPacked { 63 | repeated uint32 list_of_data = 1 [packed=false]; 64 | } 65 | 66 | message WithIntsPacked { 67 | repeated uint32 list_of_data = 1 [packed=true]; 68 | } 69 | 70 | message SubMessageList { 71 | repeated Demo1 subMessageList = 1; 72 | } 73 | 74 | message EmptyLists { 75 | repeated uint32 varuint32List = 1 [packed=false]; 76 | repeated uint32 varuint32Empty = 2 [packed=false]; 77 | } 78 | 79 | message EmptyMessage { 80 | } 81 | 82 | message FixedSizesList { 83 | repeated fixed32 fixed32List = 1 [packed=false]; 84 | } 85 | 86 | message VarintListNotPacked { 87 | repeated uint32 varuint32List = 1 [packed=false]; 88 | } 89 | 90 | message VarintListPacked { 91 | repeated uint32 varuint32List = 1 [packed=true]; 92 | } -------------------------------------------------------------------------------- /tests/protos_for_test/graphics.proto: -------------------------------------------------------------------------------- 1 | // This file contains all the protocol definitions to store static files and 2 | // database index for the game. These definitions can also be used over-the-wire 3 | // talking with the server i.e. a server could send an entire body definition or 4 | // texture to the client on-the-fly 5 | 6 | syntax = "proto3"; 7 | package graphics; 8 | 9 | option optimize_for = SPEED; 10 | message InventoryItem { 11 | int32 slot = 1; 12 | string name = 2; 13 | int32 image = 3; 14 | int32 quantity = 4; 15 | string description = 5; 16 | int32 id = 6; 17 | } 18 | 19 | message Character { 20 | string id = 1; 21 | int32 class = 2; 22 | int32 gender = 3; 23 | int32 race = 4; 24 | int32 head = 5; 25 | int32 body = 6; 26 | int32 helmet = 7; 27 | int32 right_hand = 8; 28 | string nick = 9; 29 | int32 left_hand = 10; 30 | string color = 11; 31 | string clan = 12; 32 | bool enabled = 13; 33 | } 34 | 35 | message Alignment { 36 | string id = 1; 37 | string name = 2; 38 | string color = 3; 39 | } 40 | 41 | message Index { 42 | int32 id = 1; 43 | repeated int32 grh = 2; 44 | int32 offset_x = 3; 45 | int32 offset_y = 4; 46 | map animations = 5; 47 | string name = 6; 48 | } 49 | 50 | message StoredChunk { 51 | int32 chunk_id = 1; 52 | repeated MapEntity entities = 2; 53 | } 54 | 55 | message MapEntity { 56 | int32 x = 1; 57 | int32 y = 2; 58 | Light light = 3; 59 | Shape collider = 4; 60 | int32 graphic_id = 5; 61 | string entity_id = 6; 62 | bool vertical_graphic = 7; 63 | } 64 | 65 | message Light { 66 | float hue = 1; 67 | float height = 2; 68 | float radius = 3; 69 | float saturation = 4; 70 | float fall_off = 5; 71 | } 72 | 73 | message Point { 74 | int32 x = 1; 75 | int32 y = 2; 76 | } 77 | 78 | message Shape { 79 | repeated Point points = 1; 80 | } 81 | 82 | message Npc { 83 | int32 x = 1; 84 | int32 y = 2; 85 | repeated InventoryItem items = 3; 86 | string name = 4; 87 | string alignment = 5; 88 | string ai = 6; 89 | 90 | int32 min_hp = 7; 91 | int32 max_hp = 8; 92 | int32 min_mana = 9; 93 | int32 max_mana = 10; 94 | int32 min_strenght = 11; 95 | int32 max_strenght = 12; 96 | 97 | map skills = 13; 98 | map abilities = 14; 99 | Character visual = 15; 100 | } 101 | 102 | message Tile { 103 | int32 x = 1; 104 | int32 y = 2; 105 | int32 tileset_grh = 3; 106 | int32 tileset = 4; 107 | int32 flags = 5; 108 | int32 blocked = 6; 109 | int32 layer2 = 7; 110 | int32 layer3 = 8; 111 | int32 layer4 = 9; 112 | } 113 | 114 | message MapItem { 115 | int32 x = 1; 116 | int32 y = 2; 117 | int32 item = 3; 118 | int32 amount = 4; 119 | } 120 | 121 | message GraphicsDB { 122 | repeated Texture textures = 1; 123 | repeated Graphic graphics = 2; 124 | // repeated Tileset tilesets = 3; 125 | repeated Index bodies = 4; 126 | repeated Index fxs = 5; 127 | repeated Index heads = 6; 128 | repeated Index helmets = 7; 129 | repeated Index shields = 8; 130 | repeated Index weapons = 9; 131 | repeated Script scripts = 10; 132 | repeated Spine spine = 11; 133 | } 134 | 135 | message Script { 136 | string path = 1; 137 | string code = 2; 138 | } 139 | 140 | 141 | message SubTexture { 142 | string diffuse = 1; 143 | string normal = 2; 144 | string emmisive = 3; 145 | int32 width = 4; 146 | int32 height = 5; 147 | } 148 | 149 | message Texture { 150 | string diffuse = 1; 151 | string normal = 2; 152 | string emmisive = 3; 153 | int32 width = 4; 154 | int32 height = 5; 155 | 156 | SubTexture dxt1 = 6; 157 | SubTexture dxt3 = 7; 158 | SubTexture dxt5 = 8; 159 | } 160 | 161 | message Graphic { 162 | int32 id = 1; 163 | oneof type { 164 | Sprite sprite = 2; 165 | Animation animation = 3; 166 | } 167 | string name = 4; 168 | } 169 | 170 | message Sprite { 171 | int32 texture = 1; 172 | int32 x = 2; 173 | int32 y = 3; 174 | int32 w = 4; 175 | int32 h = 5; 176 | int32 pivot_x = 6; 177 | int32 pivot_y = 7; 178 | } 179 | 180 | message Animation { 181 | repeated int32 frames = 1; 182 | float speed = 2; 183 | } 184 | 185 | message Spine { 186 | string name = 1; 187 | string json = 2; 188 | string atlas = 3; 189 | } -------------------------------------------------------------------------------- /tests/protos_for_test/jspb.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Author: mwr@google.com (Mark Rawling) 32 | 33 | syntax = "proto2"; 34 | 35 | option java_package = "com.google.apps.jspb.proto"; 36 | 37 | import "google/protobuf/descriptor.proto"; 38 | 39 | package jspb.test; 40 | 41 | message Empty { 42 | } 43 | 44 | enum OuterEnum { 45 | FOO = 1; 46 | BAR = 2; 47 | } 48 | 49 | message EnumContainer { 50 | optional OuterEnum outer_enum = 1; 51 | } 52 | 53 | message Simple1 { 54 | required string a_string = 1; 55 | repeated string a_repeated_string = 2; 56 | optional bool a_boolean = 3; 57 | } 58 | 59 | // A message that differs from Simple1 only by name 60 | message Simple2 { 61 | required string a_string = 1; 62 | repeated string a_repeated_string = 2; 63 | } 64 | 65 | message SpecialCases { 66 | required string normal = 1; 67 | // Examples of Js reserved names that are converted to pb_. 68 | required string default = 2; 69 | required string function = 3; 70 | required string var = 4; 71 | } 72 | 73 | message OptionalFields { 74 | message Nested { 75 | optional int32 an_int = 1; 76 | } 77 | optional string a_string = 1; 78 | required bool a_bool = 2; 79 | optional Nested a_nested_message = 3; 80 | repeated Nested a_repeated_message = 4; 81 | repeated string a_repeated_string = 5; 82 | } 83 | 84 | message HasExtensions { 85 | optional string str1 = 1; 86 | optional string str2 = 2; 87 | optional string str3 = 3; 88 | extensions 10 to max; 89 | } 90 | 91 | message Complex { 92 | message Nested { 93 | required int32 an_int = 2; 94 | } 95 | required string a_string = 1; 96 | required bool an_out_of_order_bool = 9; 97 | optional Nested a_nested_message = 4; 98 | repeated Nested a_repeated_message = 5; 99 | repeated string a_repeated_string = 7; 100 | } 101 | 102 | // message OuterMessage { 103 | // // Make sure this doesn't conflict with the other Complex message. 104 | // message Complex { 105 | // optional int32 inner_complex_field = 1; 106 | // } 107 | // } 108 | 109 | message IsExtension { 110 | extend HasExtensions { 111 | optional IsExtension ext_field = 100; 112 | } 113 | optional string ext1 = 1; 114 | 115 | // Extensions of proto2 Descriptor messages will be ignored. 116 | extend google.protobuf.EnumOptions { 117 | optional string simple_option = 42113038; 118 | } 119 | } 120 | 121 | message IndirectExtension { 122 | extend HasExtensions { 123 | optional Simple1 simple = 101; 124 | optional string str = 102; 125 | repeated string repeated_str = 103; 126 | repeated Simple1 repeated_simple = 104; 127 | } 128 | } 129 | 130 | extend HasExtensions { 131 | optional Simple1 simple1 = 105; 132 | } 133 | 134 | message DefaultValues { 135 | enum Enum { 136 | E1 = 13; 137 | E2 = 77; 138 | } 139 | optional string string_field = 1 [default="default<>\'\"abc"]; 140 | optional bool bool_field = 2 [default=true]; 141 | optional int64 int_field = 3 [default=11]; 142 | optional Enum enum_field = 4 [default=E1]; 143 | optional string empty_field = 6 [default=""]; 144 | optional bytes bytes_field = 8 [default="moo"]; // Base64 encoding is "bW9v" 145 | } 146 | 147 | message FloatingPointFields { 148 | optional float optional_float_field = 1; 149 | required float required_float_field = 2; 150 | repeated float repeated_float_field = 3; 151 | optional float default_float_field = 4 [default = 2.0]; 152 | optional double optional_double_field = 5; 153 | required double required_double_field = 6; 154 | repeated double repeated_double_field = 7; 155 | optional double default_double_field = 8 [default = 2.0]; 156 | } 157 | 158 | message TestClone { 159 | optional string str = 1; 160 | optional Simple1 simple1 = 3; 161 | repeated Simple1 simple2 = 5; 162 | optional bytes bytes_field = 6; 163 | optional string unused = 7; 164 | extensions 10 to max; 165 | } 166 | 167 | message CloneExtension { 168 | extend TestClone { 169 | optional CloneExtension ext_field = 100; 170 | } 171 | optional string ext = 2; 172 | } 173 | 174 | message TestGroup { 175 | // repeated group RepeatedGroup = 1 { 176 | // required string id = 1; 177 | // repeated bool some_bool = 2; 178 | // } 179 | // required group RequiredGroup = 2 { 180 | // required string id = 1; 181 | // } 182 | // optional group OptionalGroup = 3 { 183 | // required string id = 1; 184 | // } 185 | // optional group MessageInGroup = 4 { 186 | // message NestedMessage { 187 | // optional string id = 1; 188 | // } 189 | // required NestedMessage id = 1; 190 | // } 191 | // optional group EnumInGroup = 5 { 192 | // enum NestedEnum { 193 | // first = 0; 194 | // second = 1; 195 | // } 196 | // required NestedEnum id = 1; 197 | // } 198 | optional string id = 6; 199 | required Simple2 required_simple = 7; 200 | optional Simple2 optional_simple = 8; 201 | } 202 | 203 | // message TestGroup1 { 204 | // optional TestGroup.RepeatedGroup group = 1; 205 | // } 206 | 207 | message TestReservedNames { 208 | optional int32 extension = 1; 209 | extensions 10 to max; 210 | } 211 | 212 | message TestReservedNamesExtension { 213 | extend TestReservedNames { 214 | optional int32 foo = 10; 215 | } 216 | } 217 | 218 | message TestMessageWithOneof { 219 | 220 | oneof partial_oneof { 221 | string pone = 3; 222 | string pthree = 5; 223 | } 224 | 225 | oneof recursive_oneof { 226 | TestMessageWithOneof rone = 6; 227 | string rtwo = 7; 228 | } 229 | 230 | optional bool normal_field = 8; 231 | repeated string repeated_field = 9; 232 | 233 | oneof default_oneof_a { 234 | int32 aone = 10 [default = 1234]; 235 | int32 atwo = 11; 236 | } 237 | 238 | oneof default_oneof_b { 239 | int32 bone = 12; 240 | int32 btwo = 13 [default = 1234]; 241 | } 242 | } 243 | 244 | message TestEndsWithBytes { 245 | optional int32 value = 1; 246 | optional bytes data = 2; 247 | } 248 | 249 | message TestMapFieldsNoBinary { 250 | map map_string_string = 1; 251 | map map_string_int32 = 2; 252 | map map_string_int64 = 3; 253 | map map_string_bool = 4; 254 | map map_string_double = 5; 255 | map map_string_enum = 6; 256 | map map_string_msg = 7; 257 | 258 | map map_int32_string = 8; 259 | map map_int64_string = 9; 260 | map map_bool_string = 10; 261 | 262 | optional TestMapFieldsNoBinary test_map_fields = 11; 263 | map map_string_testmapfields = 12; 264 | } 265 | 266 | enum MapValueEnumNoBinary { 267 | MAP_VALUE_FOO_NOBINARY = 0; 268 | MAP_VALUE_BAR_NOBINARY = 1; 269 | MAP_VALUE_BAZ_NOBINARY = 2; 270 | } 271 | 272 | message MapValueMessageNoBinary { 273 | optional int32 foo = 1; 274 | } 275 | 276 | message Deeply { 277 | message Nested { 278 | message Message { 279 | optional int32 count = 1; 280 | } 281 | } 282 | } 283 | 284 | option java_multiple_files = true; -------------------------------------------------------------------------------- /tests/protos_for_test/mapbox.proto: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Mapbox 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are met: 6 | // 7 | // * Redistributions of source code must retain the above copyright notice, this 8 | // list of conditions and the following disclaimer. 9 | // 10 | // * Redistributions in binary form must reproduce the above copyright notice, 11 | // this list of conditions and the following disclaimer in the documentation 12 | // and/or other materials provided with the distribution. 13 | // 14 | // * Neither the name of pbf nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | syntax = "proto2"; 30 | 31 | package vector_tile; 32 | 33 | message Tile { 34 | 35 | enum GeomType { 36 | UNKNOWN = 0; 37 | POINT = 1; 38 | LINESTRING = 2; 39 | POLYGON = 3; 40 | } 41 | 42 | message Value { 43 | 44 | optional string string_value = 1; 45 | optional float float_value = 2; 46 | optional double double_value = 3; 47 | optional int64 int_value = 4; 48 | optional uint64 uint_value = 5; 49 | optional sint64 sint_value = 6; 50 | optional bool bool_value = 7; 51 | extensions 8 to max; 52 | } 53 | 54 | message Feature { 55 | 56 | optional uint64 id = 1 [ default = 0 ]; 57 | repeated uint32 tags = 2 [ packed = true ]; 58 | optional GeomType type = 3 [ default = UNKNOWN ]; 59 | repeated uint32 geometry = 4 [ packed = true ]; 60 | } 61 | 62 | message Layer { 63 | 64 | required uint32 version = 15 [ default = 1 ]; 65 | required string name = 1; 66 | repeated Feature features = 2; 67 | repeated string keys = 3; 68 | repeated Value values = 4; 69 | optional uint32 extent = 5 [ default = 4096 ]; 70 | extensions 16 to max; 71 | } 72 | 73 | repeated Layer layers = 3; 74 | 75 | extensions 16 to 8191; 76 | } -------------------------------------------------------------------------------- /tests/protos_for_test/msg-long.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package tests.longs; 3 | message LongsMessage { 4 | fixed64 fixed64_field_min = 1; 5 | fixed64 fixed64_field_max = 2; 6 | int64 int64_field_min = 3; 7 | int64 int64_field_max = 4; 8 | sfixed64 sfixed64_field_min = 5; 9 | sfixed64 sfixed64_field_max = 6; 10 | sint64 sint64_field_min = 7; 11 | sint64 sint64_field_max = 8; 12 | uint64 uint64_field_min = 9; 13 | uint64 uint64_field_max = 10; 14 | } -------------------------------------------------------------------------------- /tests/protos_for_test/oneof.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package tests.oneof; 3 | 4 | message Message { 5 | int32 value = 1; 6 | string str = 2; 7 | } 8 | 9 | enum Enum { 10 | UNSPECIFIED = 0; 11 | SOMETHING = 1; 12 | SOMETHING2 = 2; 13 | } 14 | 15 | message OneofContainer { 16 | oneof some_oneof { 17 | string string_in_oneof = 1; 18 | Message message_in_oneof = 2; 19 | int32 a_number = 3; 20 | Enum enum_value = 6; 21 | } 22 | string regular_field = 4; 23 | Enum enum_field = 5; 24 | } -------------------------------------------------------------------------------- /tests/protos_for_test/oneofSelfRef.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package oneofselfref; 4 | 5 | message Result { 6 | int32 version = 1; 7 | Node node = 2; 8 | } 9 | 10 | message Node { 11 | oneof node { 12 | SubNode sub_node = 1; 13 | string some_string = 2; 14 | } 15 | } 16 | 17 | message SubNode { 18 | Node sub = 1; 19 | string another_string = 2; 20 | } -------------------------------------------------------------------------------- /tests/protos_for_test/opentelemetry/proto/collector/README.md: -------------------------------------------------------------------------------- 1 | # OpenTelemetry Collector Proto 2 | 3 | This package describes the OpenTelemetry collector protocol. 4 | 5 | ## Packages 6 | 7 | 1. `common` package contains the common messages shared between different services. 8 | 2. `trace` package contains the Trace Service protos. 9 | 3. `metrics` package contains the Metrics Service protos. 10 | 4. `logs` package contains the Logs Service protos. 11 | -------------------------------------------------------------------------------- /tests/protos_for_test/opentelemetry/proto/collector/logs/v1/logs_service.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2020, OpenTelemetry Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package opentelemetry.proto.collector.logs.v1; 18 | 19 | import "opentelemetry/proto/logs/v1/logs.proto"; 20 | 21 | option csharp_namespace = "OpenTelemetry.Proto.Collector.Logs.V1"; 22 | option java_multiple_files = true; 23 | option java_package = "io.opentelemetry.proto.collector.logs.v1"; 24 | option java_outer_classname = "LogsServiceProto"; 25 | option go_package = "go.opentelemetry.io/proto/otlp/collector/logs/v1"; 26 | 27 | // Service that can be used to push logs between one Application instrumented with 28 | // OpenTelemetry and an collector, or between an collector and a central collector (in this 29 | // case logs are sent/received to/from multiple Applications). 30 | service LogsService { 31 | // For performance reasons, it is recommended to keep this RPC 32 | // alive for the entire life of the application. 33 | rpc Export(ExportLogsServiceRequest) returns (ExportLogsServiceResponse) {} 34 | } 35 | 36 | message ExportLogsServiceRequest { 37 | // An array of ResourceLogs. 38 | // For data coming from a single resource this array will typically contain one 39 | // element. Intermediary nodes (such as OpenTelemetry Collector) that receive 40 | // data from multiple origins typically batch the data before forwarding further and 41 | // in that case this array will contain multiple elements. 42 | repeated opentelemetry.proto.logs.v1.ResourceLogs resource_logs = 1; 43 | } 44 | 45 | message ExportLogsServiceResponse { 46 | // The details of a partially successful export request. 47 | // 48 | // If the request is only partially accepted 49 | // (i.e. when the server accepts only parts of the data and rejects the rest) 50 | // the server MUST initialize the `partial_success` field and MUST 51 | // set the `rejected_` with the number of items it rejected. 52 | // 53 | // Servers MAY also make use of the `partial_success` field to convey 54 | // warnings/suggestions to senders even when the request was fully accepted. 55 | // In such cases, the `rejected_` MUST have a value of `0` and 56 | // the `error_message` MUST be non-empty. 57 | // 58 | // A `partial_success` message with an empty value (rejected_ = 0 and 59 | // `error_message` = "") is equivalent to it not being set/present. Senders 60 | // SHOULD interpret it the same way as in the full success case. 61 | ExportLogsPartialSuccess partial_success = 1; 62 | } 63 | 64 | message ExportLogsPartialSuccess { 65 | // The number of rejected log records. 66 | // 67 | // A `rejected_` field holding a `0` value indicates that the 68 | // request was fully accepted. 69 | int64 rejected_log_records = 1; 70 | 71 | // A developer-facing human-readable message in English. It should be used 72 | // either to explain why the server rejected parts of the data during a partial 73 | // success or to convey warnings/suggestions during a full success. The message 74 | // should offer guidance on how users can address such issues. 75 | // 76 | // error_message is an optional field. An error_message with an empty value 77 | // is equivalent to it not being set. 78 | string error_message = 2; 79 | } 80 | -------------------------------------------------------------------------------- /tests/protos_for_test/opentelemetry/proto/collector/logs/v1/logs_service_http.yaml: -------------------------------------------------------------------------------- 1 | # This is an API configuration to generate an HTTP/JSON -> gRPC gateway for the 2 | # OpenTelemetry service using github.com/grpc-ecosystem/grpc-gateway. 3 | type: google.api.Service 4 | config_version: 3 5 | http: 6 | rules: 7 | - selector: opentelemetry.proto.collector.logs.v1.LogsService.Export 8 | post: /v1/logs 9 | body: "*" -------------------------------------------------------------------------------- /tests/protos_for_test/opentelemetry/proto/collector/metrics/v1/metrics_service.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2019, OpenTelemetry Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package opentelemetry.proto.collector.metrics.v1; 18 | 19 | import "opentelemetry/proto/metrics/v1/metrics.proto"; 20 | 21 | option csharp_namespace = "OpenTelemetry.Proto.Collector.Metrics.V1"; 22 | option java_multiple_files = true; 23 | option java_package = "io.opentelemetry.proto.collector.metrics.v1"; 24 | option java_outer_classname = "MetricsServiceProto"; 25 | option go_package = "go.opentelemetry.io/proto/otlp/collector/metrics/v1"; 26 | 27 | // Service that can be used to push metrics between one Application 28 | // instrumented with OpenTelemetry and a collector, or between a collector and a 29 | // central collector. 30 | service MetricsService { 31 | // For performance reasons, it is recommended to keep this RPC 32 | // alive for the entire life of the application. 33 | rpc Export(ExportMetricsServiceRequest) returns (ExportMetricsServiceResponse) {} 34 | } 35 | 36 | message ExportMetricsServiceRequest { 37 | // An array of ResourceMetrics. 38 | // For data coming from a single resource this array will typically contain one 39 | // element. Intermediary nodes (such as OpenTelemetry Collector) that receive 40 | // data from multiple origins typically batch the data before forwarding further and 41 | // in that case this array will contain multiple elements. 42 | repeated opentelemetry.proto.metrics.v1.ResourceMetrics resource_metrics = 1; 43 | } 44 | 45 | message ExportMetricsServiceResponse { 46 | // The details of a partially successful export request. 47 | // 48 | // If the request is only partially accepted 49 | // (i.e. when the server accepts only parts of the data and rejects the rest) 50 | // the server MUST initialize the `partial_success` field and MUST 51 | // set the `rejected_` with the number of items it rejected. 52 | // 53 | // Servers MAY also make use of the `partial_success` field to convey 54 | // warnings/suggestions to senders even when the request was fully accepted. 55 | // In such cases, the `rejected_` MUST have a value of `0` and 56 | // the `error_message` MUST be non-empty. 57 | // 58 | // A `partial_success` message with an empty value (rejected_ = 0 and 59 | // `error_message` = "") is equivalent to it not being set/present. Senders 60 | // SHOULD interpret it the same way as in the full success case. 61 | ExportMetricsPartialSuccess partial_success = 1; 62 | } 63 | 64 | message ExportMetricsPartialSuccess { 65 | // The number of rejected data points. 66 | // 67 | // A `rejected_` field holding a `0` value indicates that the 68 | // request was fully accepted. 69 | int64 rejected_data_points = 1; 70 | 71 | // A developer-facing human-readable message in English. It should be used 72 | // either to explain why the server rejected parts of the data during a partial 73 | // success or to convey warnings/suggestions during a full success. The message 74 | // should offer guidance on how users can address such issues. 75 | // 76 | // error_message is an optional field. An error_message with an empty value 77 | // is equivalent to it not being set. 78 | string error_message = 2; 79 | } 80 | -------------------------------------------------------------------------------- /tests/protos_for_test/opentelemetry/proto/collector/metrics/v1/metrics_service_http.yaml: -------------------------------------------------------------------------------- 1 | # This is an API configuration to generate an HTTP/JSON -> gRPC gateway for the 2 | # OpenTelemetry service using github.com/grpc-ecosystem/grpc-gateway. 3 | type: google.api.Service 4 | config_version: 3 5 | http: 6 | rules: 7 | - selector: opentelemetry.proto.collector.metrics.v1.MetricsService.Export 8 | post: /v1/metrics 9 | body: "*" -------------------------------------------------------------------------------- /tests/protos_for_test/opentelemetry/proto/collector/profiles/v1experimental/profiles_service.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2023, OpenTelemetry Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package opentelemetry.proto.collector.profiles.v1experimental; 18 | 19 | import "opentelemetry/proto/profiles/v1experimental/profiles.proto"; 20 | 21 | option csharp_namespace = "OpenTelemetry.Proto.Collector.Profiles.V1Experimental"; 22 | option java_multiple_files = true; 23 | option java_package = "io.opentelemetry.proto.collector.profiles.v1experimental"; 24 | option java_outer_classname = "ProfilesServiceProto"; 25 | option go_package = "go.opentelemetry.io/proto/otlp/collector/profiles/v1experimental"; 26 | 27 | // Service that can be used to push profiles between one Application instrumented with 28 | // OpenTelemetry and a collector, or between a collector and a central collector. 29 | service ProfilesService { 30 | // For performance reasons, it is recommended to keep this RPC 31 | // alive for the entire life of the application. 32 | rpc Export(ExportProfilesServiceRequest) returns (ExportProfilesServiceResponse) {} 33 | } 34 | 35 | message ExportProfilesServiceRequest { 36 | // An array of ResourceProfiles. 37 | // For data coming from a single resource this array will typically contain one 38 | // element. Intermediary nodes (such as OpenTelemetry Collector) that receive 39 | // data from multiple origins typically batch the data before forwarding further and 40 | // in that case this array will contain multiple elements. 41 | repeated opentelemetry.proto.profiles.v1experimental.ResourceProfiles resource_profiles = 1; 42 | } 43 | 44 | message ExportProfilesServiceResponse { 45 | // The details of a partially successful export request. 46 | // 47 | // If the request is only partially accepted 48 | // (i.e. when the server accepts only parts of the data and rejects the rest) 49 | // the server MUST initialize the `partial_success` field and MUST 50 | // set the `rejected_` with the number of items it rejected. 51 | // 52 | // Servers MAY also make use of the `partial_success` field to convey 53 | // warnings/suggestions to senders even when the request was fully accepted. 54 | // In such cases, the `rejected_` MUST have a value of `0` and 55 | // the `error_message` MUST be non-empty. 56 | // 57 | // A `partial_success` message with an empty value (rejected_ = 0 and 58 | // `error_message` = "") is equivalent to it not being set/present. Senders 59 | // SHOULD interpret it the same way as in the full success case. 60 | ExportProfilesPartialSuccess partial_success = 1; 61 | } 62 | 63 | message ExportProfilesPartialSuccess { 64 | // The number of rejected profiles. 65 | // 66 | // A `rejected_` field holding a `0` value indicates that the 67 | // request was fully accepted. 68 | int64 rejected_profiles = 1; 69 | 70 | // A developer-facing human-readable message in English. It should be used 71 | // either to explain why the server rejected parts of the data during a partial 72 | // success or to convey warnings/suggestions during a full success. The message 73 | // should offer guidance on how users can address such issues. 74 | // 75 | // error_message is an optional field. An error_message with an empty value 76 | // is equivalent to it not being set. 77 | string error_message = 2; 78 | } 79 | -------------------------------------------------------------------------------- /tests/protos_for_test/opentelemetry/proto/collector/profiles/v1experimental/profiles_service_http.yaml: -------------------------------------------------------------------------------- 1 | # This is an API configuration to generate an HTTP/JSON -> gRPC gateway for the 2 | # OpenTelemetry service using github.com/grpc-ecosystem/grpc-gateway. 3 | type: google.api.Service 4 | config_version: 3 5 | http: 6 | rules: 7 | - selector: opentelemetry.proto.collector.profiles.v1experimental.ProfilesService.Export 8 | post: /v1experimental/profiles 9 | body: "*" 10 | -------------------------------------------------------------------------------- /tests/protos_for_test/opentelemetry/proto/collector/trace/v1/trace_service.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2019, OpenTelemetry Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package opentelemetry.proto.collector.trace.v1; 18 | 19 | import "opentelemetry/proto/trace/v1/trace.proto"; 20 | 21 | option csharp_namespace = "OpenTelemetry.Proto.Collector.Trace.V1"; 22 | option java_multiple_files = true; 23 | option java_package = "io.opentelemetry.proto.collector.trace.v1"; 24 | option java_outer_classname = "TraceServiceProto"; 25 | option go_package = "go.opentelemetry.io/proto/otlp/collector/trace/v1"; 26 | 27 | // Service that can be used to push spans between one Application instrumented with 28 | // OpenTelemetry and a collector, or between a collector and a central collector (in this 29 | // case spans are sent/received to/from multiple Applications). 30 | service TraceService { 31 | // For performance reasons, it is recommended to keep this RPC 32 | // alive for the entire life of the application. 33 | rpc Export(ExportTraceServiceRequest) returns (ExportTraceServiceResponse) {} 34 | } 35 | 36 | message ExportTraceServiceRequest { 37 | // An array of ResourceSpans. 38 | // For data coming from a single resource this array will typically contain one 39 | // element. Intermediary nodes (such as OpenTelemetry Collector) that receive 40 | // data from multiple origins typically batch the data before forwarding further and 41 | // in that case this array will contain multiple elements. 42 | repeated opentelemetry.proto.trace.v1.ResourceSpans resource_spans = 1; 43 | } 44 | 45 | message ExportTraceServiceResponse { 46 | // The details of a partially successful export request. 47 | // 48 | // If the request is only partially accepted 49 | // (i.e. when the server accepts only parts of the data and rejects the rest) 50 | // the server MUST initialize the `partial_success` field and MUST 51 | // set the `rejected_` with the number of items it rejected. 52 | // 53 | // Servers MAY also make use of the `partial_success` field to convey 54 | // warnings/suggestions to senders even when the request was fully accepted. 55 | // In such cases, the `rejected_` MUST have a value of `0` and 56 | // the `error_message` MUST be non-empty. 57 | // 58 | // A `partial_success` message with an empty value (rejected_ = 0 and 59 | // `error_message` = "") is equivalent to it not being set/present. Senders 60 | // SHOULD interpret it the same way as in the full success case. 61 | ExportTracePartialSuccess partial_success = 1; 62 | } 63 | 64 | message ExportTracePartialSuccess { 65 | // The number of rejected spans. 66 | // 67 | // A `rejected_` field holding a `0` value indicates that the 68 | // request was fully accepted. 69 | int64 rejected_spans = 1; 70 | 71 | // A developer-facing human-readable message in English. It should be used 72 | // either to explain why the server rejected parts of the data during a partial 73 | // success or to convey warnings/suggestions during a full success. The message 74 | // should offer guidance on how users can address such issues. 75 | // 76 | // error_message is an optional field. An error_message with an empty value 77 | // is equivalent to it not being set. 78 | string error_message = 2; 79 | } 80 | -------------------------------------------------------------------------------- /tests/protos_for_test/opentelemetry/proto/collector/trace/v1/trace_service_http.yaml: -------------------------------------------------------------------------------- 1 | # This is an API configuration to generate an HTTP/JSON -> gRPC gateway for the 2 | # OpenTelemetry service using github.com/grpc-ecosystem/grpc-gateway. 3 | type: google.api.Service 4 | config_version: 3 5 | http: 6 | rules: 7 | - selector: opentelemetry.proto.collector.trace.v1.TraceService.Export 8 | post: /v1/traces 9 | body: "*" 10 | -------------------------------------------------------------------------------- /tests/protos_for_test/opentelemetry/proto/common/v1/common.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2019, OpenTelemetry Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package opentelemetry.proto.common.v1; 18 | 19 | option csharp_namespace = "OpenTelemetry.Proto.Common.V1"; 20 | option java_multiple_files = true; 21 | option java_package = "io.opentelemetry.proto.common.v1"; 22 | option java_outer_classname = "CommonProto"; 23 | option go_package = "go.opentelemetry.io/proto/otlp/common/v1"; 24 | 25 | // AnyValue is used to represent any type of attribute value. AnyValue may contain a 26 | // primitive value such as a string or integer or it may contain an arbitrary nested 27 | // object containing arrays, key-value lists and primitives. 28 | message AnyValue { 29 | // The value is one of the listed fields. It is valid for all values to be unspecified 30 | // in which case this AnyValue is considered to be "empty". 31 | oneof value { 32 | string string_value = 1; 33 | bool bool_value = 2; 34 | int64 int_value = 3; 35 | double double_value = 4; 36 | ArrayValue array_value = 5; 37 | KeyValueList kvlist_value = 6; 38 | bytes bytes_value = 7; 39 | } 40 | } 41 | 42 | // ArrayValue is a list of AnyValue messages. We need ArrayValue as a message 43 | // since oneof in AnyValue does not allow repeated fields. 44 | message ArrayValue { 45 | // Array of values. The array may be empty (contain 0 elements). 46 | repeated AnyValue values = 1; 47 | } 48 | 49 | // KeyValueList is a list of KeyValue messages. We need KeyValueList as a message 50 | // since `oneof` in AnyValue does not allow repeated fields. Everywhere else where we need 51 | // a list of KeyValue messages (e.g. in Span) we use `repeated KeyValue` directly to 52 | // avoid unnecessary extra wrapping (which slows down the protocol). The 2 approaches 53 | // are semantically equivalent. 54 | message KeyValueList { 55 | // A collection of key/value pairs of key-value pairs. The list may be empty (may 56 | // contain 0 elements). 57 | // The keys MUST be unique (it is not allowed to have more than one 58 | // value with the same key). 59 | repeated KeyValue values = 1; 60 | } 61 | 62 | // KeyValue is a key-value pair that is used to store Span attributes, Link 63 | // attributes, etc. 64 | message KeyValue { 65 | string key = 1; 66 | AnyValue value = 2; 67 | } 68 | 69 | // InstrumentationScope is a message representing the instrumentation scope information 70 | // such as the fully qualified name and version. 71 | message InstrumentationScope { 72 | // An empty instrumentation scope name means the name is unknown. 73 | string name = 1; 74 | string version = 2; 75 | 76 | // Additional attributes that describe the scope. [Optional]. 77 | // Attribute keys MUST be unique (it is not allowed to have more than one 78 | // attribute with the same key). 79 | repeated KeyValue attributes = 3; 80 | uint32 dropped_attributes_count = 4; 81 | } 82 | -------------------------------------------------------------------------------- /tests/protos_for_test/opentelemetry/proto/logs/v1/logs.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2020, OpenTelemetry Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package opentelemetry.proto.logs.v1; 18 | 19 | import "opentelemetry/proto/common/v1/common.proto"; 20 | import "opentelemetry/proto/resource/v1/resource.proto"; 21 | 22 | option csharp_namespace = "OpenTelemetry.Proto.Logs.V1"; 23 | option java_multiple_files = true; 24 | option java_package = "io.opentelemetry.proto.logs.v1"; 25 | option java_outer_classname = "LogsProto"; 26 | option go_package = "go.opentelemetry.io/proto/otlp/logs/v1"; 27 | 28 | // LogsData represents the logs data that can be stored in a persistent storage, 29 | // OR can be embedded by other protocols that transfer OTLP logs data but do not 30 | // implement the OTLP protocol. 31 | // 32 | // The main difference between this message and collector protocol is that 33 | // in this message there will not be any "control" or "metadata" specific to 34 | // OTLP protocol. 35 | // 36 | // When new fields are added into this message, the OTLP request MUST be updated 37 | // as well. 38 | message LogsData { 39 | // An array of ResourceLogs. 40 | // For data coming from a single resource this array will typically contain 41 | // one element. Intermediary nodes that receive data from multiple origins 42 | // typically batch the data before forwarding further and in that case this 43 | // array will contain multiple elements. 44 | repeated ResourceLogs resource_logs = 1; 45 | } 46 | 47 | // A collection of ScopeLogs from a Resource. 48 | message ResourceLogs { 49 | reserved 1000; 50 | 51 | // The resource for the logs in this message. 52 | // If this field is not set then resource info is unknown. 53 | opentelemetry.proto.resource.v1.Resource resource = 1; 54 | 55 | // A list of ScopeLogs that originate from a resource. 56 | repeated ScopeLogs scope_logs = 2; 57 | 58 | // The Schema URL, if known. This is the identifier of the Schema that the resource data 59 | // is recorded in. To learn more about Schema URL see 60 | // https://opentelemetry.io/docs/specs/otel/schemas/#schema-url 61 | // This schema_url applies to the data in the "resource" field. It does not apply 62 | // to the data in the "scope_logs" field which have their own schema_url field. 63 | string schema_url = 3; 64 | } 65 | 66 | // A collection of Logs produced by a Scope. 67 | message ScopeLogs { 68 | // The instrumentation scope information for the logs in this message. 69 | // Semantically when InstrumentationScope isn't set, it is equivalent with 70 | // an empty instrumentation scope name (unknown). 71 | opentelemetry.proto.common.v1.InstrumentationScope scope = 1; 72 | 73 | // A list of log records. 74 | repeated LogRecord log_records = 2; 75 | 76 | // The Schema URL, if known. This is the identifier of the Schema that the log data 77 | // is recorded in. To learn more about Schema URL see 78 | // https://opentelemetry.io/docs/specs/otel/schemas/#schema-url 79 | // This schema_url applies to all logs in the "logs" field. 80 | string schema_url = 3; 81 | } 82 | 83 | // Possible values for LogRecord.SeverityNumber. 84 | enum SeverityNumber { 85 | // UNSPECIFIED is the default SeverityNumber, it MUST NOT be used. 86 | SEVERITY_NUMBER_UNSPECIFIED = 0; 87 | SEVERITY_NUMBER_TRACE = 1; 88 | SEVERITY_NUMBER_TRACE2 = 2; 89 | SEVERITY_NUMBER_TRACE3 = 3; 90 | SEVERITY_NUMBER_TRACE4 = 4; 91 | SEVERITY_NUMBER_DEBUG = 5; 92 | SEVERITY_NUMBER_DEBUG2 = 6; 93 | SEVERITY_NUMBER_DEBUG3 = 7; 94 | SEVERITY_NUMBER_DEBUG4 = 8; 95 | SEVERITY_NUMBER_INFO = 9; 96 | SEVERITY_NUMBER_INFO2 = 10; 97 | SEVERITY_NUMBER_INFO3 = 11; 98 | SEVERITY_NUMBER_INFO4 = 12; 99 | SEVERITY_NUMBER_WARN = 13; 100 | SEVERITY_NUMBER_WARN2 = 14; 101 | SEVERITY_NUMBER_WARN3 = 15; 102 | SEVERITY_NUMBER_WARN4 = 16; 103 | SEVERITY_NUMBER_ERROR = 17; 104 | SEVERITY_NUMBER_ERROR2 = 18; 105 | SEVERITY_NUMBER_ERROR3 = 19; 106 | SEVERITY_NUMBER_ERROR4 = 20; 107 | SEVERITY_NUMBER_FATAL = 21; 108 | SEVERITY_NUMBER_FATAL2 = 22; 109 | SEVERITY_NUMBER_FATAL3 = 23; 110 | SEVERITY_NUMBER_FATAL4 = 24; 111 | } 112 | 113 | // LogRecordFlags represents constants used to interpret the 114 | // LogRecord.flags field, which is protobuf 'fixed32' type and is to 115 | // be used as bit-fields. Each non-zero value defined in this enum is 116 | // a bit-mask. To extract the bit-field, for example, use an 117 | // expression like: 118 | // 119 | // (logRecord.flags & LOG_RECORD_FLAGS_TRACE_FLAGS_MASK) 120 | // 121 | enum LogRecordFlags { 122 | // The zero value for the enum. Should not be used for comparisons. 123 | // Instead use bitwise "and" with the appropriate mask as shown above. 124 | LOG_RECORD_FLAGS_DO_NOT_USE = 0; 125 | 126 | // Bits 0-7 are used for trace flags. 127 | LOG_RECORD_FLAGS_TRACE_FLAGS_MASK = 0x000000FF; 128 | 129 | // Bits 8-31 are reserved for future use. 130 | } 131 | 132 | // A log record according to OpenTelemetry Log Data Model: 133 | // https://github.com/open-telemetry/oteps/blob/main/text/logs/0097-log-data-model.md 134 | message LogRecord { 135 | reserved 4; 136 | 137 | // time_unix_nano is the time when the event occurred. 138 | // Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January 1970. 139 | // Value of 0 indicates unknown or missing timestamp. 140 | fixed64 time_unix_nano = 1; 141 | 142 | // Time when the event was observed by the collection system. 143 | // For events that originate in OpenTelemetry (e.g. using OpenTelemetry Logging SDK) 144 | // this timestamp is typically set at the generation time and is equal to Timestamp. 145 | // For events originating externally and collected by OpenTelemetry (e.g. using 146 | // Collector) this is the time when OpenTelemetry's code observed the event measured 147 | // by the clock of the OpenTelemetry code. This field MUST be set once the event is 148 | // observed by OpenTelemetry. 149 | // 150 | // For converting OpenTelemetry log data to formats that support only one timestamp or 151 | // when receiving OpenTelemetry log data by recipients that support only one timestamp 152 | // internally the following logic is recommended: 153 | // - Use time_unix_nano if it is present, otherwise use observed_time_unix_nano. 154 | // 155 | // Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January 1970. 156 | // Value of 0 indicates unknown or missing timestamp. 157 | fixed64 observed_time_unix_nano = 11; 158 | 159 | // Numerical value of the severity, normalized to values described in Log Data Model. 160 | // [Optional]. 161 | SeverityNumber severity_number = 2; 162 | 163 | // The severity text (also known as log level). The original string representation as 164 | // it is known at the source. [Optional]. 165 | string severity_text = 3; 166 | 167 | // A value containing the body of the log record. Can be for example a human-readable 168 | // string message (including multi-line) describing the event in a free form or it can 169 | // be a structured data composed of arrays and maps of other values. [Optional]. 170 | opentelemetry.proto.common.v1.AnyValue body = 5; 171 | 172 | // Additional attributes that describe the specific event occurrence. [Optional]. 173 | // Attribute keys MUST be unique (it is not allowed to have more than one 174 | // attribute with the same key). 175 | repeated opentelemetry.proto.common.v1.KeyValue attributes = 6; 176 | uint32 dropped_attributes_count = 7; 177 | 178 | // Flags, a bit field. 8 least significant bits are the trace flags as 179 | // defined in W3C Trace Context specification. 24 most significant bits are reserved 180 | // and must be set to 0. Readers must not assume that 24 most significant bits 181 | // will be zero and must correctly mask the bits when reading 8-bit trace flag (use 182 | // flags & LOG_RECORD_FLAGS_TRACE_FLAGS_MASK). [Optional]. 183 | fixed32 flags = 8; 184 | 185 | // A unique identifier for a trace. All logs from the same trace share 186 | // the same `trace_id`. The ID is a 16-byte array. An ID with all zeroes OR 187 | // of length other than 16 bytes is considered invalid (empty string in OTLP/JSON 188 | // is zero-length and thus is also invalid). 189 | // 190 | // This field is optional. 191 | // 192 | // The receivers SHOULD assume that the log record is not associated with a 193 | // trace if any of the following is true: 194 | // - the field is not present, 195 | // - the field contains an invalid value. 196 | bytes trace_id = 9; 197 | 198 | // A unique identifier for a span within a trace, assigned when the span 199 | // is created. The ID is an 8-byte array. An ID with all zeroes OR of length 200 | // other than 8 bytes is considered invalid (empty string in OTLP/JSON 201 | // is zero-length and thus is also invalid). 202 | // 203 | // This field is optional. If the sender specifies a valid span_id then it SHOULD also 204 | // specify a valid trace_id. 205 | // 206 | // The receivers SHOULD assume that the log record is not associated with a 207 | // span if any of the following is true: 208 | // - the field is not present, 209 | // - the field contains an invalid value. 210 | bytes span_id = 10; 211 | } 212 | -------------------------------------------------------------------------------- /tests/protos_for_test/opentelemetry/proto/profiles/v1experimental/profiles.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2023, OpenTelemetry Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package opentelemetry.proto.profiles.v1experimental; 18 | 19 | import "opentelemetry/proto/common/v1/common.proto"; 20 | import "opentelemetry/proto/resource/v1/resource.proto"; 21 | import "opentelemetry/proto/profiles/v1experimental/pprofextended.proto"; 22 | 23 | option csharp_namespace = "OpenTelemetry.Proto.Profiles.V1Experimental"; 24 | option java_multiple_files = true; 25 | option java_package = "io.opentelemetry.proto.profiles.v1experimental"; 26 | option java_outer_classname = "ProfilesProto"; 27 | option go_package = "go.opentelemetry.io/proto/otlp/profiles/v1experimental"; 28 | 29 | // Relationships Diagram 30 | // 31 | // ┌──────────────────┐ LEGEND 32 | // │ ProfilesData │ 33 | // └──────────────────┘ ─────▶ embedded 34 | // │ 35 | // │ 1-n ─────▷ referenced by index 36 | // ▼ 37 | // ┌──────────────────┐ 38 | // │ ResourceProfiles │ 39 | // └──────────────────┘ 40 | // │ 41 | // │ 1-n 42 | // ▼ 43 | // ┌──────────────────┐ 44 | // │ ScopeProfiles │ 45 | // └──────────────────┘ 46 | // │ 47 | // │ 1-n 48 | // ▼ 49 | // ┌──────────────────┐ 50 | // │ ProfileContainer │ 51 | // └──────────────────┘ 52 | // │ 53 | // │ 1-1 54 | // ▼ 55 | // ┌──────────────────┐ 56 | // │ Profile │ 57 | // └──────────────────┘ 58 | // │ n-1 59 | // │ 1-n ┌───────────────────────────────────────┐ 60 | // ▼ │ ▽ 61 | // ┌──────────────────┐ 1-n ┌──────────────┐ ┌──────────┐ 62 | // │ Sample │ ──────▷ │ KeyValue │ │ Link │ 63 | // └──────────────────┘ └──────────────┘ └──────────┘ 64 | // │ 1-n △ △ 65 | // │ 1-n ┌─────────────────┘ │ 1-n 66 | // ▽ │ │ 67 | // ┌──────────────────┐ n-1 ┌──────────────┐ 68 | // │ Location │ ──────▷ │ Mapping │ 69 | // └──────────────────┘ └──────────────┘ 70 | // │ 71 | // │ 1-n 72 | // ▼ 73 | // ┌──────────────────┐ 74 | // │ Line │ 75 | // └──────────────────┘ 76 | // │ 77 | // │ 1-1 78 | // ▽ 79 | // ┌──────────────────┐ 80 | // │ Function │ 81 | // └──────────────────┘ 82 | // 83 | 84 | // ProfilesData represents the profiles data that can be stored in persistent storage, 85 | // OR can be embedded by other protocols that transfer OTLP profiles data but do not 86 | // implement the OTLP protocol. 87 | // 88 | // The main difference between this message and collector protocol is that 89 | // in this message there will not be any "control" or "metadata" specific to 90 | // OTLP protocol. 91 | // 92 | // When new fields are added into this message, the OTLP request MUST be updated 93 | // as well. 94 | message ProfilesData { 95 | // An array of ResourceProfiles. 96 | // For data coming from a single resource this array will typically contain 97 | // one element. Intermediary nodes that receive data from multiple origins 98 | // typically batch the data before forwarding further and in that case this 99 | // array will contain multiple elements. 100 | repeated ResourceProfiles resource_profiles = 1; 101 | } 102 | 103 | 104 | // A collection of ScopeProfiles from a Resource. 105 | message ResourceProfiles { 106 | reserved 1000; 107 | 108 | // The resource for the profiles in this message. 109 | // If this field is not set then no resource info is known. 110 | opentelemetry.proto.resource.v1.Resource resource = 1; 111 | 112 | // A list of ScopeProfiles that originate from a resource. 113 | repeated ScopeProfiles scope_profiles = 2; 114 | 115 | // The Schema URL, if known. This is the identifier of the Schema that the resource data 116 | // is recorded in. To learn more about Schema URL see 117 | // https://opentelemetry.io/docs/specs/otel/schemas/#schema-url 118 | // This schema_url applies to the data in the "resource" field. It does not apply 119 | // to the data in the "scope_profiles" field which have their own schema_url field. 120 | string schema_url = 3; 121 | } 122 | 123 | // A collection of ProfileContainers produced by an InstrumentationScope. 124 | message ScopeProfiles { 125 | // The instrumentation scope information for the profiles in this message. 126 | // Semantically when InstrumentationScope isn't set, it is equivalent with 127 | // an empty instrumentation scope name (unknown). 128 | opentelemetry.proto.common.v1.InstrumentationScope scope = 1; 129 | 130 | // A list of ProfileContainers that originate from an instrumentation scope. 131 | repeated ProfileContainer profiles = 2; 132 | 133 | // The Schema URL, if known. This is the identifier of the Schema that the metric data 134 | // is recorded in. To learn more about Schema URL see 135 | // https://opentelemetry.io/docs/specs/otel/schemas/#schema-url 136 | // This schema_url applies to all profiles in the "profiles" field. 137 | string schema_url = 3; 138 | } 139 | 140 | // A ProfileContainer represents a single profile. It wraps pprof profile with OpenTelemetry specific metadata. 141 | message ProfileContainer { 142 | // A globally unique identifier for a profile. The ID is a 16-byte array. An ID with 143 | // all zeroes is considered invalid. 144 | // 145 | // This field is required. 146 | bytes profile_id = 1; 147 | 148 | // start_time_unix_nano is the start time of the profile. 149 | // Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January 1970. 150 | // 151 | // This field is semantically required and it is expected that end_time >= start_time. 152 | fixed64 start_time_unix_nano = 2; 153 | 154 | // end_time_unix_nano is the end time of the profile. 155 | // Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January 1970. 156 | // 157 | // This field is semantically required and it is expected that end_time >= start_time. 158 | fixed64 end_time_unix_nano = 3; 159 | 160 | // attributes is a collection of key/value pairs. Note, global attributes 161 | // like server name can be set using the resource API. Examples of attributes: 162 | // 163 | // "/http/user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36" 164 | // "/http/server_latency": 300 165 | // "abc.com/myattribute": true 166 | // "abc.com/score": 10.239 167 | // 168 | // The OpenTelemetry API specification further restricts the allowed value types: 169 | // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/common/README.md#attribute 170 | // Attribute keys MUST be unique (it is not allowed to have more than one 171 | // attribute with the same key). 172 | repeated opentelemetry.proto.common.v1.KeyValue attributes = 4; 173 | 174 | // dropped_attributes_count is the number of attributes that were discarded. Attributes 175 | // can be discarded because their keys are too long or because there are too many 176 | // attributes. If this value is 0, then no attributes were dropped. 177 | uint32 dropped_attributes_count = 5; 178 | 179 | // Specifies format of the original payload. Common values are defined in semantic conventions. [required if original_payload is present] 180 | string original_payload_format = 6; 181 | 182 | // Original payload can be stored in this field. This can be useful for users who want to get the original payload. 183 | // Formats such as JFR are highly extensible and can contain more information than what is defined in this spec. 184 | // Inclusion of original payload should be configurable by the user. Default behavior should be to not include the original payload. 185 | // If the original payload is in pprof format, it SHOULD not be included in this field. 186 | // The field is optional, however if it is present `profile` MUST be present and contain the same profiling information. 187 | bytes original_payload = 7; 188 | 189 | // This is a reference to a pprof profile. Required, even when original_payload is present. 190 | opentelemetry.proto.profiles.v1experimental.Profile profile = 8; 191 | } 192 | -------------------------------------------------------------------------------- /tests/protos_for_test/opentelemetry/proto/resource/v1/resource.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2019, OpenTelemetry Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package opentelemetry.proto.resource.v1; 18 | 19 | import "opentelemetry/proto/common/v1/common.proto"; 20 | 21 | option csharp_namespace = "OpenTelemetry.Proto.Resource.V1"; 22 | option java_multiple_files = true; 23 | option java_package = "io.opentelemetry.proto.resource.v1"; 24 | option java_outer_classname = "ResourceProto"; 25 | option go_package = "go.opentelemetry.io/proto/otlp/resource/v1"; 26 | 27 | // Resource information. 28 | message Resource { 29 | // Set of attributes that describe the resource. 30 | // Attribute keys MUST be unique (it is not allowed to have more than one 31 | // attribute with the same key). 32 | repeated opentelemetry.proto.common.v1.KeyValue attributes = 1; 33 | 34 | // dropped_attributes_count is the number of dropped attributes. If the value is 0, then 35 | // no attributes were dropped. 36 | uint32 dropped_attributes_count = 2; 37 | } 38 | -------------------------------------------------------------------------------- /tests/protos_for_test/opentelemetry/proto/trace/v1/trace.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2019, OpenTelemetry Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package opentelemetry.proto.trace.v1; 18 | 19 | import "opentelemetry/proto/common/v1/common.proto"; 20 | import "opentelemetry/proto/resource/v1/resource.proto"; 21 | 22 | option csharp_namespace = "OpenTelemetry.Proto.Trace.V1"; 23 | option java_multiple_files = true; 24 | option java_package = "io.opentelemetry.proto.trace.v1"; 25 | option java_outer_classname = "TraceProto"; 26 | option go_package = "go.opentelemetry.io/proto/otlp/trace/v1"; 27 | 28 | // TracesData represents the traces data that can be stored in a persistent storage, 29 | // OR can be embedded by other protocols that transfer OTLP traces data but do 30 | // not implement the OTLP protocol. 31 | // 32 | // The main difference between this message and collector protocol is that 33 | // in this message there will not be any "control" or "metadata" specific to 34 | // OTLP protocol. 35 | // 36 | // When new fields are added into this message, the OTLP request MUST be updated 37 | // as well. 38 | message TracesData { 39 | // An array of ResourceSpans. 40 | // For data coming from a single resource this array will typically contain 41 | // one element. Intermediary nodes that receive data from multiple origins 42 | // typically batch the data before forwarding further and in that case this 43 | // array will contain multiple elements. 44 | repeated ResourceSpans resource_spans = 1; 45 | } 46 | 47 | // A collection of ScopeSpans from a Resource. 48 | message ResourceSpans { 49 | reserved 1000; 50 | 51 | // The resource for the spans in this message. 52 | // If this field is not set then no resource info is known. 53 | opentelemetry.proto.resource.v1.Resource resource = 1; 54 | 55 | // A list of ScopeSpans that originate from a resource. 56 | repeated ScopeSpans scope_spans = 2; 57 | 58 | // The Schema URL, if known. This is the identifier of the Schema that the resource data 59 | // is recorded in. To learn more about Schema URL see 60 | // https://opentelemetry.io/docs/specs/otel/schemas/#schema-url 61 | // This schema_url applies to the data in the "resource" field. It does not apply 62 | // to the data in the "scope_spans" field which have their own schema_url field. 63 | string schema_url = 3; 64 | } 65 | 66 | // A collection of Spans produced by an InstrumentationScope. 67 | message ScopeSpans { 68 | // The instrumentation scope information for the spans in this message. 69 | // Semantically when InstrumentationScope isn't set, it is equivalent with 70 | // an empty instrumentation scope name (unknown). 71 | opentelemetry.proto.common.v1.InstrumentationScope scope = 1; 72 | 73 | // A list of Spans that originate from an instrumentation scope. 74 | repeated Span spans = 2; 75 | 76 | // The Schema URL, if known. This is the identifier of the Schema that the span data 77 | // is recorded in. To learn more about Schema URL see 78 | // https://opentelemetry.io/docs/specs/otel/schemas/#schema-url 79 | // This schema_url applies to all spans and span events in the "spans" field. 80 | string schema_url = 3; 81 | } 82 | 83 | // A Span represents a single operation performed by a single component of the system. 84 | // 85 | // The next available field id is 17. 86 | message Span { 87 | // A unique identifier for a trace. All spans from the same trace share 88 | // the same `trace_id`. The ID is a 16-byte array. An ID with all zeroes OR 89 | // of length other than 16 bytes is considered invalid (empty string in OTLP/JSON 90 | // is zero-length and thus is also invalid). 91 | // 92 | // This field is required. 93 | bytes trace_id = 1; 94 | 95 | // A unique identifier for a span within a trace, assigned when the span 96 | // is created. The ID is an 8-byte array. An ID with all zeroes OR of length 97 | // other than 8 bytes is considered invalid (empty string in OTLP/JSON 98 | // is zero-length and thus is also invalid). 99 | // 100 | // This field is required. 101 | bytes span_id = 2; 102 | 103 | // trace_state conveys information about request position in multiple distributed tracing graphs. 104 | // It is a trace_state in w3c-trace-context format: https://www.w3.org/TR/trace-context/#tracestate-header 105 | // See also https://github.com/w3c/distributed-tracing for more details about this field. 106 | string trace_state = 3; 107 | 108 | // The `span_id` of this span's parent span. If this is a root span, then this 109 | // field must be empty. The ID is an 8-byte array. 110 | bytes parent_span_id = 4; 111 | 112 | // Flags, a bit field. 113 | // 114 | // Bits 0-7 (8 least significant bits) are the trace flags as defined in W3C Trace 115 | // Context specification. To read the 8-bit W3C trace flag, use 116 | // `flags & SPAN_FLAGS_TRACE_FLAGS_MASK`. 117 | // 118 | // See https://www.w3.org/TR/trace-context-2/#trace-flags for the flag definitions. 119 | // 120 | // Bits 8 and 9 represent the 3 states of whether a span's parent 121 | // is remote. The states are (unknown, is not remote, is remote). 122 | // To read whether the value is known, use `(flags & SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK) != 0`. 123 | // To read whether the span is remote, use `(flags & SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK) != 0`. 124 | // 125 | // When creating span messages, if the message is logically forwarded from another source 126 | // with an equivalent flags fields (i.e., usually another OTLP span message), the field SHOULD 127 | // be copied as-is. If creating from a source that does not have an equivalent flags field 128 | // (such as a runtime representation of an OpenTelemetry span), the high 22 bits MUST 129 | // be set to zero. 130 | // Readers MUST NOT assume that bits 10-31 (22 most significant bits) will be zero. 131 | // 132 | // [Optional]. 133 | fixed32 flags = 16; 134 | 135 | // A description of the span's operation. 136 | // 137 | // For example, the name can be a qualified method name or a file name 138 | // and a line number where the operation is called. A best practice is to use 139 | // the same display name at the same call point in an application. 140 | // This makes it easier to correlate spans in different traces. 141 | // 142 | // This field is semantically required to be set to non-empty string. 143 | // Empty value is equivalent to an unknown span name. 144 | // 145 | // This field is required. 146 | string name = 5; 147 | 148 | // SpanKind is the type of span. Can be used to specify additional relationships between spans 149 | // in addition to a parent/child relationship. 150 | enum SpanKind { 151 | // Unspecified. Do NOT use as default. 152 | // Implementations MAY assume SpanKind to be INTERNAL when receiving UNSPECIFIED. 153 | SPAN_KIND_UNSPECIFIED = 0; 154 | 155 | // Indicates that the span represents an internal operation within an application, 156 | // as opposed to an operation happening at the boundaries. Default value. 157 | SPAN_KIND_INTERNAL = 1; 158 | 159 | // Indicates that the span covers server-side handling of an RPC or other 160 | // remote network request. 161 | SPAN_KIND_SERVER = 2; 162 | 163 | // Indicates that the span describes a request to some remote service. 164 | SPAN_KIND_CLIENT = 3; 165 | 166 | // Indicates that the span describes a producer sending a message to a broker. 167 | // Unlike CLIENT and SERVER, there is often no direct critical path latency relationship 168 | // between producer and consumer spans. A PRODUCER span ends when the message was accepted 169 | // by the broker while the logical processing of the message might span a much longer time. 170 | SPAN_KIND_PRODUCER = 4; 171 | 172 | // Indicates that the span describes consumer receiving a message from a broker. 173 | // Like the PRODUCER kind, there is often no direct critical path latency relationship 174 | // between producer and consumer spans. 175 | SPAN_KIND_CONSUMER = 5; 176 | } 177 | 178 | // Distinguishes between spans generated in a particular context. For example, 179 | // two spans with the same name may be distinguished using `CLIENT` (caller) 180 | // and `SERVER` (callee) to identify queueing latency associated with the span. 181 | SpanKind kind = 6; 182 | 183 | // start_time_unix_nano is the start time of the span. On the client side, this is the time 184 | // kept by the local machine where the span execution starts. On the server side, this 185 | // is the time when the server's application handler starts running. 186 | // Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January 1970. 187 | // 188 | // This field is semantically required and it is expected that end_time >= start_time. 189 | fixed64 start_time_unix_nano = 7; 190 | 191 | // end_time_unix_nano is the end time of the span. On the client side, this is the time 192 | // kept by the local machine where the span execution ends. On the server side, this 193 | // is the time when the server application handler stops running. 194 | // Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January 1970. 195 | // 196 | // This field is semantically required and it is expected that end_time >= start_time. 197 | fixed64 end_time_unix_nano = 8; 198 | 199 | // attributes is a collection of key/value pairs. Note, global attributes 200 | // like server name can be set using the resource API. Examples of attributes: 201 | // 202 | // "/http/user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36" 203 | // "/http/server_latency": 300 204 | // "example.com/myattribute": true 205 | // "example.com/score": 10.239 206 | // 207 | // The OpenTelemetry API specification further restricts the allowed value types: 208 | // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/common/README.md#attribute 209 | // Attribute keys MUST be unique (it is not allowed to have more than one 210 | // attribute with the same key). 211 | repeated opentelemetry.proto.common.v1.KeyValue attributes = 9; 212 | 213 | // dropped_attributes_count is the number of attributes that were discarded. Attributes 214 | // can be discarded because their keys are too long or because there are too many 215 | // attributes. If this value is 0, then no attributes were dropped. 216 | uint32 dropped_attributes_count = 10; 217 | 218 | // Event is a time-stamped annotation of the span, consisting of user-supplied 219 | // text description and key-value pairs. 220 | message Event { 221 | // time_unix_nano is the time the event occurred. 222 | fixed64 time_unix_nano = 1; 223 | 224 | // name of the event. 225 | // This field is semantically required to be set to non-empty string. 226 | string name = 2; 227 | 228 | // attributes is a collection of attribute key/value pairs on the event. 229 | // Attribute keys MUST be unique (it is not allowed to have more than one 230 | // attribute with the same key). 231 | repeated opentelemetry.proto.common.v1.KeyValue attributes = 3; 232 | 233 | // dropped_attributes_count is the number of dropped attributes. If the value is 0, 234 | // then no attributes were dropped. 235 | uint32 dropped_attributes_count = 4; 236 | } 237 | 238 | // events is a collection of Event items. 239 | repeated Event events = 11; 240 | 241 | // dropped_events_count is the number of dropped events. If the value is 0, then no 242 | // events were dropped. 243 | uint32 dropped_events_count = 12; 244 | 245 | // A pointer from the current span to another span in the same trace or in a 246 | // different trace. For example, this can be used in batching operations, 247 | // where a single batch handler processes multiple requests from different 248 | // traces or when the handler receives a request from a different project. 249 | message Link { 250 | // A unique identifier of a trace that this linked span is part of. The ID is a 251 | // 16-byte array. 252 | bytes trace_id = 1; 253 | 254 | // A unique identifier for the linked span. The ID is an 8-byte array. 255 | bytes span_id = 2; 256 | 257 | // The trace_state associated with the link. 258 | string trace_state = 3; 259 | 260 | // attributes is a collection of attribute key/value pairs on the link. 261 | // Attribute keys MUST be unique (it is not allowed to have more than one 262 | // attribute with the same key). 263 | repeated opentelemetry.proto.common.v1.KeyValue attributes = 4; 264 | 265 | // dropped_attributes_count is the number of dropped attributes. If the value is 0, 266 | // then no attributes were dropped. 267 | uint32 dropped_attributes_count = 5; 268 | 269 | // Flags, a bit field. 270 | // 271 | // Bits 0-7 (8 least significant bits) are the trace flags as defined in W3C Trace 272 | // Context specification. To read the 8-bit W3C trace flag, use 273 | // `flags & SPAN_FLAGS_TRACE_FLAGS_MASK`. 274 | // 275 | // See https://www.w3.org/TR/trace-context-2/#trace-flags for the flag definitions. 276 | // 277 | // Bits 8 and 9 represent the 3 states of whether the link is remote. 278 | // The states are (unknown, is not remote, is remote). 279 | // To read whether the value is known, use `(flags & SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK) != 0`. 280 | // To read whether the link is remote, use `(flags & SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK) != 0`. 281 | // 282 | // Readers MUST NOT assume that bits 10-31 (22 most significant bits) will be zero. 283 | // When creating new spans, bits 10-31 (most-significant 22-bits) MUST be zero. 284 | // 285 | // [Optional]. 286 | fixed32 flags = 6; 287 | } 288 | 289 | // links is a collection of Links, which are references from this span to a span 290 | // in the same or different trace. 291 | repeated Link links = 13; 292 | 293 | // dropped_links_count is the number of dropped links after the maximum size was 294 | // enforced. If this value is 0, then no links were dropped. 295 | uint32 dropped_links_count = 14; 296 | 297 | // An optional final status for this span. Semantically when Status isn't set, it means 298 | // span's status code is unset, i.e. assume STATUS_CODE_UNSET (code = 0). 299 | Status status = 15; 300 | } 301 | 302 | // The Status type defines a logical error model that is suitable for different 303 | // programming environments, including REST APIs and RPC APIs. 304 | message Status { 305 | reserved 1; 306 | 307 | // A developer-facing human readable error message. 308 | string message = 2; 309 | 310 | // For the semantics of status codes see 311 | // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/api.md#set-status 312 | enum StatusCode { 313 | // The default status. 314 | STATUS_CODE_UNSET = 0; 315 | // The Span has been validated by an Application developer or Operator to 316 | // have completed successfully. 317 | STATUS_CODE_OK = 1; 318 | // The Span contains an error. 319 | STATUS_CODE_ERROR = 2; 320 | }; 321 | 322 | // The status code. 323 | StatusCode code = 3; 324 | } 325 | 326 | // SpanFlags represents constants used to interpret the 327 | // Span.flags field, which is protobuf 'fixed32' type and is to 328 | // be used as bit-fields. Each non-zero value defined in this enum is 329 | // a bit-mask. To extract the bit-field, for example, use an 330 | // expression like: 331 | // 332 | // (span.flags & SPAN_FLAGS_TRACE_FLAGS_MASK) 333 | // 334 | // See https://www.w3.org/TR/trace-context-2/#trace-flags for the flag definitions. 335 | // 336 | // Note that Span flags were introduced in version 1.1 of the 337 | // OpenTelemetry protocol. Older Span producers do not set this 338 | // field, consequently consumers should not rely on the absence of a 339 | // particular flag bit to indicate the presence of a particular feature. 340 | enum SpanFlags { 341 | // The zero value for the enum. Should not be used for comparisons. 342 | // Instead use bitwise "and" with the appropriate mask as shown above. 343 | SPAN_FLAGS_DO_NOT_USE = 0; 344 | 345 | // Bits 0-7 are used for trace flags. 346 | SPAN_FLAGS_TRACE_FLAGS_MASK = 0x000000FF; 347 | 348 | // Bits 8 and 9 are used to indicate that the parent span or link span is remote. 349 | // Bit 8 (`HAS_IS_REMOTE`) indicates whether the value is known. 350 | // Bit 9 (`IS_REMOTE`) indicates whether the span or link is remote. 351 | SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK = 0x00000100; 352 | SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK = 0x00000200; 353 | 354 | // Bits 10-31 are reserved for future use. 355 | } 356 | -------------------------------------------------------------------------------- /tests/protos_for_test/selfref.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package selfref; 4 | 5 | message SelfRefNode { 6 | int32 version = 1; 7 | SelfRefNode node = 2; 8 | } 9 | -------------------------------------------------------------------------------- /tests/protos_for_test/test_messages_proto3.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | // 31 | // Test schema for proto3 messages. This test schema is used by: 32 | // 33 | // - benchmarks 34 | // - fuzz tests 35 | // - conformance tests 36 | // 37 | 38 | syntax = "proto3"; 39 | 40 | package protobuf_test_messages.proto3; 41 | 42 | option java_package = "com.google.protobuf_test_messages.proto3"; 43 | option objc_class_prefix = "Proto3"; 44 | 45 | // This is the default, but we specify it here explicitly. 46 | option optimize_for = SPEED; 47 | 48 | import "google/protobuf/any.proto"; 49 | import "google/protobuf/duration.proto"; 50 | import "google/protobuf/field_mask.proto"; 51 | import "google/protobuf/struct.proto"; 52 | import "google/protobuf/timestamp.proto"; 53 | import "google/protobuf/wrappers.proto"; 54 | 55 | option cc_enable_arenas = true; 56 | 57 | // This proto includes every type of field in both singular and repeated 58 | // forms. 59 | // 60 | // Also, crucially, all messages and enums in this file are eventually 61 | // submessages of this message. So for example, a fuzz test of TestAllTypes 62 | // could trigger bugs that occur in any message type in this file. We verify 63 | // this stays true in a unit test. 64 | message TestAllTypesProto3 { 65 | message NestedMessage { 66 | int32 a = 1; 67 | // FIXME 68 | // TestAllTypesProto3 corecursive = 2; 69 | } 70 | 71 | enum NestedEnum { 72 | FOO = 0; 73 | BAR = 1; 74 | BAZ = 2; 75 | NEG = -1; // Intentionally negative. 76 | } 77 | 78 | enum AliasedEnum { 79 | // option allow_alias = true; 80 | 81 | ALIAS_FOO = 0; 82 | ALIAS_BAR = 1; 83 | // ALIAS_BAZ = 2; 84 | MOO = 2; 85 | //moo = 2; 86 | //bAz = 2; 87 | } 88 | 89 | // Singular 90 | int32 optional_int32 = 1; 91 | int64 optional_int64 = 2; 92 | uint32 optional_uint32 = 3; 93 | uint64 optional_uint64 = 4; 94 | sint32 optional_sint32 = 5; 95 | sint64 optional_sint64 = 6; 96 | fixed32 optional_fixed32 = 7; 97 | fixed64 optional_fixed64 = 8; 98 | sfixed32 optional_sfixed32 = 9; 99 | sfixed64 optional_sfixed64 = 10; 100 | float optional_float = 11; 101 | double optional_double = 12; 102 | bool optional_bool = 13; 103 | string optional_string = 14; 104 | bytes optional_bytes = 15; 105 | 106 | NestedMessage optional_nested_message = 18; 107 | ForeignMessage optional_foreign_message = 19; 108 | 109 | NestedEnum optional_nested_enum = 21; 110 | ForeignEnum optional_foreign_enum = 22; 111 | AliasedEnum optional_aliased_enum = 23; 112 | 113 | string optional_string_piece = 24 [ctype = STRING_PIECE]; 114 | string optional_cord = 25 [ctype = CORD]; 115 | 116 | // FIXME 117 | // TestAllTypesProto3 recursive_message = 27; 118 | 119 | // Repeated 120 | repeated int32 repeated_int32 = 31; 121 | repeated int64 repeated_int64 = 32; 122 | repeated uint32 repeated_uint32 = 33; 123 | repeated uint64 repeated_uint64 = 34; 124 | repeated sint32 repeated_sint32 = 35; 125 | repeated sint64 repeated_sint64 = 36; 126 | repeated fixed32 repeated_fixed32 = 37; 127 | repeated fixed64 repeated_fixed64 = 38; 128 | repeated sfixed32 repeated_sfixed32 = 39; 129 | repeated sfixed64 repeated_sfixed64 = 40; 130 | repeated float repeated_float = 41; 131 | repeated double repeated_double = 42; 132 | repeated bool repeated_bool = 43; 133 | repeated string repeated_string = 44; 134 | repeated bytes repeated_bytes = 45; 135 | 136 | repeated NestedMessage repeated_nested_message = 48; 137 | repeated ForeignMessage repeated_foreign_message = 49; 138 | 139 | repeated NestedEnum repeated_nested_enum = 51; 140 | repeated ForeignEnum repeated_foreign_enum = 52; 141 | 142 | repeated string repeated_string_piece = 54 [ctype = STRING_PIECE]; 143 | repeated string repeated_cord = 55 [ctype = CORD]; 144 | 145 | // Packed 146 | repeated int32 packed_int32 = 75 [packed = true]; 147 | repeated int64 packed_int64 = 76 [packed = true]; 148 | repeated uint32 packed_uint32 = 77 [packed = true]; 149 | repeated uint64 packed_uint64 = 78 [packed = true]; 150 | repeated sint32 packed_sint32 = 79 [packed = true]; 151 | repeated sint64 packed_sint64 = 80 [packed = true]; 152 | repeated fixed32 packed_fixed32 = 81 [packed = true]; 153 | repeated fixed64 packed_fixed64 = 82 [packed = true]; 154 | repeated sfixed32 packed_sfixed32 = 83 [packed = true]; 155 | repeated sfixed64 packed_sfixed64 = 84 [packed = true]; 156 | repeated float packed_float = 85 [packed = true]; 157 | repeated double packed_double = 86 [packed = true]; 158 | repeated bool packed_bool = 87 [packed = true]; 159 | repeated NestedEnum packed_nested_enum = 88 [packed = true]; 160 | 161 | // Unpacked 162 | repeated int32 unpacked_int32 = 89 [packed = false]; 163 | repeated int64 unpacked_int64 = 90 [packed = false]; 164 | repeated uint32 unpacked_uint32 = 91 [packed = false]; 165 | repeated uint64 unpacked_uint64 = 92 [packed = false]; 166 | repeated sint32 unpacked_sint32 = 93 [packed = false]; 167 | repeated sint64 unpacked_sint64 = 94 [packed = false]; 168 | repeated fixed32 unpacked_fixed32 = 95 [packed = false]; 169 | repeated fixed64 unpacked_fixed64 = 96 [packed = false]; 170 | repeated sfixed32 unpacked_sfixed32 = 97 [packed = false]; 171 | repeated sfixed64 unpacked_sfixed64 = 98 [packed = false]; 172 | repeated float unpacked_float = 99 [packed = false]; 173 | repeated double unpacked_double = 100 [packed = false]; 174 | repeated bool unpacked_bool = 101 [packed = false]; 175 | repeated NestedEnum unpacked_nested_enum = 102 [packed = false]; 176 | 177 | // Map 178 | map map_int32_int32 = 56; 179 | map map_int64_int64 = 57; 180 | map map_uint32_uint32 = 58; 181 | map map_uint64_uint64 = 59; 182 | map map_sint32_sint32 = 60; 183 | map map_sint64_sint64 = 61; 184 | map map_fixed32_fixed32 = 62; 185 | map map_fixed64_fixed64 = 63; 186 | map map_sfixed32_sfixed32 = 64; 187 | map map_sfixed64_sfixed64 = 65; 188 | map map_int32_float = 66; 189 | map map_int32_double = 67; 190 | map map_bool_bool = 68; 191 | map map_string_string = 69; 192 | map map_string_bytes = 70; 193 | map map_string_nested_message = 71; 194 | map map_string_foreign_message = 72; 195 | map map_string_nested_enum = 73; 196 | map map_string_foreign_enum = 74; 197 | 198 | oneof oneof_field { 199 | uint32 oneof_uint32 = 111; 200 | NestedMessage oneof_nested_message = 112; 201 | string oneof_string = 113; 202 | bytes oneof_bytes = 114; 203 | bool oneof_bool = 115; 204 | uint64 oneof_uint64 = 116; 205 | float oneof_float = 117; 206 | double oneof_double = 118; 207 | NestedEnum oneof_enum = 119; 208 | google.protobuf.NullValue oneof_null_value = 120; 209 | } 210 | 211 | // Well-known types 212 | google.protobuf.BoolValue optional_bool_wrapper = 201; 213 | google.protobuf.Int32Value optional_int32_wrapper = 202; 214 | google.protobuf.Int64Value optional_int64_wrapper = 203; 215 | google.protobuf.UInt32Value optional_uint32_wrapper = 204; 216 | google.protobuf.UInt64Value optional_uint64_wrapper = 205; 217 | google.protobuf.FloatValue optional_float_wrapper = 206; 218 | google.protobuf.DoubleValue optional_double_wrapper = 207; 219 | google.protobuf.StringValue optional_string_wrapper = 208; 220 | google.protobuf.BytesValue optional_bytes_wrapper = 209; 221 | 222 | repeated google.protobuf.BoolValue repeated_bool_wrapper = 211; 223 | repeated google.protobuf.Int32Value repeated_int32_wrapper = 212; 224 | repeated google.protobuf.Int64Value repeated_int64_wrapper = 213; 225 | repeated google.protobuf.UInt32Value repeated_uint32_wrapper = 214; 226 | repeated google.protobuf.UInt64Value repeated_uint64_wrapper = 215; 227 | repeated google.protobuf.FloatValue repeated_float_wrapper = 216; 228 | repeated google.protobuf.DoubleValue repeated_double_wrapper = 217; 229 | repeated google.protobuf.StringValue repeated_string_wrapper = 218; 230 | repeated google.protobuf.BytesValue repeated_bytes_wrapper = 219; 231 | 232 | google.protobuf.Duration optional_duration = 301; 233 | google.protobuf.Timestamp optional_timestamp = 302; 234 | google.protobuf.FieldMask optional_field_mask = 303; 235 | google.protobuf.Struct optional_struct = 304; 236 | google.protobuf.Any optional_any = 305; 237 | google.protobuf.Value optional_value = 306; 238 | google.protobuf.NullValue optional_null_value = 307; 239 | 240 | repeated google.protobuf.Duration repeated_duration = 311; 241 | repeated google.protobuf.Timestamp repeated_timestamp = 312; 242 | repeated google.protobuf.FieldMask repeated_fieldmask = 313; 243 | repeated google.protobuf.Struct repeated_struct = 324; 244 | repeated google.protobuf.Any repeated_any = 315; 245 | repeated google.protobuf.Value repeated_value = 316; 246 | repeated google.protobuf.ListValue repeated_list_value = 317; 247 | 248 | // Test field-name-to-JSON-name convention. 249 | // (protobuf says names can be any valid C/C++ identifier.) 250 | int32 fieldname1 = 401; 251 | int32 field_name2 = 402; 252 | int32 _field_name3 = 403; 253 | int32 field__name4_ = 404; 254 | int32 field0name5 = 405; 255 | int32 field_0_name6 = 406; 256 | int32 fieldName7 = 407; 257 | int32 FieldName8 = 408; 258 | int32 field_Name9 = 409; 259 | int32 Field_Name10 = 410; 260 | int32 FIELD_NAME11 = 411; 261 | int32 FIELD_name12 = 412; 262 | int32 __field_name13 = 413; 263 | int32 __Field_name14 = 414; 264 | int32 field__name15 = 415; 265 | int32 field__Name16 = 416; 266 | int32 field_name17__ = 417; 267 | int32 Field_name18__ = 418; 268 | 269 | // Reserved for testing unknown fields 270 | reserved 501 to 510; 271 | } 272 | 273 | message ForeignMessage { 274 | int32 c = 1; 275 | } 276 | 277 | enum ForeignEnum { 278 | FOREIGN_FOO = 0; 279 | FOREIGN_BAR = 1; 280 | FOREIGN_BAZ = 2; 281 | } 282 | 283 | message NullHypothesisProto3 {} 284 | 285 | message EnumOnlyProto3 { 286 | enum Bool { 287 | kFalse = 0; 288 | kTrue = 1; 289 | } 290 | } -------------------------------------------------------------------------------- /tests/protos_for_test/whitespace-in-name.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package some.really.long.name.which.does.not.really.make.any.sense.but.sometimes.we.still.see.stuff.like.this; 4 | 5 | message WouldYouParseThisForMePlease { 6 | optional some.really.long. name . which . does .not 7 | .really.make.any. sense.but. 8 | sometimes.we.still 9 | . 10 | see.stuff .like.this 11 | .Test field = 1; 12 | } 13 | 14 | message Test { 15 | string field = 1; 16 | } -------------------------------------------------------------------------------- /tests/tests.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const protobuf = @import("protobuf"); 3 | const mem = std.mem; 4 | const Allocator = mem.Allocator; 5 | const eql = mem.eql; 6 | const fd = protobuf.fd; 7 | const pb_decode = protobuf.pb_decode; 8 | const pb_encode = protobuf.pb_encode; 9 | const pb_deinit = protobuf.pb_deinit; 10 | const pb_init = protobuf.pb_init; 11 | const testing = std.testing; 12 | const ArrayList = std.ArrayList; 13 | const AutoHashMap = std.AutoHashMap; 14 | const FieldType = protobuf.FieldType; 15 | const tests = @import("./generated/tests.pb.zig"); 16 | const DefaultValues = @import("./generated/jspb/test.pb.zig").DefaultValues; 17 | const tests_oneof = @import("./generated/tests/oneof.pb.zig"); 18 | const metrics = @import("./generated/opentelemetry/proto/metrics/v1.pb.zig"); 19 | const selfref = @import("./generated/selfref.pb.zig"); 20 | const pblogs = @import("./generated/opentelemetry/proto/logs/v1.pb.zig"); 21 | 22 | pub fn printAllDecoded(input: []const u8) !void { 23 | var iterator = protobuf.WireDecoderIterator{ .input = input }; 24 | std.debug.print("Decoding: {s}\n", .{std.fmt.fmtSliceHexUpper(input)}); 25 | while (try iterator.next()) |extracted_data| { 26 | std.debug.print(" {any}\n", .{extracted_data}); 27 | } 28 | } 29 | 30 | test "DefaultValuesInit" { 31 | var demo = DefaultValues.init(testing.allocator); 32 | 33 | try testing.expectEqualSlices(u8, "default<>'\"abc", demo.string_field.?.getSlice()); 34 | try testing.expectEqual(true, demo.bool_field.?); 35 | try testing.expectEqual(demo.int_field, 11); 36 | try testing.expectEqual(demo.enum_field.?, .E1); 37 | try testing.expectEqualSlices(u8, "", demo.empty_field.?.getSlice()); 38 | try testing.expectEqualSlices(u8, "moo", demo.bytes_field.?.getSlice()); 39 | } 40 | 41 | test "DefaultValuesDecode" { 42 | var demo = try DefaultValues.decode("", testing.allocator); 43 | 44 | try testing.expectEqualSlices(u8, "default<>'\"abc", demo.string_field.?.getSlice()); 45 | try testing.expectEqual(true, demo.bool_field.?); 46 | try testing.expectEqual(demo.int_field, 11); 47 | try testing.expectEqual(demo.enum_field.?, .E1); 48 | try testing.expectEqualSlices(u8, "", demo.empty_field.?.getSlice()); 49 | try testing.expectEqualSlices(u8, "moo", demo.bytes_field.?.getSlice()); 50 | } 51 | 52 | test "issue #74" { 53 | var item = metrics.MetricsData.init(testing.allocator); 54 | var copy = try item.dupe(testing.allocator); 55 | copy.deinit(); 56 | item.deinit(); 57 | } 58 | 59 | test "LogsData proto issue #84" { 60 | var logsData = pblogs.LogsData.init(std.testing.allocator); 61 | defer logsData.deinit(); 62 | 63 | const rl = pblogs.ResourceLogs.init(std.testing.allocator); 64 | defer rl.deinit(); 65 | 66 | try logsData.resource_logs.append(rl); 67 | 68 | const bytes = try logsData.encode(std.testing.allocator); // <- compile error before 69 | defer std.testing.allocator.free(bytes); 70 | } 71 | 72 | const SelfRefNode = selfref.SelfRefNode; 73 | const ManagedStruct = protobuf.ManagedStruct; 74 | 75 | //pub const SelfRefNode = struct { 76 | // version: i32 = 0, 77 | // node: ?ManagedStruct(SelfRefNode)= null, 78 | // 79 | // pub const _desc_table = .{ 80 | // .version = fd(1, .{ .Varint = .Simple }), 81 | // .node = fd(2, .{ .SubMessage = {} }), 82 | // }; 83 | // 84 | // pub usingnamespace protobuf.MessageMixins(@This()); 85 | //}; 86 | 87 | 88 | test "self ref test" { 89 | var demo = SelfRefNode.init(testing.allocator); 90 | var demo2 = SelfRefNode.init(testing.allocator); 91 | demo2.version = 1; 92 | demo.node = ManagedStruct(SelfRefNode).managed(&demo2); 93 | defer demo.deinit(); 94 | 95 | try testing.expectEqual(@as(i32, 0), demo.version); 96 | const encoded = try demo.encode(testing.allocator); 97 | defer testing.allocator.free(encoded); 98 | 99 | try testing.expectEqualSlices(u8, &[_]u8{0x12, 0x02, 0x08, 0x01}, encoded); 100 | 101 | const decoded = try SelfRefNode.decode(encoded, testing.allocator); 102 | defer decoded.deinit(); 103 | 104 | try testing.expectEqual(@as(i32, 1), decoded.node.?.get().version); 105 | } 106 | 107 | // TODO: check for cyclic structure -------------------------------------------------------------------------------- /tests/tests_fixedsizes.zig: -------------------------------------------------------------------------------- 1 | const FixedSizes = @import("./generated/tests.pb.zig").FixedSizes; 2 | 3 | const std = @import("std"); 4 | const testing = std.testing; 5 | 6 | test "FixedSizes" { 7 | var demo = FixedSizes.init(testing.allocator); 8 | defer demo.deinit(); 9 | demo.sfixed64 = -1; 10 | demo.sfixed32 = -2; 11 | demo.fixed32 = 1; 12 | demo.fixed64 = 2; 13 | demo.double = 5.0; // 0x4014000000000000 14 | demo.float = 5.0; // 0x40a00000 15 | 16 | const obtained = try demo.encode(testing.allocator); 17 | defer testing.allocator.free(obtained); 18 | 19 | const expected = [_]u8{ 0x08 + 1, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x10 + 5, 0xFE, 0xFF, 0xFF, 0xFF, 0x18 + 5, 0x01, 0x00, 0x00, 0x00, 0x20 + 1, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28 + 1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x40, 0x30 + 5, 0x00, 0x00, 0xa0, 0x40 }; 20 | 21 | try testing.expectEqualSlices(u8, &expected, obtained); 22 | 23 | // decoding 24 | const decoded = try FixedSizes.decode(&expected, testing.allocator); 25 | defer decoded.deinit(); 26 | try testing.expectEqual(demo, decoded); 27 | } 28 | 29 | test "FixedSizes - encode/decode" { 30 | var demo = FixedSizes.init(testing.allocator); 31 | defer demo.deinit(); 32 | demo.sfixed64 = -1123123141; 33 | demo.sfixed32 = -2131312; 34 | demo.fixed32 = 1; 35 | demo.fixed64 = 2; 36 | demo.double = 5.0; 37 | demo.float = 5.0; 38 | 39 | const obtained = try demo.encode(testing.allocator); 40 | defer testing.allocator.free(obtained); 41 | 42 | // decoding 43 | const decoded = try FixedSizes.decode(obtained, testing.allocator); 44 | defer decoded.deinit(); 45 | try testing.expectEqualDeep(demo, decoded); 46 | } 47 | --------------------------------------------------------------------------------