diff --git a/.gitignore b/.gitignore index 788727f..79a0101 100644 --- a/.gitignore +++ b/.gitignore @@ -28,4 +28,5 @@ devenv.lock *.nix .devenv **/zig-pkg/**/* -.claude \ No newline at end of file +.claude +.tool-versions diff --git a/bootstrapped-generator/main.zig b/bootstrapped-generator/main.zig index 6958e1f..ea2c1d4 100644 --- a/bootstrapped-generator/main.zig +++ b/bootstrapped-generator/main.zig @@ -988,7 +988,18 @@ const GenerationContext = struct { \\ ) !std.json.Parsed(@This()) {{ \\ return protobuf.json.decode(@This(), input, options, allocator); \\ }} - \\ + \\ + \\ /// Decodes the message from the JSON string, honoring pb options + \\ /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + \\ pub fn jsonDecodeOpts( + \\ input: []const u8, + \\ options: std.json.ParseOptions, + \\ pb_options: protobuf.json.Options, + \\ allocator: std.mem.Allocator, + \\ ) !std.json.Parsed(@This()) {{ + \\ return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + \\ }} + \\ \\ /// Encodes the message to a JSON string. \\ pub fn jsonEncode( \\ self: @This(), diff --git a/src/json.zig b/src/json.zig index 65e17d7..9b36f30 100644 --- a/src/json.zig +++ b/src/json.zig @@ -11,14 +11,79 @@ pub const Options = struct { /// - `false`: emits oneof variants as flat fields in the parent object. /// Example: `{"stringInOneof":"x"}` — this matches the protobuf JSON spec. emit_oneof_field_name: bool = true, + + /// `bytes` fields whose proto name appears in this list are encoded/decoded as + /// lowercase hex strings instead of base64. This is per-field, matching OTLP/JSON + /// which hex-encodes only identifier fields. For OTLP pass: + /// &.{ "trace_id", "span_id", "parent_span_id" } + /// In memory the value is always raw bytes (same as the binary wire path), so a + /// base64 `bytes` field like AnyValue.bytes_value in the same message is unaffected. + /// + /// `encode` reads this directly; for decode use `decodeOpts` (plain `jsonDecode` + /// stays base64). Both thread it explicitly — no global/thread-local state. + hex_bytes_fields: []const []const u8 = &.{}, }; +/// Whether a `bytes` field with proto name `name` should use hex JSON encoding. +fn nameIsHex(set: []const []const u8, name: []const u8) bool { + for (set) |f| { + if (std.mem.eql(u8, f, name)) return true; + } + return false; +} + +/// std.json calls this (fixed 3-arg signature) for top-level and nested messages +/// reached via its own recursion. It can't carry pb `Options`, so it defaults to +/// base64 bytes. Hex decoding goes through `decodeOpts`, which threads `pb_options` +/// down `parseOpts`/`parseStructField`/`parseInner` directly, bypassing std.json's +/// recursion for generated submessages. pub fn parse( Self: type, allocator: std.mem.Allocator, source: anytype, options: std.json.ParseOptions, ) !Self { + return parseOpts(Self, allocator, source, options, .{}); +} + +/// Recurse into a submessage field type, threading `pb_options`. Generated messages +/// go through `parseOpts` (so hex fields work at any depth); well-known types (which +/// have a custom `jsonStringify`) keep std.json's dispatch since they carry no hex +/// bytes. Mirrors std.json.innerParse for the optional/pointer wrappers we emit. +fn parseInner( + comptime FT: type, + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + pb_options: Options, +) std.json.ParseError(@TypeOf(source.*))!FT { + switch (@typeInfo(FT)) { + .optional => |o| return @as(FT, try parseInner(o.child, allocator, source, options, pb_options)), + .pointer => |p| { + if (comptime p.size == .one) { + const v = try allocator.create(p.child); + v.* = try parseInner(p.child, allocator, source, options, pb_options); + return v; + } + return std.json.innerParse(FT, allocator, source, options); + }, + .@"struct" => { + if (comptime @hasDecl(FT, "jsonStringify")) { + return std.json.innerParse(FT, allocator, source, options); + } + return parseOpts(FT, allocator, source, options, pb_options); + }, + else => return std.json.innerParse(FT, allocator, source, options), + } +} + +fn parseOpts( + Self: type, + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + pb_options: Options, +) std.json.ParseError(@TypeOf(source.*))!Self { // Increase eval branch quota for types with hundreds of fields @setEvalBranchQuota(1000000); @@ -99,6 +164,7 @@ pub fn parse( allocator, source, options, + pb_options, ); break; }, @@ -113,6 +179,7 @@ pub fn parse( allocator, source, options, + pb_options, ); fields_seen[i] = true; break; @@ -190,6 +257,7 @@ pub fn parse( allocator, source, options, + nameIsHex(pb_options.hex_bytes_fields, union_field.name), ), else => try std.json.innerParse( union_field.type, @@ -198,11 +266,12 @@ pub fn parse( options, ), }, - .submessage => try std.json.innerParse( + .submessage => try parseInner( union_field.type, allocator, source, options, + pb_options, ), .@"enum" => try parseEnumField( union_field.type, @@ -252,6 +321,40 @@ pub fn decode( return parsed; } +/// Like `decode`, but honors `pb_options` (e.g. `hex_bytes_fields`). Use this when +/// decoding messages with hex `bytes` fields such as OTLP trace_id/span_id. Unlike +/// `decode`, this drives the parse itself so `pb_options` reaches every nested message +/// (std.json's recursion can't carry custom options). +pub fn decodeOpts( + comptime T: type, + input: []const u8, + options: std.json.ParseOptions, + pb_options: Options, + allocator: std.mem.Allocator, +) !std.json.Parsed(T) { + var parsed: std.json.Parsed(T) = .{ + .arena = try allocator.create(std.heap.ArenaAllocator), + .value = undefined, + }; + errdefer allocator.destroy(parsed.arena); + parsed.arena.* = .init(allocator); + errdefer parsed.arena.deinit(); + const aalloc = parsed.arena.allocator(); + + var scanner = std.json.Scanner.initCompleteInput(aalloc, input); + defer scanner.deinit(); + + // Resolve the same defaults std.json.parseFromTokenSourceLeaky would; `parse` + // dereferences options.max_value_len. + var resolved = options; + if (resolved.max_value_len == null) resolved.max_value_len = input.len; + if (resolved.allocate == null) resolved.allocate = .alloc_if_needed; + + parsed.value = try parseInner(T, aalloc, &scanner, resolved, pb_options); + if (.end_of_document != try scanner.next()) return error.UnexpectedToken; + return parsed; +} + pub fn encode( data: anytype, std_options: std.json.Stringify.Options, @@ -323,6 +426,7 @@ fn stringifyOpts(Self: type, self: *const Self, jws: anytype, opts: Options) std try stringify_struct_field_with_options( field_value, descriptor, + fieldInfo.name, jws, opts, ); @@ -369,6 +473,7 @@ fn freeAllocated(allocator: std.mem.Allocator, token: std.json.Token) void { fn stringify_struct_field_with_options( struct_field: anytype, field_descriptor: protobuf.FieldDescriptor, + field_name: []const u8, jws: anytype, pb_options: Options, ) !void { @@ -390,7 +495,7 @@ fn stringify_struct_field_with_options( switch (field_descriptor.ftype) { .scalar => |scalar| switch (scalar) { - .bytes => try print_bytes(value, jws), + .bytes => try print_bytes(value, nameIsHex(pb_options.hex_bytes_fields, field_name), jws), .string => try jws.write(value), else => try print_numeric(value, jws), }, @@ -423,6 +528,7 @@ fn stringify_struct_field_with_options( try stringify_struct_field_with_options( entry.value, @field(Elem._desc_table, "value"), + "value", jws, pb_options, ); @@ -433,7 +539,7 @@ fn stringify_struct_field_with_options( for (slice) |el| { switch (repeated) { .scalar => |scalar| switch (scalar) { - .bytes => try print_bytes(el, jws), + .bytes => try print_bytes(el, nameIsHex(pb_options.hex_bytes_fields, field_name), jws), .string => try jws.write(el), else => try print_numeric(el, jws), }, @@ -462,7 +568,7 @@ fn stringify_struct_field_with_options( try jws.objectField(union_camel_case_name); switch (@field(oneof._desc_table, union_field.name).ftype) { .scalar => |scalar| switch (scalar) { - .bytes => try print_bytes(@field(value, union_field.name), jws), + .bytes => try print_bytes(@field(value, union_field.name), nameIsHex(pb_options.hex_bytes_fields, union_field.name), jws), .string => try jws.write(@field(value, union_field.name)), else => try print_numeric(@field(value, union_field.name), jws), }, @@ -501,95 +607,6 @@ fn stringify_struct_field_with_options( } } -fn stringify_struct_field( - struct_field: anytype, - field_descriptor: protobuf.FieldDescriptor, - jws: anytype, -) !void { - var value: switch (@typeInfo(@TypeOf(struct_field))) { - .optional => |optional| optional.child, - else => @TypeOf(struct_field), - } = undefined; - - switch (@typeInfo(@TypeOf(struct_field))) { - .optional => { - if (struct_field) |v| { - value = v; - } else return; - }, - else => { - value = struct_field; - }, - } - - switch (field_descriptor.ftype) { - .scalar => |scalar| switch (scalar) { - .bytes => try print_bytes(value, jws), - // `.string`s have their own jsonStringify implementation - .string => try jws.write(value), - else => try print_numeric(value, jws), - }, - .@"enum" => try print_numeric(value, jws), - .repeated, .packed_repeated => |repeated| { - // ArrayListUnmanaged - const slice = value.items; - try jws.beginArray(); - for (slice) |el| { - switch (repeated) { - .scalar => |scalar| switch (scalar) { - .bytes => try print_bytes(el, jws), - .string => try jws.write(el), - else => try print_numeric(el, jws), - }, - .@"enum" => try print_numeric(el, jws), - .submessage => try jws.write(el), - } - } - try jws.endArray(); - }, - .oneof => |oneof| { - // Tagged union type - const union_info = @typeInfo(@TypeOf(value)).@"union"; - if (union_info.tag_type == null) { - @compileError("Untagged unions are not supported here"); - } - - try jws.beginObject(); - inline for (union_info.fields) |union_field| { - if (value == @field( - union_info.tag_type.?, - union_field.name, - )) { - const union_camel_case_name = comptime to_camel_case(union_field.name); - try jws.objectField(union_camel_case_name); - switch (@field(oneof._desc_table, union_field.name).ftype) { - .scalar => |scalar| switch (scalar) { - .bytes => try print_bytes(@field(value, union_field.name), jws), - .string => try jws.write(@field(value, union_field.name)), - else => try print_numeric(@field(value, union_field.name), jws), - }, - .@"enum" => try print_numeric(@field(value, union_field.name), jws), - .submessage => try jws.write(@field(value, union_field.name)), - .repeated, .packed_repeated => { - @compileError("Repeated fields are not allowed in oneof"); - }, - .oneof => { - @compileError("one oneof inside another? really?"); - }, - } - break; - } - } else unreachable; - - try jws.endObject(); - }, - .submessage => { - // `.submessage`s (generated structs) have their own jsonStringify implementation - try jws.write(value); - }, - } -} - /// Parse a protobuf enum field from JSON. /// Accepts both integer values and string names (case-insensitive per proto3 JSON spec). /// When options.ignore_unknown_fields is true, unknown string names return the default (0). @@ -633,7 +650,8 @@ fn parseStructField( allocator: std.mem.Allocator, source: anytype, options: std.json.ParseOptions, -) !void { + pb_options: Options, +) std.json.ParseError(@TypeOf(source.*))!void { @field(result.*, fieldInfo.name) = switch (@field( T._desc_table, fieldInfo.name, @@ -685,7 +703,7 @@ fn parseStructField( } return e; }; - } else try std.json.innerParse(ValueType, allocator, source, options); + } else try parseInner(ValueType, allocator, source, options, pb_options); try array_list.append(allocator, .{ .key = parsed_key, .value = parsed_value }); } break :list array_list; @@ -704,13 +722,13 @@ fn parseStructField( .scalar => |scalar| { try array_list.ensureUnusedCapacity(allocator, 1); array_list.appendAssumeCapacity(switch (scalar) { - .bytes => try parse_bytes(allocator, source, options), + .bytes => try parse_bytes(allocator, source, options, nameIsHex(pb_options.hex_bytes_fields, fieldInfo.name)), else => try std.json.innerParse(child_type, allocator, source, options), }); }, .submessage => { try array_list.ensureUnusedCapacity(allocator, 1); - array_list.appendAssumeCapacity(try std.json.innerParse(child_type, allocator, source, options)); + array_list.appendAssumeCapacity(try parseInner(child_type, allocator, source, options, pb_options)); }, .@"enum" => { const v = parseEnumField(child_type, allocator, source, options) catch |e| { @@ -778,7 +796,7 @@ fn parseStructField( union_field.name, ).ftype) { .scalar => |scalar| switch (scalar) { - .bytes => try parse_bytes(allocator, source, options), + .bytes => try parse_bytes(allocator, source, options, nameIsHex(pb_options.hex_bytes_fields, union_field.name)), else => try std.json.innerParse( union_field.type, allocator, @@ -787,11 +805,12 @@ fn parseStructField( ), }, .submessage => other: { - break :other try std.json.innerParse( + break :other try parseInner( union_field.type, allocator, source, options, + pb_options, ); }, .@"enum" => other: { @@ -844,8 +863,14 @@ fn parseStructField( if (comptime @typeInfo(fieldInfo.type) == .optional) { const InnerType = @typeInfo(fieldInfo.type).optional.child; if (comptime @typeInfo(InnerType) != .pointer) { - if (comptime @hasDecl(InnerType, "jsonParse")) { - if (try source.peekNextTokenType() == .null) { + if (try source.peekNextTokenType() == .null) { + // Well-known types may map null to a value (e.g. + // google.protobuf.Value -> null_value); let their custom + // jsonParse decide. Generated messages treat explicit null as + // absent. Routing generated messages through their jsonParse + // here would form an inferred-error-set dependency loop with + // parseOpts, so handle them directly. + if (comptime @hasDecl(InnerType, "jsonStringify")) { const inner = InnerType.jsonParse(allocator, source, options) catch { // The inner type rejected null. Some parsers peek without // consuming on error, so consume the null token if still pending. @@ -856,19 +881,21 @@ fn parseStructField( }; break :blk @as(fieldInfo.type, inner); } + _ = try source.next(); + break :blk @as(fieldInfo.type, null); } } } - break :blk try std.json.innerParse(fieldInfo.type, allocator, source, options); + break :blk try parseInner(fieldInfo.type, allocator, source, options, pb_options); }, .scalar => |scalar| switch (scalar) { - .bytes => try parse_bytes(allocator, source, options), + .bytes => try parse_bytes(allocator, source, options, nameIsHex(pb_options.hex_bytes_fields, fieldInfo.name)), .float, .double => blk: { // Proto3 JSON: reject JSON numbers that overflow to ±inf. However, // the string tokens "Infinity", "-Infinity", and "NaN" are valid per spec. const next_type = try source.peekNextTokenType(); const v = try std.json.innerParse(fieldInfo.type, allocator, source, options); - if (next_type == .number and std.math.isInf(v)) return error.InvalidCharacter; + if (next_type == .number and floatIsInf(v)) return error.InvalidCharacter; break :blk v; }, // `.string`s have their own jsonParse implementation @@ -890,8 +917,35 @@ fn parseStructField( }; } +fn floatIsInf(value: anytype) bool { + switch (comptime @typeInfo(@TypeOf(value))) { + .optional => { + if (value) |v| return floatIsInf(v); + return false; + }, + .float, .comptime_float => return std.math.isInf(value), + else => @compileError("Float expected but " ++ @typeName(@TypeOf(value)) ++ " given"), + } +} + +fn floatIsNan(value: anytype) bool { + switch (comptime @typeInfo(@TypeOf(value))) { + .optional => { + if (value) |v| return floatIsNan(v); + return false; + }, + .float, .comptime_float => return std.math.isNan(value), + else => @compileError("Float expected but " ++ @typeName(@TypeOf(value)) ++ " given"), + } +} + fn print_numeric(value: anytype, jws: anytype) !void { switch (@typeInfo(@TypeOf(value))) { + .optional => { + if (value) |v| return print_numeric(v, jws); + try jws.write(null); + return; + }, .float, .comptime_float => {}, .int => |info| { // Proto3 JSON: 64-bit integers must be encoded as strings. @@ -918,7 +972,7 @@ fn print_numeric(value: anytype, jws: anytype) !void { else => @compileError("Float/integer expected but " ++ @typeName(@TypeOf(value)) ++ " given"), } - if (std.math.isNan(value)) { + if (floatIsNan(value)) { try jws.write("NaN"); } else if (std.math.isPositiveInf(value)) { try jws.write("Infinity"); @@ -961,11 +1015,16 @@ fn mapKeyEq(a: anytype, b: @TypeOf(a)) bool { } } -fn print_bytes(value: anytype, jws: anytype) !void { +fn print_bytes(value: anytype, as_hex: bool, jws: anytype) !void { try jsonValueStartAssumeTypeOk(jws); try jws.writer.writeByte('"'); - try std.base64.standard.Encoder.encodeWriter(jws.writer, value); + if (as_hex) { + // Raw bytes in memory -> lowercase hex (OTLP trace_id/span_id form). + try jws.writer.printHex(value, .lower); + } else { + try std.base64.standard.Encoder.encodeWriter(jws.writer, value); + } try jws.writer.writeByte('"'); @@ -1081,9 +1140,17 @@ fn parse_bytes( allocator: std.mem.Allocator, source: anytype, options: std.json.ParseOptions, + as_hex: bool, ) ![]const u8 { const temp_raw = try std.json.innerParse([]u8, allocator, source, options); defer allocator.free(temp_raw); + if (as_hex) { + // OTLP hex string -> raw bytes in memory (matches the binary wire path). + const out = try allocator.alloc(u8, temp_raw.len / 2); + errdefer allocator.free(out); + const decoded = std.fmt.hexToBytes(out, temp_raw) catch return error.UnexpectedToken; + return decoded; + } return decodeBase64Lenient(allocator, temp_raw) catch error.UnexpectedToken; } diff --git a/src/wire.zig b/src/wire.zig index de1917b..9c9d9be 100644 --- a/src/wire.zig +++ b/src/wire.zig @@ -271,11 +271,8 @@ pub fn decodeScalar( else u64; - var val: Unsigned = 0; - for (0..@sizeOf(Unsigned)) |i| { - const b = try reader.takeByte(); - val |= @as(Unsigned, b) << @intCast(8 * i); - } + const bytes = try reader.takeArray(@sizeOf(Unsigned)); + const val = std.mem.readInt(Unsigned, bytes, .little); return .{ @bitCast(val), @sizeOf(Unsigned) }; } @@ -415,10 +412,28 @@ pub fn decodeRepeated( } // Packed repeated scalar. else if (options.bytes) |bytes| { + // Pre-allocate capacity to avoid repeated reallocations. + if (comptime scalar.isFixed()) { + // Fixed-size scalars: exact element count is known. + const elem_size = @sizeOf(scalar.toType()); + // A packed fixed field must contain a whole number of + // elements. Reject otherwise: the loop below appends while + // `consumed < bytes`, so a non-multiple would append one + // element past the reserved (floor-divided) capacity. + if (bytes % elem_size != 0) { + @branchHint(.cold); + return error.InvalidInput; + } + try result.ensureTotalCapacity(allocator, result.items.len + bytes / elem_size); + } else { + // Varints are at least 1 byte each, so byte count bounds the element count. + try result.ensureTotalCapacity(allocator, result.items.len + bytes); + } + var consumed: usize = 0; while (consumed < bytes) { const decoded, const c = try decodeScalar(scalar, reader); - try result.append(allocator, decoded); + result.appendAssumeCapacity(decoded); consumed += c; } if (consumed != bytes) { @@ -438,6 +453,9 @@ pub fn decodeRepeated( .@"enum" => { // Packed repeated enum. if (options.bytes) |bytes| { + // Enums are varints (at least 1 byte each), so byte count bounds the count. + try result.ensureTotalCapacity(allocator, result.items.len + bytes); + var consumed: usize = 0; while (consumed < bytes) { const raw, const c = try decodeScalar(.int32, reader); @@ -445,7 +463,7 @@ pub fn decodeRepeated( @branchHint(.cold); return error.InvalidInput; }; - try result.append(allocator, decoded); + result.appendAssumeCapacity(decoded); consumed += c; } if (consumed > bytes) { @@ -469,10 +487,15 @@ pub fn decodeRepeated( // Submessages are length-delimited, and cannot be packed. std.debug.assert(options.bytes != null); - try result.append( - allocator, - try protobuf.init(Result, allocator), - ); + // Ensure capacity before append to reduce reallocations. When at + // capacity, grow by at least 8 (or double) to amortize allocation + // cost across repeated submessage occurrences. + if (result.items.len >= result.capacity) { + const grow_by = @max(8, result.capacity); + try result.ensureTotalCapacity(allocator, result.capacity + grow_by); + } + + result.appendAssumeCapacity(try protobuf.init(Result, allocator)); errdefer result.items[result.items.len - 1].deinit(allocator); const msg = &result.items[result.items.len - 1]; const consumed = try decodeMessage( @@ -548,6 +571,89 @@ test decodeRepeated { // capacity should remain >8 try std.testing.expect(list.capacity >= 8); } + + // Packed fixed field whose byte length is not a multiple of the element + // size must be rejected *before* decoding. Capacity is reserved as + // bytes / elem_size (floored), so without the up-front check the loop would + // append one element past the reserved capacity -> OOB heap write. + { + var list: std.ArrayList(u32) = .empty; + defer list.deinit(std.testing.allocator); + + // fixed32 elem_size = 4. options.bytes = 6 is not a multiple of 4: + // one full element (4 bytes) plus 2 trailing bytes. + const input: []const u8 = &.{ 0x01, 0x00, 0x00, 0x00, 0xff, 0xff }; + var reader: std.Io.Reader = .fixed(input); + + try std.testing.expectError( + error.InvalidInput, + decodeRepeated( + &list, + std.testing.allocator, + .{ .scalar = .fixed32 }, + &reader, + .{ .bytes = 6 }, + ), + ); + + // nothing should have been appended + try std.testing.expectEqual(0, list.items.len); + } + + // A well-formed packed fixed field (exact multiple) still decodes. + { + var list: std.ArrayList(u32) = .empty; + defer list.deinit(std.testing.allocator); + + // Two little-endian fixed32 values: 1 and 0x04030201. + const input: []const u8 = &.{ 0x01, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04 }; + var reader: std.Io.Reader = .fixed(input); + + const consumed = try decodeRepeated( + &list, + std.testing.allocator, + .{ .scalar = .fixed32 }, + &reader, + .{ .bytes = input.len }, + ); + try std.testing.expectEqual(input.len, consumed); + try std.testing.expectEqualSlices(u32, &.{ 1, 0x04030201 }, list.items); + } +} + +test "captureField rejects over-long length varint" { + // The .len branch reads the length as a varint into a fixed [10]u8 buffer. + // An over-long varint (>10 bytes, every byte with the continuation bit set) + // must be rejected before it overflows the buffer / the u6 shift. + var buf: std.ArrayList(u8) = .empty; + defer buf.deinit(std.testing.allocator); + + // 11 bytes all with the high (continuation) bit set: never terminates + // within the 10-byte varint limit. + const input: []const u8 = &(.{0x80} ** 11); + var reader: std.Io.Reader = .fixed(input); + + const tag: Tag = .{ .wire_type = .len, .field = 1 }; + try std.testing.expectError( + error.InvalidInput, + captureField(std.testing.allocator, &reader, tag, &buf), + ); +} + +test "captureField accepts a maximal 10-byte length varint shape" { + // A 10-byte varint is the maximum legal length; it must not be rejected by + // the over-long guard. Use 9 continuation bytes followed by a terminator. + var buf: std.ArrayList(u8) = .empty; + defer buf.deinit(std.testing.allocator); + + // 10-byte length varint encoding 0, then no payload (length 0). + const len_varint: []const u8 = &(.{0x80} ** 9 ++ .{0x00}); + var reader: std.Io.Reader = .fixed(len_varint); + + const tag: Tag = .{ .wire_type = .len, .field = 1 }; + const consumed = try captureField(std.testing.allocator, &reader, tag, &buf); + // 10 length bytes consumed, zero-length payload. + try std.testing.expectEqual(10, consumed); } /// Decode a message from reader. @@ -1231,8 +1337,14 @@ fn captureField( len_buf[len_i] = b; len_i += 1; len_val |= @as(u64, b & 0x7F) << shift; - shift += 7; if (b & 0x80 == 0) break; + // A varint is at most 10 bytes. Reject longer encodings before + // they overflow `len_buf` (OOB stack write) or `shift` (u6). + if (len_i >= 10) { + @branchHint(.cold); + return error.InvalidInput; + } + shift += 7; } try buf.appendSlice(allocator, len_buf[0..len_i]); data_consumed += len_i; diff --git a/src/wkt.zig b/src/wkt.zig index fe976d5..8eb5323 100644 --- a/src/wkt.zig +++ b/src/wkt.zig @@ -50,6 +50,9 @@ pub const Any = struct { pub fn jsonDecode(input: []const u8, options: std.json.ParseOptions, allocator: std.mem.Allocator) !std.json.Parsed(@This()) { return protobuf.json.decode(@This(), input, options, allocator); } + pub fn jsonDecodeOpts(input: []const u8, options: std.json.ParseOptions, pb_options: protobuf.json.Options, allocator: std.mem.Allocator) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } pub fn jsonEncode(self: @This(), options: std.json.Stringify.Options, pb_options: protobuf.json.Options, allocator: std.mem.Allocator) ![]const u8 { return protobuf.json.encode(self, options, pb_options, allocator); } @@ -134,6 +137,9 @@ pub const Duration = struct { pub fn jsonDecode(input: []const u8, options: std.json.ParseOptions, allocator: std.mem.Allocator) !std.json.Parsed(@This()) { return protobuf.json.decode(@This(), input, options, allocator); } + pub fn jsonDecodeOpts(input: []const u8, options: std.json.ParseOptions, pb_options: protobuf.json.Options, allocator: std.mem.Allocator) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } pub fn jsonEncode(self: @This(), options: std.json.Stringify.Options, pb_options: protobuf.json.Options, allocator: std.mem.Allocator) ![]const u8 { return protobuf.json.encode(self, options, pb_options, allocator); } @@ -232,6 +238,9 @@ pub const FieldMask = struct { pub fn jsonDecode(input: []const u8, options: std.json.ParseOptions, allocator: std.mem.Allocator) !std.json.Parsed(@This()) { return protobuf.json.decode(@This(), input, options, allocator); } + pub fn jsonDecodeOpts(input: []const u8, options: std.json.ParseOptions, pb_options: protobuf.json.Options, allocator: std.mem.Allocator) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } pub fn jsonEncode(self: @This(), options: std.json.Stringify.Options, pb_options: protobuf.json.Options, allocator: std.mem.Allocator) ![]const u8 { return protobuf.json.encode(self, options, pb_options, allocator); } @@ -411,6 +420,9 @@ pub const Struct = struct { pub fn jsonDecode(input: []const u8, options: std.json.ParseOptions, allocator: std.mem.Allocator) !std.json.Parsed(@This()) { return protobuf.json.decode(@This(), input, options, allocator); } + pub fn jsonDecodeOpts(input: []const u8, options: std.json.ParseOptions, pb_options: protobuf.json.Options, allocator: std.mem.Allocator) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } pub fn jsonEncode(self: @This(), options: std.json.Stringify.Options, pb_options: protobuf.json.Options, allocator: std.mem.Allocator) ![]const u8 { return protobuf.json.encode(self, options, pb_options, allocator); } @@ -488,6 +500,9 @@ pub const Value = struct { pub fn jsonDecode(input: []const u8, options: std.json.ParseOptions, allocator: std.mem.Allocator) !std.json.Parsed(@This()) { return protobuf.json.decode(@This(), input, options, allocator); } + pub fn jsonDecodeOpts(input: []const u8, options: std.json.ParseOptions, pb_options: protobuf.json.Options, allocator: std.mem.Allocator) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } pub fn jsonEncode(self: @This(), options: std.json.Stringify.Options, pb_options: protobuf.json.Options, allocator: std.mem.Allocator) ![]const u8 { return protobuf.json.encode(self, options, pb_options, allocator); } @@ -582,6 +597,9 @@ pub const ListValue = struct { pub fn jsonDecode(input: []const u8, options: std.json.ParseOptions, allocator: std.mem.Allocator) !std.json.Parsed(@This()) { return protobuf.json.decode(@This(), input, options, allocator); } + pub fn jsonDecodeOpts(input: []const u8, options: std.json.ParseOptions, pb_options: protobuf.json.Options, allocator: std.mem.Allocator) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } pub fn jsonEncode(self: @This(), options: std.json.Stringify.Options, pb_options: protobuf.json.Options, allocator: std.mem.Allocator) ![]const u8 { return protobuf.json.encode(self, options, pb_options, allocator); } @@ -637,6 +655,9 @@ pub const Timestamp = struct { pub fn jsonDecode(input: []const u8, options: std.json.ParseOptions, allocator: std.mem.Allocator) !std.json.Parsed(@This()) { return protobuf.json.decode(@This(), input, options, allocator); } + pub fn jsonDecodeOpts(input: []const u8, options: std.json.ParseOptions, pb_options: protobuf.json.Options, allocator: std.mem.Allocator) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } pub fn jsonEncode(self: @This(), options: std.json.Stringify.Options, pb_options: protobuf.json.Options, allocator: std.mem.Allocator) ![]const u8 { return protobuf.json.encode(self, options, pb_options, allocator); } @@ -794,6 +815,9 @@ pub const DoubleValue = struct { pub fn jsonDecode(input: []const u8, options: std.json.ParseOptions, allocator: std.mem.Allocator) !std.json.Parsed(@This()) { return protobuf.json.decode(@This(), input, options, allocator); } + pub fn jsonDecodeOpts(input: []const u8, options: std.json.ParseOptions, pb_options: protobuf.json.Options, allocator: std.mem.Allocator) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } pub fn jsonEncode(self: @This(), options: std.json.Stringify.Options, pb_options: protobuf.json.Options, allocator: std.mem.Allocator) ![]const u8 { return protobuf.json.encode(self, options, pb_options, allocator); } @@ -840,6 +864,9 @@ pub const FloatValue = struct { pub fn jsonDecode(input: []const u8, options: std.json.ParseOptions, allocator: std.mem.Allocator) !std.json.Parsed(@This()) { return protobuf.json.decode(@This(), input, options, allocator); } + pub fn jsonDecodeOpts(input: []const u8, options: std.json.ParseOptions, pb_options: protobuf.json.Options, allocator: std.mem.Allocator) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } pub fn jsonEncode(self: @This(), options: std.json.Stringify.Options, pb_options: protobuf.json.Options, allocator: std.mem.Allocator) ![]const u8 { return protobuf.json.encode(self, options, pb_options, allocator); } @@ -886,6 +913,9 @@ pub const Int64Value = struct { pub fn jsonDecode(input: []const u8, options: std.json.ParseOptions, allocator: std.mem.Allocator) !std.json.Parsed(@This()) { return protobuf.json.decode(@This(), input, options, allocator); } + pub fn jsonDecodeOpts(input: []const u8, options: std.json.ParseOptions, pb_options: protobuf.json.Options, allocator: std.mem.Allocator) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } pub fn jsonEncode(self: @This(), options: std.json.Stringify.Options, pb_options: protobuf.json.Options, allocator: std.mem.Allocator) ![]const u8 { return protobuf.json.encode(self, options, pb_options, allocator); } @@ -935,6 +965,9 @@ pub const UInt64Value = struct { pub fn jsonDecode(input: []const u8, options: std.json.ParseOptions, allocator: std.mem.Allocator) !std.json.Parsed(@This()) { return protobuf.json.decode(@This(), input, options, allocator); } + pub fn jsonDecodeOpts(input: []const u8, options: std.json.ParseOptions, pb_options: protobuf.json.Options, allocator: std.mem.Allocator) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } pub fn jsonEncode(self: @This(), options: std.json.Stringify.Options, pb_options: protobuf.json.Options, allocator: std.mem.Allocator) ![]const u8 { return protobuf.json.encode(self, options, pb_options, allocator); } @@ -984,6 +1017,9 @@ pub const Int32Value = struct { pub fn jsonDecode(input: []const u8, options: std.json.ParseOptions, allocator: std.mem.Allocator) !std.json.Parsed(@This()) { return protobuf.json.decode(@This(), input, options, allocator); } + pub fn jsonDecodeOpts(input: []const u8, options: std.json.ParseOptions, pb_options: protobuf.json.Options, allocator: std.mem.Allocator) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } pub fn jsonEncode(self: @This(), options: std.json.Stringify.Options, pb_options: protobuf.json.Options, allocator: std.mem.Allocator) ![]const u8 { return protobuf.json.encode(self, options, pb_options, allocator); } @@ -1022,6 +1058,9 @@ pub const UInt32Value = struct { pub fn jsonDecode(input: []const u8, options: std.json.ParseOptions, allocator: std.mem.Allocator) !std.json.Parsed(@This()) { return protobuf.json.decode(@This(), input, options, allocator); } + pub fn jsonDecodeOpts(input: []const u8, options: std.json.ParseOptions, pb_options: protobuf.json.Options, allocator: std.mem.Allocator) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } pub fn jsonEncode(self: @This(), options: std.json.Stringify.Options, pb_options: protobuf.json.Options, allocator: std.mem.Allocator) ![]const u8 { return protobuf.json.encode(self, options, pb_options, allocator); } @@ -1060,6 +1099,9 @@ pub const BoolValue = struct { pub fn jsonDecode(input: []const u8, options: std.json.ParseOptions, allocator: std.mem.Allocator) !std.json.Parsed(@This()) { return protobuf.json.decode(@This(), input, options, allocator); } + pub fn jsonDecodeOpts(input: []const u8, options: std.json.ParseOptions, pb_options: protobuf.json.Options, allocator: std.mem.Allocator) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } pub fn jsonEncode(self: @This(), options: std.json.Stringify.Options, pb_options: protobuf.json.Options, allocator: std.mem.Allocator) ![]const u8 { return protobuf.json.encode(self, options, pb_options, allocator); } @@ -1098,6 +1140,9 @@ pub const StringValue = struct { pub fn jsonDecode(input: []const u8, options: std.json.ParseOptions, allocator: std.mem.Allocator) !std.json.Parsed(@This()) { return protobuf.json.decode(@This(), input, options, allocator); } + pub fn jsonDecodeOpts(input: []const u8, options: std.json.ParseOptions, pb_options: protobuf.json.Options, allocator: std.mem.Allocator) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } pub fn jsonEncode(self: @This(), options: std.json.Stringify.Options, pb_options: protobuf.json.Options, allocator: std.mem.Allocator) ![]const u8 { return protobuf.json.encode(self, options, pb_options, allocator); } @@ -1136,6 +1181,9 @@ pub const BytesValue = struct { pub fn jsonDecode(input: []const u8, options: std.json.ParseOptions, allocator: std.mem.Allocator) !std.json.Parsed(@This()) { return protobuf.json.decode(@This(), input, options, allocator); } + pub fn jsonDecodeOpts(input: []const u8, options: std.json.ParseOptions, pb_options: protobuf.json.Options, allocator: std.mem.Allocator) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } pub fn jsonEncode(self: @This(), options: std.json.Stringify.Options, pb_options: protobuf.json.Options, allocator: std.mem.Allocator) ![]const u8 { return protobuf.json.encode(self, options, pb_options, allocator); } @@ -1176,6 +1224,9 @@ pub const Empty = struct { pub fn jsonDecode(input: []const u8, options: std.json.ParseOptions, allocator: std.mem.Allocator) !std.json.Parsed(@This()) { return protobuf.json.decode(@This(), input, options, allocator); } + pub fn jsonDecodeOpts(input: []const u8, options: std.json.ParseOptions, pb_options: protobuf.json.Options, allocator: std.mem.Allocator) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } pub fn jsonEncode(self: @This(), options: std.json.Stringify.Options, pb_options: protobuf.json.Options, allocator: std.mem.Allocator) ![]const u8 { return protobuf.json.encode(self, options, pb_options, allocator); } diff --git a/tests/generated/google/protobuf.pb.zig b/tests/generated/google/protobuf.pb.zig index e332962..12c30d0 100644 --- a/tests/generated/google/protobuf.pb.zig +++ b/tests/generated/google/protobuf.pb.zig @@ -81,6 +81,17 @@ pub const FileDescriptorSet = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -174,6 +185,17 @@ pub const FileDescriptorProto = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -272,6 +294,17 @@ pub const DescriptorProto = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -343,6 +376,17 @@ pub const DescriptorProto = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -402,6 +446,17 @@ pub const DescriptorProto = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -496,6 +551,17 @@ pub const ExtensionRangeOptions = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -555,6 +621,17 @@ pub const ExtensionRangeOptions = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -671,6 +748,17 @@ pub const FieldDescriptorProto = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -740,6 +828,17 @@ pub const OneofDescriptorProto = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -832,6 +931,17 @@ pub const EnumDescriptorProto = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -891,6 +1001,17 @@ pub const EnumDescriptorProto = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -962,6 +1083,17 @@ pub const EnumValueDescriptorProto = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1033,6 +1165,17 @@ pub const ServiceDescriptorProto = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1110,6 +1253,17 @@ pub const MethodDescriptorProto = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1224,6 +1378,17 @@ pub const FileOptions = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1302,6 +1467,17 @@ pub const MessageOptions = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1442,6 +1618,17 @@ pub const FieldOptions = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1515,6 +1702,17 @@ pub const FieldOptions = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1574,6 +1772,17 @@ pub const FieldOptions = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1642,6 +1851,17 @@ pub const OneofOptions = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1716,6 +1936,17 @@ pub const EnumOptions = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1790,6 +2021,17 @@ pub const EnumValueOptions = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1860,6 +2102,17 @@ pub const ServiceOptions = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1942,6 +2195,17 @@ pub const MethodOptions = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -2040,6 +2304,17 @@ pub const UninterpretedOption = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -2099,6 +2374,17 @@ pub const UninterpretedOption = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -2247,6 +2533,17 @@ pub const FeatureSet = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -2306,6 +2603,17 @@ pub const FeatureSet = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -2395,6 +2703,17 @@ pub const FeatureSetDefaults = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -2454,6 +2773,17 @@ pub const FeatureSetDefaults = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -2537,6 +2867,17 @@ pub const SourceCodeInfo = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -2596,6 +2937,17 @@ pub const SourceCodeInfo = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -2689,6 +3041,17 @@ pub const GeneratedCodeInfo = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -2748,6 +3111,17 @@ pub const GeneratedCodeInfo = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), diff --git a/tests/generated/graphics.pb.zig b/tests/generated/graphics.pb.zig index d3169fe..74ef0c7 100644 --- a/tests/generated/graphics.pb.zig +++ b/tests/generated/graphics.pb.zig @@ -60,6 +60,17 @@ pub const InventoryItem = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -150,6 +161,17 @@ pub const Character = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -220,6 +242,17 @@ pub const Alignment = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -305,6 +338,17 @@ pub const Index = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -364,6 +408,17 @@ pub const Index = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -432,6 +487,17 @@ pub const StoredChunk = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -510,6 +576,17 @@ pub const MapEntity = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -584,6 +661,17 @@ pub const Light = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -652,6 +740,17 @@ pub const Point = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -718,6 +817,17 @@ pub const Shape = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -821,6 +931,17 @@ pub const Npc = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -889,6 +1010,17 @@ pub const Npc = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -948,6 +1080,17 @@ pub const Npc = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1030,6 +1173,17 @@ pub const Tile = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1102,6 +1256,17 @@ pub const MapItem = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1186,6 +1351,17 @@ pub const GraphicsDB = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1254,6 +1430,17 @@ pub const Script = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1328,6 +1515,17 @@ pub const SubTexture = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1408,6 +1606,17 @@ pub const Texture = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1491,6 +1700,17 @@ pub const Graphic = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1569,6 +1789,17 @@ pub const Sprite = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1637,6 +1868,17 @@ pub const Animation = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1707,6 +1949,17 @@ pub const Spine = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), diff --git a/tests/generated/jspb/test.pb.zig b/tests/generated/jspb/test.pb.zig index c2b8483..83d0b95 100644 --- a/tests/generated/jspb/test.pb.zig +++ b/tests/generated/jspb/test.pb.zig @@ -61,6 +61,17 @@ pub const Empty = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -127,6 +138,17 @@ pub const EnumContainer = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -197,6 +219,17 @@ pub const Simple1 = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -266,6 +299,17 @@ pub const Simple2 = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -338,6 +382,17 @@ pub const SpecialCases = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -419,6 +474,17 @@ pub const OptionalFields = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -478,6 +544,17 @@ pub const OptionalFields = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -548,6 +625,17 @@ pub const HasExtensions = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -629,6 +717,17 @@ pub const Complex = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -688,6 +787,17 @@ pub const Complex = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -754,6 +864,17 @@ pub const IsExtension = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -816,6 +937,17 @@ pub const IndirectExtension = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -898,6 +1030,17 @@ pub const DefaultValues = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -978,6 +1121,17 @@ pub const FloatingPointFields = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1052,6 +1206,17 @@ pub const TestClone = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1118,6 +1283,17 @@ pub const CloneExtension = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1188,6 +1364,17 @@ pub const TestGroup = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1254,6 +1441,17 @@ pub const TestReservedNames = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1316,6 +1514,17 @@ pub const TestReservedNamesExtension = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1444,6 +1653,17 @@ pub const TestMessageWithOneof = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1512,6 +1732,17 @@ pub const TestEndsWithBytes = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1609,6 +1840,17 @@ pub const TestMapFieldsNoBinary = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1677,6 +1919,17 @@ pub const TestMapFieldsNoBinary = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1745,6 +1998,17 @@ pub const TestMapFieldsNoBinary = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1813,6 +2077,17 @@ pub const TestMapFieldsNoBinary = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1881,6 +2156,17 @@ pub const TestMapFieldsNoBinary = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1949,6 +2235,17 @@ pub const TestMapFieldsNoBinary = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -2017,6 +2314,17 @@ pub const TestMapFieldsNoBinary = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -2085,6 +2393,17 @@ pub const TestMapFieldsNoBinary = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -2153,6 +2472,17 @@ pub const TestMapFieldsNoBinary = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -2221,6 +2551,17 @@ pub const TestMapFieldsNoBinary = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -2289,6 +2630,17 @@ pub const TestMapFieldsNoBinary = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -2348,6 +2700,17 @@ pub const TestMapFieldsNoBinary = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -2414,6 +2777,17 @@ pub const MapValueMessageNoBinary = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -2486,6 +2860,17 @@ pub const Deeply = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -2545,6 +2930,17 @@ pub const Deeply = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -2604,6 +3000,17 @@ pub const Deeply = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), diff --git a/tests/generated/oneofselfref.pb.zig b/tests/generated/oneofselfref.pb.zig index 06877f3..6d3413f 100644 --- a/tests/generated/oneofselfref.pb.zig +++ b/tests/generated/oneofselfref.pb.zig @@ -52,6 +52,17 @@ pub const Result = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -131,6 +142,17 @@ pub const Node = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -199,6 +221,17 @@ pub const SubNode = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), diff --git a/tests/generated/opentelemetry/proto/common/v1.pb.zig b/tests/generated/opentelemetry/proto/common/v1.pb.zig index 5bc2fa9..6007a51 100644 --- a/tests/generated/opentelemetry/proto/common/v1.pb.zig +++ b/tests/generated/opentelemetry/proto/common/v1.pb.zig @@ -81,6 +81,17 @@ pub const AnyValue = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -149,6 +160,17 @@ pub const ArrayValue = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -220,6 +242,17 @@ pub const KeyValueList = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -290,6 +323,17 @@ pub const KeyValue = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -364,6 +408,17 @@ pub const InstrumentationScope = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), diff --git a/tests/generated/opentelemetry/proto/logs/v1.pb.zig b/tests/generated/opentelemetry/proto/logs/v1.pb.zig index de72269..d8b952f 100644 --- a/tests/generated/opentelemetry/proto/logs/v1.pb.zig +++ b/tests/generated/opentelemetry/proto/logs/v1.pb.zig @@ -107,6 +107,17 @@ pub const LogsData = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -178,6 +189,17 @@ pub const ResourceLogs = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -249,6 +271,17 @@ pub const ScopeLogs = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -335,6 +368,17 @@ pub const LogRecord = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), diff --git a/tests/generated/opentelemetry/proto/metrics/v1.pb.zig b/tests/generated/opentelemetry/proto/metrics/v1.pb.zig index deaf874..3b033c9 100644 --- a/tests/generated/opentelemetry/proto/metrics/v1.pb.zig +++ b/tests/generated/opentelemetry/proto/metrics/v1.pb.zig @@ -104,6 +104,17 @@ pub const MetricsData = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -175,6 +186,17 @@ pub const ResourceMetrics = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -246,6 +268,17 @@ pub const ScopeMetrics = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -426,6 +459,17 @@ pub const Metric = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -501,6 +545,17 @@ pub const Gauge = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -573,6 +628,17 @@ pub const Sum = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -643,6 +709,17 @@ pub const Histogram = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -713,6 +790,17 @@ pub const ExponentialHistogram = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -785,6 +873,17 @@ pub const Summary = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -876,6 +975,17 @@ pub const NumberDataPoint = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -972,6 +1082,17 @@ pub const HistogramDataPoint = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1079,6 +1200,17 @@ pub const ExponentialHistogramDataPoint = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1138,6 +1270,17 @@ pub const ExponentialHistogramDataPoint = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1235,6 +1378,17 @@ pub const SummaryDataPoint = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1294,6 +1448,17 @@ pub const SummaryDataPoint = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1385,6 +1550,17 @@ pub const Exemplar = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), diff --git a/tests/generated/opentelemetry/proto/resource/v1.pb.zig b/tests/generated/opentelemetry/proto/resource/v1.pb.zig index c33ec79..2746aa3 100644 --- a/tests/generated/opentelemetry/proto/resource/v1.pb.zig +++ b/tests/generated/opentelemetry/proto/resource/v1.pb.zig @@ -55,6 +55,17 @@ pub const Resource = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), diff --git a/tests/generated/protobuf_test_messages/proto3.pb.zig b/tests/generated/protobuf_test_messages/proto3.pb.zig index 54535ba..bc2ae0a 100644 --- a/tests/generated/protobuf_test_messages/proto3.pb.zig +++ b/tests/generated/protobuf_test_messages/proto3.pb.zig @@ -415,6 +415,17 @@ pub const TestAllTypesProto3 = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -483,6 +494,17 @@ pub const TestAllTypesProto3 = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -551,6 +573,17 @@ pub const TestAllTypesProto3 = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -619,6 +652,17 @@ pub const TestAllTypesProto3 = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -687,6 +731,17 @@ pub const TestAllTypesProto3 = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -755,6 +810,17 @@ pub const TestAllTypesProto3 = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -823,6 +889,17 @@ pub const TestAllTypesProto3 = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -891,6 +968,17 @@ pub const TestAllTypesProto3 = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -959,6 +1047,17 @@ pub const TestAllTypesProto3 = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1027,6 +1126,17 @@ pub const TestAllTypesProto3 = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1095,6 +1205,17 @@ pub const TestAllTypesProto3 = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1163,6 +1284,17 @@ pub const TestAllTypesProto3 = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1231,6 +1363,17 @@ pub const TestAllTypesProto3 = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1299,6 +1442,17 @@ pub const TestAllTypesProto3 = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1367,6 +1521,17 @@ pub const TestAllTypesProto3 = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1435,6 +1600,17 @@ pub const TestAllTypesProto3 = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1503,6 +1679,17 @@ pub const TestAllTypesProto3 = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1571,6 +1758,17 @@ pub const TestAllTypesProto3 = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1639,6 +1837,17 @@ pub const TestAllTypesProto3 = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1707,6 +1916,17 @@ pub const TestAllTypesProto3 = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1766,6 +1986,17 @@ pub const TestAllTypesProto3 = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1832,6 +2063,17 @@ pub const ForeignMessage = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1894,6 +2136,17 @@ pub const NullHypothesisProto3 = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1962,6 +2215,17 @@ pub const EnumOnlyProto3 = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), diff --git a/tests/generated/selfref.pb.zig b/tests/generated/selfref.pb.zig index c1227f9..4461556 100644 --- a/tests/generated/selfref.pb.zig +++ b/tests/generated/selfref.pb.zig @@ -52,6 +52,17 @@ pub const SelfRefNode = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), diff --git a/tests/generated/some/really/long/name/which/does/not/really/make/any/sense/but/sometimes/we/still/see/stuff/like/this.pb.zig b/tests/generated/some/really/long/name/which/does/not/really/make/any/sense/but/sometimes/we/still/see/stuff/like/this.pb.zig index ad439a5..4710617 100644 --- a/tests/generated/some/really/long/name/which/does/not/really/make/any/sense/but/sometimes/we/still/see/stuff/like/this.pb.zig +++ b/tests/generated/some/really/long/name/which/does/not/really/make/any/sense/but/sometimes/we/still/see/stuff/like/this.pb.zig @@ -50,6 +50,17 @@ pub const WouldYouParseThisForMePlease = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -116,6 +127,17 @@ pub const Test = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), diff --git a/tests/generated/tests.pb.zig b/tests/generated/tests.pb.zig index b03bb6f..5797d96 100644 --- a/tests/generated/tests.pb.zig +++ b/tests/generated/tests.pb.zig @@ -82,6 +82,17 @@ pub const FixedSizes = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -163,6 +174,17 @@ pub const WithEnum = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -237,6 +259,17 @@ pub const WithEnumShadow = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -303,6 +336,17 @@ pub const RepeatedEnum = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -387,6 +431,17 @@ pub const Packed = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -471,6 +526,17 @@ pub const UnPacked = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -537,6 +603,17 @@ pub const WithSubmessages = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -603,6 +680,17 @@ pub const WithStrings = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -669,6 +757,17 @@ pub const WithRepeatedStrings = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -692,9 +791,90 @@ pub const WithRepeatedStrings = struct { pub const WithBytes = struct { byte_field: []const u8 = &.{}, + hex_field: []const u8 = &.{}, pub const _desc_table = .{ .byte_field = fd(1, .{ .scalar = .bytes }), + .hex_field = fd(2, .{ .scalar = .bytes }), + }; + + /// Encodes the message to the writer + /// The allocator is used to generate submessages internally. + /// Hence, an ArenaAllocator is a preferred choice if allocations are a bottleneck. + pub fn encode( + self: @This(), + writer: *std.Io.Writer, + allocator: std.mem.Allocator, + ) (std.Io.Writer.Error || std.mem.Allocator.Error)!void { + return protobuf.encode(writer, allocator, self); + } + + /// Decodes the message from the bytes read from the reader. + pub fn decode( + reader: *std.Io.Reader, + allocator: std.mem.Allocator, + ) (protobuf.DecodingError || std.Io.Reader.Error || std.mem.Allocator.Error)!@This() { + return protobuf.decode(@This(), reader, allocator); + } + + /// Deinitializes and frees the memory associated with the message. + pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { + return protobuf.deinit(allocator, self); + } + + /// Duplicates the message. + pub fn dupe(self: @This(), allocator: std.mem.Allocator) std.mem.Allocator.Error!@This() { + return protobuf.dupe(@This(), self, allocator); + } + + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + + /// Encodes the message to a JSON string. + pub fn jsonEncode( + self: @This(), + options: std.json.Stringify.Options, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) ![]const u8 { + return protobuf.json.encode(self, options, pb_options, allocator); + } + + /// This method is used by std.json + /// internally for deserialization. DO NOT RENAME! + pub fn jsonParse( + allocator: std.mem.Allocator, + source: anytype, + options: std.json.ParseOptions, + ) !@This() { + return protobuf.json.parse(@This(), allocator, source, options); + } +}; + +pub const WithBytesNested = struct { + inner: ?WithBytes = null, + items: std.ArrayList(WithBytes) = .empty, + + pub const _desc_table = .{ + .inner = fd(1, .submessage), + .items = fd(2, .{ .repeated = .submessage }), }; /// Encodes the message to the writer @@ -735,6 +915,17 @@ pub const WithBytes = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -801,6 +992,17 @@ pub const WithRepeatedBytes = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1088,6 +1290,17 @@ pub const ComplexType = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), diff --git a/tests/generated/tests/longs.pb.zig b/tests/generated/tests/longs.pb.zig index 6e826b4..43252bc 100644 --- a/tests/generated/tests/longs.pb.zig +++ b/tests/generated/tests/longs.pb.zig @@ -68,6 +68,17 @@ pub const LongsMessage = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), diff --git a/tests/generated/tests/oneof.pb.zig b/tests/generated/tests/oneof.pb.zig index ebfb3ce..6d39ea3 100644 --- a/tests/generated/tests/oneof.pb.zig +++ b/tests/generated/tests/oneof.pb.zig @@ -59,6 +59,17 @@ pub const Message = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -148,6 +159,17 @@ pub const OneofContainer = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -230,6 +252,17 @@ pub const S3LockResult = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -292,6 +325,17 @@ pub const Success = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -356,6 +400,17 @@ pub const NotOwner = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -424,6 +479,17 @@ pub const Conflict = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), diff --git a/tests/generated/tests/service.pb.zig b/tests/generated/tests/service.pb.zig index 0c744ae..1093155 100644 --- a/tests/generated/tests/service.pb.zig +++ b/tests/generated/tests/service.pb.zig @@ -53,6 +53,17 @@ pub const UnaryRequest = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -122,6 +133,17 @@ pub const UnaryResponse = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -189,6 +211,17 @@ pub const StreamRequest = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -256,6 +289,17 @@ pub const StreamResponse = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), diff --git a/tests/generated/unittest.pb.zig b/tests/generated/unittest.pb.zig index c98758b..69f6c43 100644 --- a/tests/generated/unittest.pb.zig +++ b/tests/generated/unittest.pb.zig @@ -358,6 +358,17 @@ pub const TestAllTypes = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -417,6 +428,17 @@ pub const TestAllTypes = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -492,6 +514,17 @@ pub const NestedTestAllTypes = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -560,6 +593,17 @@ pub const TestDeprecatedFields = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -622,6 +666,17 @@ pub const TestDeprecatedMessage = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -692,6 +747,17 @@ pub const ForeignMessage = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -754,6 +820,17 @@ pub const TestReservedFields = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -816,6 +893,17 @@ pub const TestAllExtensions = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -884,6 +972,17 @@ pub const TestGroup = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -946,6 +1045,17 @@ pub const TestGroupExtension = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1008,6 +1118,17 @@ pub const TestNestedExtension = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1078,6 +1199,17 @@ pub const TestChildExtension = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1166,6 +1298,17 @@ pub const TestChildExtensionData = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1225,6 +1368,17 @@ pub const TestChildExtensionData = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1284,6 +1438,17 @@ pub const TestChildExtensionData = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1352,6 +1517,17 @@ pub const TestNestedChildExtension = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1422,6 +1598,17 @@ pub const TestNestedChildExtensionData = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1559,6 +1746,17 @@ pub const TestRequired = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1631,6 +1829,17 @@ pub const TestRequiredForeign = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1701,6 +1910,17 @@ pub const TestRequiredMessage = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1771,6 +1991,17 @@ pub const TestNestedRequiredForeign = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1838,6 +2069,17 @@ pub const TestForeignNested = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1901,6 +2143,17 @@ pub const TestEmptyMessage = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -1965,6 +2218,17 @@ pub const TestEmptyMessageWithExtensions = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -2042,6 +2306,17 @@ pub const TestPickleNestedMessage = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -2101,6 +2376,17 @@ pub const TestPickleNestedMessage = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -2160,6 +2446,17 @@ pub const TestPickleNestedMessage = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -2222,6 +2519,17 @@ pub const TestMultipleExtensionRanges = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -2291,6 +2599,17 @@ pub const TestReallyLargeTagNumber = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -2359,6 +2678,17 @@ pub const TestRecursiveMessage = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -2437,6 +2767,17 @@ pub const TestMutualRecursionA = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -2496,6 +2837,17 @@ pub const TestMutualRecursionA = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -2564,6 +2916,17 @@ pub const TestMutualRecursionB = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -2637,6 +3000,17 @@ pub const TestIsInitialized = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -2696,6 +3070,17 @@ pub const TestIsInitialized = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -2766,6 +3151,17 @@ pub const TestDupFieldNumber = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -2833,6 +3229,17 @@ pub const TestEagerMessage = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -2899,6 +3306,17 @@ pub const TestLazyMessage = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -2976,6 +3394,17 @@ pub const TestEagerMaybeLazy = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -3035,6 +3464,17 @@ pub const TestEagerMaybeLazy = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -3111,6 +3551,17 @@ pub const TestNestedMessageHasBits = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -3170,6 +3621,17 @@ pub const TestNestedMessageHasBits = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -3260,6 +3722,17 @@ pub const TestCamelCaseFieldNames = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -3343,6 +3816,17 @@ pub const TestFieldOrderings = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -3402,6 +3886,17 @@ pub const TestFieldOrderings = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -3468,6 +3963,17 @@ pub const TestExtensionOrderings1 = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -3541,6 +4047,17 @@ pub const TestExtensionOrderings2 = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -3600,6 +4117,17 @@ pub const TestExtensionOrderings2 = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -3718,6 +4246,17 @@ pub const TestExtremeDefaultValues = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -3784,6 +4323,17 @@ pub const SparseEnumMessage = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -3851,6 +4401,17 @@ pub const OneString = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -3917,6 +4478,17 @@ pub const MoreString = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -3983,6 +4555,17 @@ pub const OneBytes = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -4049,6 +4632,17 @@ pub const MoreBytes = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -4177,6 +4771,17 @@ pub const ManyOptionalString = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -4244,6 +4849,17 @@ pub const Int32Message = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -4310,6 +4926,17 @@ pub const Uint32Message = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -4376,6 +5003,17 @@ pub const Int64Message = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -4442,6 +5080,17 @@ pub const Uint64Message = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -4508,6 +5157,17 @@ pub const BoolMessage = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -4597,6 +5257,17 @@ pub const TestOneof = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -4671,6 +5342,17 @@ pub const TestOneofBackwardsCompatible = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -4833,6 +5515,17 @@ pub const TestOneof2 = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -4892,6 +5585,17 @@ pub const TestOneof2 = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -4981,6 +5685,17 @@ pub const TestRequiredOneof = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -5040,6 +5755,17 @@ pub const TestRequiredOneof = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -5123,13 +5849,24 @@ pub const TestPackedTypes = struct { return protobuf.dupe(@This(), self, allocator); } - /// Decodes the message from the JSON string. - pub fn jsonDecode( + /// Decodes the message from the JSON string. + pub fn jsonDecode( + input: []const u8, + options: std.json.ParseOptions, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decode(@This(), input, options, allocator); + } + + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( input: []const u8, options: std.json.ParseOptions, + pb_options: protobuf.json.Options, allocator: std.mem.Allocator, ) !std.json.Parsed(@This()) { - return protobuf.json.decode(@This(), input, options, allocator); + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); } /// Encodes the message to a JSON string. @@ -5226,6 +5963,17 @@ pub const TestUnpackedTypes = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -5288,6 +6036,17 @@ pub const TestPackedExtensions = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -5350,6 +6109,17 @@ pub const TestUnpackedExtensions = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -5445,6 +6215,17 @@ pub const TestDynamicExtensions = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -5504,6 +6285,17 @@ pub const TestDynamicExtensions = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -5580,6 +6372,17 @@ pub const TestRepeatedScalarDifferentTagSizes = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -5680,6 +6483,17 @@ pub const TestParsingMerge = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -5739,6 +6553,17 @@ pub const TestParsingMerge = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -5807,6 +6632,17 @@ pub const TestMergeException = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -5873,6 +6709,17 @@ pub const TestCommentInjectionMessage = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -5951,6 +6798,17 @@ pub const TestMessageSize = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -6014,6 +6872,17 @@ pub const FooRequest = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -6076,6 +6945,17 @@ pub const FooResponse = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -6138,6 +7018,17 @@ pub const FooClientMessage = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -6200,6 +7091,17 @@ pub const FooServerMessage = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -6262,6 +7164,17 @@ pub const BarRequest = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -6324,6 +7237,17 @@ pub const BarResponse = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -6402,6 +7326,17 @@ pub const TestJsonName = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -6516,6 +7451,17 @@ pub const TestHugeFieldNumbers = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -6575,6 +7521,17 @@ pub const TestHugeFieldNumbers = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -6657,6 +7614,17 @@ pub const TestExtensionInsideTable = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -6723,6 +7691,17 @@ pub const TestNestedGroupExtensionInnerExtension = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -6795,6 +7774,17 @@ pub const TestExtensionRangeSerialize = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -6867,6 +7857,17 @@ pub const TestVerifyInt32Simple = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -6943,6 +7944,17 @@ pub const TestVerifyInt32 = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -7025,6 +8037,17 @@ pub const TestVerifyMostlyInt32 = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -7109,6 +8132,17 @@ pub const TestVerifyMostlyInt32BigFieldNumber = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -7181,6 +8215,17 @@ pub const TestVerifyUint32Simple = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -7257,6 +8302,17 @@ pub const TestVerifyUint32 = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -7333,6 +8389,17 @@ pub const TestVerifyOneUint32 = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -7411,6 +8478,17 @@ pub const TestVerifyOneInt32BigFieldNumber = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -7491,6 +8569,17 @@ pub const TestVerifyInt32BigFieldNumber = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -7571,6 +8660,17 @@ pub const TestVerifyUint32BigFieldNumber = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -7662,6 +8762,17 @@ pub const TestVerifyBigFieldNumberUint32 = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -7721,6 +8832,17 @@ pub const TestVerifyBigFieldNumberUint32 = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -7924,6 +9046,17 @@ pub const EnumParseTester = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), diff --git a/tests/generated/vector_tile.pb.zig b/tests/generated/vector_tile.pb.zig index 08dcef6..7c226a3 100644 --- a/tests/generated/vector_tile.pb.zig +++ b/tests/generated/vector_tile.pb.zig @@ -77,6 +77,17 @@ pub const Tile = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -149,6 +160,17 @@ pub const Tile = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -225,6 +247,17 @@ pub const Tile = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), @@ -284,6 +317,17 @@ pub const Tile = struct { return protobuf.json.decode(@This(), input, options, allocator); } + /// Decodes the message from the JSON string, honoring pb options + /// (e.g. hex_bytes_fields for OTLP trace_id/span_id). + pub fn jsonDecodeOpts( + input: []const u8, + options: std.json.ParseOptions, + pb_options: protobuf.json.Options, + allocator: std.mem.Allocator, + ) !std.json.Parsed(@This()) { + return protobuf.json.decodeOpts(@This(), input, options, pb_options, allocator); + } + /// Encodes the message to a JSON string. pub fn jsonEncode( self: @This(), diff --git a/tests/protos_for_test/all.proto b/tests/protos_for_test/all.proto index 8d834f6..f61c9c4 100644 --- a/tests/protos_for_test/all.proto +++ b/tests/protos_for_test/all.proto @@ -88,6 +88,12 @@ message WithRepeatedStrings { message WithBytes { bytes byte_field = 1; + bytes hex_field = 2; +} + +message WithBytesNested { + WithBytes inner = 1; + repeated WithBytes items = 2; } message WithRepeatedBytes { diff --git a/tests/tests_json.zig b/tests/tests_json.zig index c566104..beecfb2 100644 --- a/tests/tests_json.zig +++ b/tests/tests_json.zig @@ -728,6 +728,126 @@ test "JSON: decode Bytes (from snake_case)" { try expect(compare_pb_structs(pb_instance, decoded.value)); } +// -------------- +// per-field hex bytes test (Options.hex_bytes_fields) +// -------------- +const WithBytes = @import("./generated/tests.pb.zig").WithBytes; +const WithBytesNested = @import("./generated/tests.pb.zig").WithBytesNested; + +test "JSON: hex field and base64 field coexist in one message (with options)" { + // hex_field is named in hex_bytes_fields; byte_field is a normal base64 bytes + // field. Both must round-trip in the same message — the case that fails under a + // global toggle. In memory both hold raw bytes. + const hex_opts: protobuf.json.Options = .{ .hex_bytes_fields = &.{"hex_field"} }; + + var pb_instance = WithBytes{ + .hex_field = try allocator.dupe(u8, &.{ 0xca, 0xfe, 0xca, 0xfe }), + .byte_field = try allocator.dupe(u8, &.{ 1, 2, 3, 4 }), + }; + defer pb_instance.deinit(allocator); + + // hex_field -> lowercase hex; byte_field -> base64. + const encoded = try pb_instance.jsonEncode(.{}, hex_opts, allocator); + defer allocator.free(encoded); + try expectEqualSlices(u8, "{\"byteField\":\"AQIDBA==\",\"hexField\":\"cafecafe\"}", encoded); + + const decoded = try WithBytes.jsonDecodeOpts(encoded, .{}, hex_opts, allocator); + defer decoded.deinit(); + try expectEqualSlices(u8, &.{ 0xca, 0xfe, 0xca, 0xfe }, decoded.value.hex_field); + try expectEqualSlices(u8, &.{ 1, 2, 3, 4 }, decoded.value.byte_field); +} + +test "JSON: without hex options every bytes field is base64" { + // No hex_bytes_fields -> both fields base64, on both the plain and the *Opts paths. + var pb_instance = WithBytes{ + .hex_field = try allocator.dupe(u8, &.{ 0xca, 0xfe, 0xca, 0xfe }), + .byte_field = try allocator.dupe(u8, &.{ 1, 2, 3, 4 }), + }; + defer pb_instance.deinit(allocator); + + // jsonEncode with empty pb options: hex_field is base64, not hex. + const encoded = try pb_instance.jsonEncode(.{}, .{}, allocator); + defer allocator.free(encoded); + try expectEqualSlices(u8, "{\"byteField\":\"AQIDBA==\",\"hexField\":\"yv7K/g==\"}", encoded); + + // Plain jsonDecode (no options) reads both as base64. + const decoded = try WithBytes.jsonDecode(encoded, .{}, allocator); + defer decoded.deinit(); + try expectEqualSlices(u8, &.{ 0xca, 0xfe, 0xca, 0xfe }, decoded.value.hex_field); + try expectEqualSlices(u8, &.{ 1, 2, 3, 4 }, decoded.value.byte_field); + + // jsonDecodeOpts with empty options behaves identically to jsonDecode. + const decoded_opts = try WithBytes.jsonDecodeOpts(encoded, .{}, .{}, allocator); + defer decoded_opts.deinit(); + try expectEqualSlices(u8, &.{ 0xca, 0xfe, 0xca, 0xfe }, decoded_opts.value.hex_field); +} + +test "JSON: hex options thread through nested and repeated messages" { + // The reason the global thread-local was removed: hex selection must reach + // bytes fields at any depth (e.g. OTLP trace_id on a Span deep in the tree). + const hex_opts: protobuf.json.Options = .{ .hex_bytes_fields = &.{"hex_field"} }; + + const item0 = WithBytes{ .hex_field = try allocator.dupe(u8, &.{ 0xaa, 0xbb }) }; + const inner = WithBytes{ .hex_field = try allocator.dupe(u8, &.{ 0xca, 0xfe }) }; + var items: std.ArrayList(WithBytes) = .empty; + try items.append(allocator, item0); + var pb_instance = WithBytesNested{ .inner = inner, .items = items }; + defer pb_instance.deinit(allocator); + + const encoded = try pb_instance.jsonEncode(.{}, hex_opts, allocator); + defer allocator.free(encoded); + try expectEqualSlices(u8, "{\"inner\":{\"hexField\":\"cafe\"},\"items\":[{\"hexField\":\"aabb\"}]}", encoded); + + const decoded = try WithBytesNested.jsonDecodeOpts(encoded, .{}, hex_opts, allocator); + defer decoded.deinit(); + try expectEqualSlices(u8, &.{ 0xca, 0xfe }, decoded.value.inner.?.hex_field); + try expectEqualSlices(u8, &.{ 0xaa, 0xbb }, decoded.value.items.items[0].hex_field); +} + +test "bytes round-trip identically through protobuf binary and JSON-hex" { + // The canonical-representation guarantee: in memory a bytes field is always raw + // bytes, whether it arrived via the binary wire format or via hex JSON. + const hex_opts: protobuf.json.Options = .{ .hex_bytes_fields = &.{"hex_field"} }; + const raw_hex = [_]u8{ 0xde, 0xad, 0xbe, 0xef }; + const raw_b64 = [_]u8{ 1, 2, 3, 4 }; + + var original = WithBytes{ + .hex_field = try allocator.dupe(u8, &raw_hex), + .byte_field = try allocator.dupe(u8, &raw_b64), + }; + defer original.deinit(allocator); + + // protobuf binary round-trip (hex is JSON-only, so binary is unaffected). + var w: std.Io.Writer.Allocating = .init(allocator); + defer w.deinit(); + try original.encode(&w.writer, allocator); + var reader: std.Io.Reader = .fixed(w.written()); + var from_binary = try WithBytes.decode(&reader, allocator); + defer from_binary.deinit(allocator); + + // JSON-hex round-trip. + const j = try original.jsonEncode(.{}, hex_opts, allocator); + defer allocator.free(j); + const from_json = try WithBytes.jsonDecodeOpts(j, .{}, hex_opts, allocator); + defer from_json.deinit(); + + // Both formats reconstruct the exact same raw bytes as the original. + try expectEqualSlices(u8, &raw_hex, from_binary.hex_field); + try expectEqualSlices(u8, &raw_hex, from_json.value.hex_field); + try expectEqualSlices(u8, &raw_b64, from_binary.byte_field); + try expectEqualSlices(u8, &raw_b64, from_json.value.byte_field); +} + +test "JSON: decode rejects invalid hex in a hex_bytes field" { + const hex_opts: protobuf.json.Options = .{ .hex_bytes_fields = &.{"hex_field"} }; + try std.testing.expectError(error.UnexpectedToken, WithBytes.jsonDecodeOpts( + "{\"hexField\":\"zz\"}", + .{}, + hex_opts, + allocator, + )); +} + // -------------- // MoreBytes test // -------------- @@ -987,6 +1107,7 @@ const test_packed_types_init = @import( const test_packed_types_camel_case_json = @embedFile( "./json_data/test_packed_types/camelCase.json", ); +const unittest = @import("./generated/unittest.pb.zig"); test "JSON: encode TestPackedTypes (repeated NaNs/infs)" { var pb_instance = try test_packed_types_init(allocator); @@ -1016,6 +1137,19 @@ test "JSON: decode TestPackedTypes (repeated NaNs/infs)" { try expect(compare_pb_structs(pb_instance, decoded.value)); } +test "JSON: decode TestAllTypes optional floats" { + const decoded = try unittest.TestAllTypes.jsonDecode( + \\{"optionalFloat":1.5,"optionalDouble":2.5} + , + .{}, + allocator, + ); + defer decoded.deinit(); + + try std.testing.expectEqual(@as(f32, 1.5), decoded.value.optional_float.?); + try std.testing.expectEqual(@as(f64, 2.5), decoded.value.optional_double.?); +} + test "JSON: decode selfref structs" { // TODO }