Packages
protox
0.8.0
2.0.9
2.0.8
2.0.7
2.0.6
2.0.5
2.0.4
2.0.3
2.0.2
2.0.1
2.0.0
2.0.0-dev
1.7.8
1.7.7
1.7.6
1.7.5
1.7.4
retired
1.7.3
1.7.2
1.7.1
1.7.0
1.6.10
1.6.9
1.6.8
1.6.7
1.6.6
1.6.5
1.6.4
1.6.3
1.6.2
1.6.1
1.6.0
1.5.1
1.5.0
1.4.0
1.3.2
1.3.1
1.3.0
1.2.4
1.2.3
1.2.2
1.2.1
1.2.0
1.1.1
1.1.0
1.0.0
0.25.0
0.24.0
0.23.1
0.23.0
0.22.0
0.21.0
0.20.0
0.19.1
0.19.0
0.18.0
0.17.0
0.16.2
0.16.1
0.16.0
0.15.2
0.15.1
0.15.0
0.14.0
0.13.0
0.12.1
0.12.0
0.11.1
0.11.0
0.10.0
0.9.1
0.9.0
0.8.0
0.7.1
0.7.0
A fast, easy to use and 100% conformant Elixir library for Google Protocol Buffers (aka protobuf)
Current section
Files
Jump to
Current section
Files
lib/protox/escript/conformance.ex
defmodule Protox.Escript.Conformance do
@moduledoc false
def run() do
:io.setopts(:standard_io, encoding: :latin1)
"./conformance_report.txt"
|> File.open!([:write])
|> loop()
end
defp loop(log_file) do
IO.binwrite(log_file, "\n---------\n")
case IO.binread(:stdio, 4) do
:eof ->
IO.binwrite(log_file, "EOF\n")
:ok
{:error, reason} ->
IO.binwrite(log_file, "Error: #{inspect reason}\n")
{:error, reason}
<<len::unsigned-little-32>> ->
:stdio
|> IO.binread(len)
|> dump_data(log_file)
|> ConformanceRequest.decode()
|> handle_request(log_file)
|> make_message_bytes()
|> output(log_file)
loop(log_file)
end
end
defp handle_request(
{
:ok,
req = %ConformanceRequest{
requested_output_format: :PROTOBUF,
payload: {:protobuf_payload, _}
}
},
log_file
) do
IO.binwrite(log_file, "Will parse protobuf\n")
{:protobuf_payload, payload} = req.payload
case TestAllTypes.decode(payload) do
{:ok, msg} ->
IO.binwrite(log_file, "Parse: success.\n")
encoded_payload = msg |> Protox.Encode.encode() |> :binary.list_to_bin()
%ConformanceResponse{result: {:protobuf_payload, encoded_payload}}
{:error, reason} ->
IO.binwrite(log_file, "Parse error: #{inspect reason}\n")
%ConformanceResponse{result: {:parse_error, "Parse error: #{inspect reason}"}}
end
end
# All JSON related tests are skipped.
defp handle_request({:ok, req}, log_file) do
skip_reason = case {req.requested_output_format, req.payload} do
{:UNSPECIFIED, _} ->
"unspecified input"
{:JSON, _} ->
"json input"
{:PROTOBUF, {:json_payload, _}} ->
"json output"
end
IO.binwrite(log_file, "SKIPPED\n")
IO.binwrite(log_file, "Reason: #{inspect skip_reason}\n")
IO.binwrite(log_file, "#{inspect req}\n")
%ConformanceResponse{result: {:skipped, "SKIPPED"}}
end
defp handle_request({:error, reason}, log_file) do
IO.binwrite(log_file, "ConformanceRequest parse error: #{inspect reason}\n")
%ConformanceResponse{result: {:parse_error, "Parse error: #{inspect reason}"}}
end
defp dump_data(data, log_file) do
IO.binwrite(log_file, "Received #{inspect data}\n")
data
end
defp output(data, log_file) do
IO.binwrite(log_file, "Will write #{byte_size(data)} bytes\n")
IO.binwrite(:stdio, data)
end
defp make_message_bytes(msg) do
data = msg |> Protox.Encode.encode() |> :binary.list_to_bin()
<<byte_size(data)::unsigned-little-32, data::binary>>
end
end