Skip to content
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

Merged
merged 8 commits into from
Aug 13, 2018
Merged

Feature/payload types #82

merged 8 commits into from
Aug 13, 2018

Conversation

bblaszkow06
Copy link
Member

Closes #68

@type metadata_t :: map

@type t :: %Buffer{
payload: payload_t,
payload: Payload.t(),
type: :binary | :shm | :pointer,
Copy link
Member

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.

@moduledoc """
"""

@type t :: struct()
Copy link
Member

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

def to_binary(payload)
end

defimpl Membrane.Payload, for: BitString do

This comment was marked as resolved.

This comment was marked as resolved.

@@ -0,0 +1,50 @@
defprotocol Membrane.Payload do
@moduledoc """

This comment was marked as resolved.

end

@spec split_at(binary(), non_neg_integer) :: {binary(), binary()}
def split_at(data, 0) do
Copy link
Member

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.

@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()}
Copy link
Member

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

@bblaszkow06 bblaszkow06 force-pushed the feature/payload-types branch 5 times, most recently from 5de962e to 4d71e4f Compare August 8, 2018 07:09
"""
@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
Copy link
Member

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..."

Copy link
Member

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

`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.
Copy link
Member

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.

@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)
Copy link
Member

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.

@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
Copy link
Member

@mat-hek mat-hek Aug 10, 2018

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..."

@bblaszkow06 bblaszkow06 merged commit 4503162 into master Aug 13, 2018
@bblaszkow06 bblaszkow06 deleted the feature/payload-types branch August 13, 2018 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants