diff --git a/lib/protobuf/decoder.ex b/lib/protobuf/decoder.ex index 0fb33f3d..cbdfa1e1 100644 --- a/lib/protobuf/decoder.ex +++ b/lib/protobuf/decoder.ex @@ -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 @@ -351,6 +360,11 @@ defmodule Protobuf.Decoder do raw_decode_key(rest, [bytes | result]) end + defp raw_handle_varint(:delimiter, <>, result, len) do + <> = bin + {bytes, rest} + end + defp raw_handle_varint(:packed, <<>>, result, val) do [val | result] end