Current section
Files
Jump to
Current section
Files
src/acrostic@encoding.erl
-module(acrostic@encoding).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([encode_i32/1, encode_i64/1, encode_string/1, encode_varint/1, encode_bool/1, encode_field/3, encode_repeated_field/3]).
-export_type([field_encoder/1]).
-type field_encoder(LEV) :: {field_encoder,
acrostic@wire:wire_type(),
fun((LEV) -> bitstring())}.
-file("/Users/windy/mygleam/acrostic/src/acrostic/encoding.gleam", 34).
-spec encode_i32(float()) -> bitstring().
encode_i32(N) ->
<<N:32/float-little>>.
-file("/Users/windy/mygleam/acrostic/src/acrostic/encoding.gleam", 38).
-spec encode_i64(float()) -> bitstring().
encode_i64(N) ->
<<N:64/float-little>>.
-file("/Users/windy/mygleam/acrostic/src/acrostic/encoding.gleam", 42).
-spec encode_string(binary()) -> bitstring().
encode_string(S) ->
<<S/binary>>.
-file("/Users/windy/mygleam/acrostic/src/acrostic/encoding.gleam", 13).
-spec encode_varint(integer()) -> bitstring().
encode_varint(N) ->
case erlang:'band'(N, 16#FFFFFFFFFFFFFFFF) of
X when X >= 16#80 ->
gleam@bit_array:append(
<<(begin
_pipe = N,
_pipe@1 = erlang:'band'(_pipe, 16#7F),
erlang:'bor'(_pipe@1, 16#80)
end)>>,
encode_varint(acrostic@internal@helper:lsr(X, 7))
);
X@1 ->
<<(erlang:'band'(X@1, 16#7F))>>
end.
-file("/Users/windy/mygleam/acrostic/src/acrostic/encoding.gleam", 25).
-spec encode_bool(boolean()) -> bitstring().
encode_bool(B) ->
encode_varint((case B of
true ->
1;
false ->
0
end)).
-file("/Users/windy/mygleam/acrostic/src/acrostic/encoding.gleam", 95).
-spec encode_key(integer(), integer()) -> bitstring().
encode_key(Field_number, Wire_type) ->
Key = begin
_pipe = Field_number,
_pipe@1 = erlang:'bsl'(_pipe, 3),
erlang:'bor'(_pipe@1, Wire_type)
end,
encode_varint(Key).
-file("/Users/windy/mygleam/acrostic/src/acrostic/encoding.gleam", 50).
-spec encode_field(integer(), LFA, field_encoder(LFA)) -> bitstring().
encode_field(Field_num, Value, Encoder) ->
Key = encode_key(
Field_num,
begin
_pipe = erlang:element(2, Encoder),
acrostic@wire:to_int(_pipe)
end
),
Body = (erlang:element(3, Encoder))(Value),
Length = case erlang:element(2, Encoder) =:= len of
true ->
encode_varint(erlang:byte_size(Body));
false ->
<<>>
end,
_pipe@1 = Key,
_pipe@2 = gleam@bit_array:append(_pipe@1, Length),
gleam@bit_array:append(_pipe@2, Body).
-file("/Users/windy/mygleam/acrostic/src/acrostic/encoding.gleam", 65).
-spec encode_repeated_field(integer(), list(LFC), field_encoder(LFC)) -> bitstring().
encode_repeated_field(Field_num, List, Encoder) ->
case List of
[] ->
<<>>;
_ ->
Packed = erlang:element(2, Encoder) /= len,
case Packed of
true ->
Key = encode_key(
Field_num,
begin
_pipe = len,
acrostic@wire:to_int(_pipe)
end
),
Body = begin
_pipe@1 = List,
_pipe@2 = gleam@list:map(
_pipe@1,
fun(V) -> (erlang:element(3, Encoder))(V) end
),
gleam@list:fold(
_pipe@2,
<<>>,
fun gleam@bit_array:append/2
)
end,
Length = encode_varint(erlang:byte_size(Body)),
_pipe@3 = Key,
_pipe@4 = gleam@bit_array:append(_pipe@3, Length),
gleam@bit_array:append(_pipe@4, Body);
false ->
_pipe@5 = List,
_pipe@6 = gleam@list:map(
_pipe@5,
fun(V@1) -> encode_field(Field_num, V@1, Encoder) end
),
gleam@list:fold(_pipe@6, <<>>, fun gleam@bit_array:append/2)
end
end.