-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
408 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "priv/protodef-spec"] | ||
path = priv/protodef-spec | ||
url = https://github.com/rom1504/ProtoDef.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,6 @@ defmodule ProtoDef.AstUtils do | |
|> Enum.concat | ||
end | ||
|
||
def extract_block({:__block__, _, [expr]}), do: expr | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,38 @@ | ||
defmodule ProtoDef.Type.CString do | ||
@behaviour ProtoDef.Type | ||
use ProtoDef.Type | ||
|
||
defstruct [] | ||
defstruct ident: nil | ||
|
||
def preprocess(nil, _ctx) do | ||
%__MODULE__{} | ||
end | ||
|
||
def structure(_, _), do: __MODULE__ | ||
|
||
def decoder_ast(_descr, _ctx) do | ||
quote do | ||
with do | ||
{:ok, {str, rest}} = ProtoDef.Type.CString.decode_string(unquote(@data_var)) | ||
{str, rest} | ||
end | ||
end | ||
end | ||
|
||
def encoder_ast(_descr, _ctx) do | ||
quote do | ||
with do | ||
# This makes sure there are no null bytes in the string | ||
:error = ProtoDef.Type.CString.decode_string(unquote(@input_var)) | ||
[unquote(@input_var), 0] | ||
end | ||
end | ||
end | ||
|
||
def decode_string(bin, num \\ 0) do | ||
case bin do | ||
<<str::binary-size(num), 0, rest::binary>> -> {:ok, {str, rest}} | ||
_ when byte_size(bin) > num -> decode_string(bin, num+1) | ||
_ -> :error | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.