-
Notifications
You must be signed in to change notification settings - Fork 33
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
Feature/payload types #82
Conversation
lib/membrane/buffer.ex
Outdated
@type metadata_t :: map | ||
|
||
@type t :: %Buffer{ | ||
payload: payload_t, | ||
payload: Payload.t(), | ||
type: :binary | :shm | :pointer, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this field necessary? I don't think Core should be aware of all payload types. Also name type
is a bit misleading, because it determines the type of payload, not type of buffer. Maybe it could be replaced with type
function in Payload
protocol, returning atom.
lib/membrane/payload.ex
Outdated
@moduledoc """ | ||
""" | ||
|
||
@type t :: struct() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This protocol can be implemented for anything, and it is already for binary, so I would say any
lib/membrane/payload.ex
Outdated
def to_binary(payload) | ||
end | ||
|
||
defimpl Membrane.Payload, for: BitString do |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
@@ -0,0 +1,50 @@ | |||
defprotocol Membrane.Payload do | |||
@moduledoc """ |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
lib/membrane/payload.ex
Outdated
end | ||
|
||
@spec split_at(binary(), non_neg_integer) :: {binary(), binary()} | ||
def split_at(data, 0) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is already covered by the last clause. I am also not sure if we should require supporting this in protocol, as we do not use this, and implementing for other payloads might be problematic.
lib/membrane/payload.ex
Outdated
@doc """ | ||
Splits the payload at given position (1st part has the size equal to `at_pos` argument) | ||
""" | ||
@spec split_at(payload :: t(), at_pos :: non_neg_integer()) :: {t(), t()} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would change at_pos
type to pos_integer
5de962e
to
4d71e4f
Compare
4d71e4f
to
78d5a50
Compare
lib/membrane/payload.ex
Outdated
""" | ||
@spec size(payload :: t()) :: non_neg_integer() | ||
def size(payload) | ||
|
||
@doc """ | ||
Splits the payload at given position (1st part has the size equal to `at_pos` argument) | ||
|
||
`at_pos` has to be greater than 0 and smaller than the size of payload. This guarantees |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It sounds like a user would have to guarantee that at_pos
is valid. I would rather write "at_pos
is always greater than 0..."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still not resolved
lib/membrane/payload.ex
Outdated
`at_pos` has to be greater than 0 and smaller than the size of payload. This guarantees | ||
returned payloads are never empty. | ||
|
||
When such conditions are not met, the function should raise. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would remove this sentence, as it is responsibility of the core to invoke these functions with proper arguments. Additional checks might be performed to be sure. Going current way, we should also write that function should raise e.g. if a string is passed instead of integer.
lib/membrane/payload.ex
Outdated
@spec split_at(payload :: t(), at_pos :: non_neg_integer()) :: {t(), t()} | ||
def split_at(payload, at_pos) | ||
@spec split_at!(payload :: t(), at_pos :: pos_integer()) :: {t(), t()} | ||
def split_at!(payload, at_pos) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this exclamation is unnecessary. Specificaton of the function does not impose that any errors may happen
Returns an atom describing type of the payload. | ||
""" | ||
@spec type(t()) :: atom() | ||
def type(payload) |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
95d7e5e
to
e00facf
Compare
lib/membrane/payload.ex
Outdated
@doc """ | ||
Splits the payload at given position (1st part has the size equal to `at_pos` argument) | ||
|
||
`at_pos` has to be greater than 0 and smaller than the size of payload. This guarantees |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It sounds as if a user would have to guarantee that at_pos
is valid. I would rather write "at_pos
is always greater than 0..."
Closes #68