Current section

Files

Jump to
cucumber_messages lib cucumber_messages generated cucumber_messages_source_reference.ex
Raw

lib/cucumber_messages/generated/cucumber_messages_source_reference.ex

# Code generated by protox. Don't edit.
# credo:disable-for-this-file
defmodule CucumberMessages.SourceReference do
@moduledoc false
if function_exported?(Protox, :check_generator_version, 1) do
Protox.check_generator_version(1)
else
raise "This code was generated with protox 2 but the runtime is using an older version of protox."
end
@type t :: %__MODULE__{
location: CucumberMessages.Location.t() | nil,
reference:
{:uri, String.t()}
| {:java_method, CucumberMessages.SourceReference.JavaMethod.t()}
| {:java_stack_trace_element,
CucumberMessages.SourceReference.JavaStackTraceElement.t()}
| nil,
__uf__: [{non_neg_integer(), Protox.Types.tag(), binary()}]
}
defstruct reference: nil, location: nil, __uf__: []
(
(
@spec encode(t()) :: {:ok, iodata(), non_neg_integer()} | {:error, any()}
def encode(msg) do
msg |> encode!() |> Tuple.insert_at(0, :ok)
rescue
e in [Protox.EncodingError, Protox.RequiredFieldsError] -> {:error, e}
end
@spec encode!(t()) :: {iodata(), non_neg_integer()} | no_return()
def encode!(msg) do
{_acc = [], _acc_size = 0}
|> encode_reference(msg)
|> encode_location(msg)
|> encode_unknown_fields(msg)
end
)
defp encode_reference({acc, acc_size}, msg) do
case msg.reference do
nil ->
{acc, acc_size}
{:java_stack_trace_element, child_field_value} ->
{value_bytes, value_bytes_size} = Protox.Encode.encode_message(child_field_value)
{["\"", value_bytes | acc], acc_size + 1 + value_bytes_size}
{:java_method, child_field_value} ->
{value_bytes, value_bytes_size} = Protox.Encode.encode_message(child_field_value)
{["\x1A", value_bytes | acc], acc_size + 1 + value_bytes_size}
{:uri, child_field_value} ->
{value_bytes, value_bytes_size} = Protox.Encode.encode_string(child_field_value)
{["\n", value_bytes | acc], acc_size + 1 + value_bytes_size}
end
end
defp encode_location({acc, acc_size}, msg) do
if msg.location == nil do
{acc, acc_size}
else
{value_bytes, value_bytes_size} = Protox.Encode.encode_message(msg.location)
{["\x12", value_bytes | acc], acc_size + 1 + value_bytes_size}
end
rescue
ArgumentError ->
reraise Protox.EncodingError.new(:location, "invalid field value"), __STACKTRACE__
end
defp encode_unknown_fields({acc, acc_size}, msg) do
Enum.reduce(msg.__uf__, {acc, acc_size}, fn {tag, wire_type, bytes}, {acc, acc_size} ->
case wire_type do
0 ->
{key_bytes, key_size} = Protox.Encode.make_key_bytes(tag, :int32)
{[acc, <<key_bytes::binary, bytes::binary>>], acc_size + key_size + byte_size(bytes)}
1 ->
{key_bytes, key_size} = Protox.Encode.make_key_bytes(tag, :double)
{[acc, <<key_bytes::binary, bytes::binary>>], acc_size + key_size + byte_size(bytes)}
2 ->
{len_bytes, len_size} = bytes |> byte_size() |> Protox.Varint.encode()
{key_bytes, key_size} = Protox.Encode.make_key_bytes(tag, :packed)
{[acc, <<key_bytes::binary, len_bytes::binary, bytes::binary>>],
acc_size + key_size + len_size + byte_size(bytes)}
5 ->
{key_bytes, key_size} = Protox.Encode.make_key_bytes(tag, :float)
{[acc, <<key_bytes::binary, bytes::binary>>], acc_size + key_size + byte_size(bytes)}
end
end)
end
)
(
(
@spec decode(binary()) :: {:ok, t()} | {:error, any()}
def decode(bytes) do
{:ok, decode!(bytes)}
rescue
e in [Protox.DecodingError, Protox.IllegalTagError, Protox.RequiredFieldsError] ->
{:error, e}
end
(
@spec decode!(binary()) :: t() | no_return()
def decode!(bytes) do
parse_key_value(bytes, struct(CucumberMessages.SourceReference))
end
)
)
(
@spec parse_key_value(binary(), struct()) :: struct()
defp parse_key_value(<<>>, msg) do
msg
end
defp parse_key_value(bytes, msg) do
{field, rest} =
case bytes do
<<_::5, 3::3, _rest::binary>> ->
raise Protox.DecodingError.new(bytes, "invalid wire type 3")
<<_::5, 4::3, _rest::binary>> ->
raise Protox.DecodingError.new(bytes, "invalid wire type 4")
<<_::5, 6::3, _rest::binary>> ->
raise Protox.DecodingError.new(bytes, "invalid wire type 6")
<<_::5, 7::3, _rest::binary>> ->
raise Protox.DecodingError.new(bytes, "invalid wire type 7")
<<0::5, _::3, _rest::binary>> ->
raise %Protox.IllegalTagError{}
<<4::5, _wire_type::3, bytes::binary>> ->
{len, bytes} = Protox.Varint.decode(bytes)
{delimited, rest} = Protox.Decode.parse_delimited(bytes, len)
{[
case msg.reference do
{:java_stack_trace_element, previous_value} ->
{:reference,
{:java_stack_trace_element,
Protox.MergeMessage.merge(
previous_value,
CucumberMessages.SourceReference.JavaStackTraceElement.decode!(delimited)
)}}
_ ->
{:reference,
{:java_stack_trace_element,
CucumberMessages.SourceReference.JavaStackTraceElement.decode!(delimited)}}
end
], rest}
<<3::5, _wire_type::3, bytes::binary>> ->
{len, bytes} = Protox.Varint.decode(bytes)
{delimited, rest} = Protox.Decode.parse_delimited(bytes, len)
{[
case msg.reference do
{:java_method, previous_value} ->
{:reference,
{:java_method,
Protox.MergeMessage.merge(
previous_value,
CucumberMessages.SourceReference.JavaMethod.decode!(delimited)
)}}
_ ->
{:reference,
{:java_method,
CucumberMessages.SourceReference.JavaMethod.decode!(delimited)}}
end
], rest}
<<2::5, _wire_type::3, bytes::binary>> ->
{len, bytes} = Protox.Varint.decode(bytes)
{delimited, rest} = Protox.Decode.parse_delimited(bytes, len)
{[
location:
Protox.MergeMessage.merge(
msg.location,
CucumberMessages.Location.decode!(delimited)
)
], rest}
<<1::5, _wire_type::3, bytes::binary>> ->
{len, bytes} = Protox.Varint.decode(bytes)
{delimited, rest} = Protox.Decode.parse_delimited(bytes, len)
{[reference: {:uri, Protox.Decode.validate_string!(delimited)}], rest}
<<bytes::binary>> ->
{tag, wire_type, rest} = Protox.Decode.parse_key(bytes)
{value, rest} = Protox.Decode.parse_unknown(tag, wire_type, rest)
{[__uf__: msg.__uf__ ++ [value]], rest}
end
msg_updated = struct(msg, field)
parse_key_value(rest, msg_updated)
end
)
)
(
@spec unknown_fields(struct()) :: [{non_neg_integer(), Protox.Types.tag(), binary()}]
def unknown_fields(msg) do
msg.__uf__
end
@spec unknown_fields_name() :: :__uf__
def unknown_fields_name() do
:__uf__
end
@spec clear_unknown_fields(struct) :: struct
def clear_unknown_fields(msg) do
struct!(msg, __uf__: [])
end
)
(
@spec default(atom()) ::
{:ok, boolean() | integer() | String.t() | float()}
| {:error, :no_such_field | :no_default_value}
def default(:java_stack_trace_element) do
{:error, :no_default_value}
end
def default(:java_method) do
{:error, :no_default_value}
end
def default(:location) do
{:ok, nil}
end
def default(:uri) do
{:error, :no_default_value}
end
def default(_) do
{:error, :no_such_field}
end
)
@spec schema() :: Protox.MessageSchema.t()
def schema() do
%{
__struct__: Protox.MessageSchema,
fields: %{
java_method: %{
__struct__: Protox.Field,
kind: %{__struct__: Protox.OneOf, parent: :reference},
label: :optional,
name: :java_method,
tag: 3,
type: {:message, CucumberMessages.SourceReference.JavaMethod}
},
java_stack_trace_element: %{
__struct__: Protox.Field,
kind: %{__struct__: Protox.OneOf, parent: :reference},
label: :optional,
name: :java_stack_trace_element,
tag: 4,
type: {:message, CucumberMessages.SourceReference.JavaStackTraceElement}
},
location: %{
__struct__: Protox.Field,
kind: %{__struct__: Protox.Scalar, default_value: nil},
label: :optional,
name: :location,
tag: 2,
type: {:message, CucumberMessages.Location}
},
uri: %{
__struct__: Protox.Field,
kind: %{__struct__: Protox.OneOf, parent: :reference},
label: :optional,
name: :uri,
tag: 1,
type: :string
}
},
file_options: %{
__struct__: Protox.Google.Protobuf.FileOptions,
__uf__: [],
cc_enable_arenas: nil,
cc_generic_services: nil,
csharp_namespace: nil,
deprecated: nil,
go_package: "messages",
java_generate_equals_and_hash: nil,
java_generic_services: nil,
java_multiple_files: nil,
java_outer_classname: nil,
java_package: nil,
java_string_check_utf8: nil,
objc_class_prefix: nil,
optimize_for: nil,
php_class_prefix: nil,
php_generic_services: nil,
php_metadata_namespace: nil,
php_namespace: nil,
py_generic_services: nil,
ruby_package: nil,
swift_prefix: nil,
uninterpreted_option: []
},
name: CucumberMessages.SourceReference,
syntax: :proto3
}
end
end