Current section
Files
Jump to
Current section
Files
lib/pg_query/proto/pg_query_a__const.ex
# Code generated by protox. Don't edit.
# credo:disable-for-this-file
defmodule PgQuery.A_Const 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: integer(),
isnull: boolean(),
val:
{:ival, PgQuery.Integer.t()}
| {:fval, PgQuery.Float.t()}
| {:boolval, PgQuery.Boolean.t()}
| {:sval, PgQuery.String.t()}
| {:bsval, PgQuery.BitString.t()}
| nil,
__uf__: [{non_neg_integer(), Protox.Types.tag(), binary()}]
}
defstruct location: 0, isnull: false, val: 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_val(msg)
|> encode_location(msg)
|> encode_isnull(msg)
|> encode_unknown_fields(msg)
end
)
defp encode_val({acc, acc_size}, msg) do
case msg.val do
nil ->
{acc, acc_size}
{:bsval, child_field_value} ->
{value_bytes, value_bytes_size} = Protox.Encode.encode_message(child_field_value)
{["*", value_bytes | acc], acc_size + 1 + value_bytes_size}
{:sval, child_field_value} ->
{value_bytes, value_bytes_size} = Protox.Encode.encode_message(child_field_value)
{["\"", value_bytes | acc], acc_size + 1 + value_bytes_size}
{:boolval, 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}
{:fval, child_field_value} ->
{value_bytes, value_bytes_size} = Protox.Encode.encode_message(child_field_value)
{["\x12", value_bytes | acc], acc_size + 1 + value_bytes_size}
{:ival, child_field_value} ->
{value_bytes, value_bytes_size} = Protox.Encode.encode_message(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 == 0 do
{acc, acc_size}
else
{value_bytes, value_bytes_size} = Protox.Encode.encode_int32(msg.location)
{["X", value_bytes | acc], acc_size + 1 + value_bytes_size}
end
rescue
ArgumentError ->
reraise Protox.EncodingError.new(:location, "invalid field value"), __STACKTRACE__
end
defp encode_isnull({acc, acc_size}, msg) do
if msg.isnull == false do
{acc, acc_size}
else
{value_bytes, value_bytes_size} = Protox.Encode.encode_bool(msg.isnull)
{["P", value_bytes | acc], acc_size + 1 + value_bytes_size}
end
rescue
ArgumentError ->
reraise Protox.EncodingError.new(:isnull, "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(PgQuery.A_Const))
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{}
<<11::5, _wire_type::3, bytes::binary>> ->
{value, rest} = Protox.Decode.parse_int32(bytes)
{[location: value], rest}
<<10::5, _wire_type::3, bytes::binary>> ->
{value, rest} = Protox.Decode.parse_bool(bytes)
{[isnull: value], rest}
<<5::5, _wire_type::3, bytes::binary>> ->
{len, bytes} = Protox.Varint.decode(bytes)
{delimited, rest} = Protox.Decode.parse_delimited(bytes, len)
{[
case msg.val do
{:bsval, previous_value} ->
{:val,
{:bsval,
Protox.MergeMessage.merge(
previous_value,
PgQuery.BitString.decode!(delimited)
)}}
_ ->
{:val, {:bsval, PgQuery.BitString.decode!(delimited)}}
end
], rest}
<<4::5, _wire_type::3, bytes::binary>> ->
{len, bytes} = Protox.Varint.decode(bytes)
{delimited, rest} = Protox.Decode.parse_delimited(bytes, len)
{[
case msg.val do
{:sval, previous_value} ->
{:val,
{:sval,
Protox.MergeMessage.merge(
previous_value,
PgQuery.String.decode!(delimited)
)}}
_ ->
{:val, {:sval, PgQuery.String.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.val do
{:boolval, previous_value} ->
{:val,
{:boolval,
Protox.MergeMessage.merge(
previous_value,
PgQuery.Boolean.decode!(delimited)
)}}
_ ->
{:val, {:boolval, PgQuery.Boolean.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)
{[
case msg.val do
{:fval, previous_value} ->
{:val,
{:fval,
Protox.MergeMessage.merge(previous_value, PgQuery.Float.decode!(delimited))}}
_ ->
{:val, {:fval, PgQuery.Float.decode!(delimited)}}
end
], rest}
<<1::5, _wire_type::3, bytes::binary>> ->
{len, bytes} = Protox.Varint.decode(bytes)
{delimited, rest} = Protox.Decode.parse_delimited(bytes, len)
{[
case msg.val do
{:ival, previous_value} ->
{:val,
{:ival,
Protox.MergeMessage.merge(
previous_value,
PgQuery.Integer.decode!(delimited)
)}}
_ ->
{:val, {:ival, PgQuery.Integer.decode!(delimited)}}
end
], 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(:location) do
{:ok, 0}
end
def default(:isnull) do
{:ok, false}
end
def default(:bsval) do
{:error, :no_default_value}
end
def default(:sval) do
{:error, :no_default_value}
end
def default(:boolval) do
{:error, :no_default_value}
end
def default(:fval) do
{:error, :no_default_value}
end
def default(:ival) 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: %{
boolval: %{
__struct__: Protox.Field,
extender: nil,
kind: %{__struct__: Protox.OneOf, parent: :val},
label: :optional,
name: :boolval,
tag: 3,
type: {:message, PgQuery.Boolean}
},
bsval: %{
__struct__: Protox.Field,
extender: nil,
kind: %{__struct__: Protox.OneOf, parent: :val},
label: :optional,
name: :bsval,
tag: 5,
type: {:message, PgQuery.BitString}
},
fval: %{
__struct__: Protox.Field,
extender: nil,
kind: %{__struct__: Protox.OneOf, parent: :val},
label: :optional,
name: :fval,
tag: 2,
type: {:message, PgQuery.Float}
},
isnull: %{
__struct__: Protox.Field,
extender: nil,
kind: %{__struct__: Protox.Scalar, default_value: false},
label: :optional,
name: :isnull,
tag: 10,
type: :bool
},
ival: %{
__struct__: Protox.Field,
extender: nil,
kind: %{__struct__: Protox.OneOf, parent: :val},
label: :optional,
name: :ival,
tag: 1,
type: {:message, PgQuery.Integer}
},
location: %{
__struct__: Protox.Field,
extender: nil,
kind: %{__struct__: Protox.Scalar, default_value: 0},
label: :optional,
name: :location,
tag: 11,
type: :int32
},
sval: %{
__struct__: Protox.Field,
extender: nil,
kind: %{__struct__: Protox.OneOf, parent: :val},
label: :optional,
name: :sval,
tag: 4,
type: {:message, PgQuery.String}
}
},
file_options: nil,
name: PgQuery.A_Const,
syntax: :proto3
}
end
end