Skip to content
Open
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
14 changes: 14 additions & 0 deletions lib/protobuf/decoder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ defmodule Protobuf.Decoder do
struct = build_struct(kvs, msg_props, module.new())
reverse_repeated(struct, repeated_fields)
end

def decode_delimited_stream(data, module) do
Stream.unfold(data, fn
<<>> -> nil
data ->
{message_bin, rest} = decode_varint(data, :delimiter)
{decode(message_bin, module), rest}
end)
end

@doc false
def decode_raw(data) do
Expand Down Expand Up @@ -351,6 +360,11 @@ defmodule Protobuf.Decoder do
raw_decode_key(rest, [bytes | result])
end

defp raw_handle_varint(:delimiter, <<bin::bits>>, result, len) do
<<bytes::bytes-size(len), rest::bits>> = bin
{bytes, rest}
end

defp raw_handle_varint(:packed, <<>>, result, val) do
[val | result]
end
Expand Down