Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync proto files from go-sdk v1.7.7 #2

Merged
merged 1 commit into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
2, Use [protox](https://hex.pm/packages/protox) as the Elixir protobuf library (`protox` requires `~> 1.2.4`), to generate the
modules from `protos/*.proto` files, in the root directory of this repo run the corresponding command as below:

```
mix protox.generate --keep-unknown-fields=false --multiple-files --output-path=lib --include-path=. protos/*.proto
```shell
mix protox.generate --namespace=ExAliyunOts --keep-unknown-fields=false --multiple-files --output-path=lib --include-path=protos protos/*.proto
```

3, The generated `lib/*.ex` files will be used by [Alibaba TableStore Elixir SDK](https://hex.pm/packages/ex_aliyun_ots) as a dependence.
94 changes: 45 additions & 49 deletions lib/elixir_ex_aliyun_ots_table_store_abort_transaction_request.ex
Original file line number Diff line number Diff line change
@@ -1,44 +1,38 @@
# credo:disable-for-this-file
defmodule(ExAliyunOts.TableStore.AbortTransactionRequest) do
defmodule ExAliyunOts.TableStore.AbortTransactionRequest do
@moduledoc false
defstruct(transaction_id: nil)
defstruct transaction_id: nil

(
(
@spec encode(struct) :: {:ok, iodata} | {:error, any}
def(encode(msg)) do
def encode(msg) do
try do
{:ok, encode!(msg)}
rescue
e in [Protox.EncodingError, Protox.RequiredFieldsError] ->
{:error, e}
e in [Protox.EncodingError, Protox.RequiredFieldsError] -> {:error, e}
end
end

@spec encode!(struct) :: iodata | no_return
def(encode!(msg)) do
def encode!(msg) do
[] |> encode_transaction_id(msg)
end
)

[]

[
defp(encode_transaction_id(acc, msg)) do
defp encode_transaction_id(acc, msg) do
try do
case(msg.transaction_id) do
nil ->
raise(Protox.RequiredFieldsError.new([:transaction_id]))

_ ->
[acc, "\n", Protox.Encode.encode_string(msg.transaction_id)]
case msg.transaction_id do
nil -> raise Protox.RequiredFieldsError.new([:transaction_id])
_ -> [acc, "\n", Protox.Encode.encode_string(msg.transaction_id)]
end
rescue
ArgumentError ->
reraise(
Protox.EncodingError.new(:transaction_id, "invalid field value"),
__STACKTRACE__
)
reraise Protox.EncodingError.new(:transaction_id, "invalid field value"),
__STACKTRACE__
end
end
]
Expand All @@ -49,7 +43,7 @@ defmodule(ExAliyunOts.TableStore.AbortTransactionRequest) do
(
(
@spec decode(binary) :: {:ok, struct} | {:error, any}
def(decode(bytes)) do
def decode(bytes) do
try do
{:ok, decode!(bytes)}
rescue
Expand All @@ -60,32 +54,29 @@ defmodule(ExAliyunOts.TableStore.AbortTransactionRequest) do

(
@spec decode!(binary) :: struct | no_return
def(decode!(bytes)) do
def decode!(bytes) do
{msg, set_fields} =
parse_key_value([], bytes, struct(ExAliyunOts.TableStore.AbortTransactionRequest))

case([:transaction_id] -- set_fields) do
[] ->
msg

missing_fields ->
raise(Protox.RequiredFieldsError.new(missing_fields))
case [:transaction_id] -- set_fields do
[] -> msg
missing_fields -> raise Protox.RequiredFieldsError.new(missing_fields)
end
end
)
)

(
@spec parse_key_value([atom], binary, struct) :: {struct, [atom]}
defp(parse_key_value(set_fields, <<>>, msg)) do
defp parse_key_value(set_fields, <<>>, msg) do
{msg, set_fields}
end

defp(parse_key_value(set_fields, bytes, msg)) do
defp parse_key_value(set_fields, bytes, msg) do
{new_set_fields, field, rest} =
case(Protox.Decode.parse_key(bytes)) do
case Protox.Decode.parse_key(bytes) do
{0, _, _} ->
raise(%Protox.IllegalTagError{})
raise %Protox.IllegalTagError{}

{1, _, bytes} ->
{len, bytes} = Protox.Varint.decode(bytes)
Expand All @@ -107,17 +98,16 @@ defmodule(ExAliyunOts.TableStore.AbortTransactionRequest) do

(
@spec json_decode(iodata(), keyword()) :: {:ok, struct()} | {:error, any()}
def(json_decode(input, opts \\ [])) do
def json_decode(input, opts \\ []) do
try do
{:ok, json_decode!(input, opts)}
rescue
e in Protox.JsonDecodingError ->
{:error, e}
e in Protox.JsonDecodingError -> {:error, e}
end
end

@spec json_decode!(iodata(), keyword()) :: struct() | no_return()
def(json_decode!(input, opts \\ [])) do
def json_decode!(input, opts \\ []) do
{json_library_wrapper, json_library} = Protox.JsonLibrary.get_library(opts, :decode)

Protox.JsonDecode.decode!(
Expand All @@ -128,17 +118,16 @@ defmodule(ExAliyunOts.TableStore.AbortTransactionRequest) do
end

@spec json_encode(struct(), keyword()) :: {:ok, iodata()} | {:error, any()}
def(json_encode(msg, opts \\ [])) do
def json_encode(msg, opts \\ []) do
try do
{:ok, json_encode!(msg, opts)}
rescue
e in Protox.JsonEncodingError ->
{:error, e}
e in Protox.JsonEncodingError -> {:error, e}
end
end

@spec json_encode!(struct(), keyword()) :: iodata() | no_return()
def(json_encode!(msg, opts \\ [])) do
def json_encode!(msg, opts \\ []) do
{json_library_wrapper, json_library} = Protox.JsonLibrary.get_library(opts, :encode)
Protox.JsonEncode.encode!(msg, &json_library_wrapper.encode!(json_library, &1))
end
Expand All @@ -149,22 +138,22 @@ defmodule(ExAliyunOts.TableStore.AbortTransactionRequest) do
@spec defs() :: %{
required(non_neg_integer) => {atom, Protox.Types.kind(), Protox.Types.type()}
}
def(defs()) do
def defs() do
%{1 => {:transaction_id, {:scalar, ""}, :string}}
end

@deprecated "Use fields_defs()/0 instead"
@spec defs_by_name() :: %{
required(atom) => {non_neg_integer, Protox.Types.kind(), Protox.Types.type()}
}
def(defs_by_name()) do
def defs_by_name() do
%{transaction_id: {1, {:scalar, ""}, :string}}
end
)

(
@spec fields_defs() :: list(Protox.Field.t())
def(fields_defs()) do
def fields_defs() do
[
%{
__struct__: Protox.Field,
Expand All @@ -181,7 +170,7 @@ defmodule(ExAliyunOts.TableStore.AbortTransactionRequest) do
[
@spec(field_def(atom) :: {:ok, Protox.Field.t()} | {:error, :no_such_field}),
(
def(field_def(:transaction_id)) do
def field_def(:transaction_id) do
{:ok,
%{
__struct__: Protox.Field,
Expand All @@ -194,7 +183,7 @@ defmodule(ExAliyunOts.TableStore.AbortTransactionRequest) do
}}
end

def(field_def("transactionId")) do
def field_def("transactionId") do
{:ok,
%{
__struct__: Protox.Field,
Expand All @@ -207,7 +196,7 @@ defmodule(ExAliyunOts.TableStore.AbortTransactionRequest) do
}}
end

def(field_def("transaction_id")) do
def field_def("transaction_id") do
{:ok,
%{
__struct__: Protox.Field,
Expand All @@ -220,7 +209,7 @@ defmodule(ExAliyunOts.TableStore.AbortTransactionRequest) do
}}
end
),
def(field_def(_)) do
def field_def(_) do
{:error, :no_such_field}
end
]
Expand All @@ -230,25 +219,32 @@ defmodule(ExAliyunOts.TableStore.AbortTransactionRequest) do

(
@spec required_fields() :: [:transaction_id]
def(required_fields()) do
def required_fields() do
[:transaction_id]
end
)

(
@spec syntax() :: atom()
def(syntax()) do
def syntax() do
:proto2
end
)

[
@spec(default(atom) :: {:ok, boolean | integer | String.t() | float} | {:error, atom}),
def(default(:transaction_id)) do
def default(:transaction_id) do
{:ok, ""}
end,
def(default(_)) do
def default(_) do
{:error, :no_such_field}
end
]
end

(
@spec file_options() :: nil
def file_options() do
nil
end
)
end
Loading