-
Notifications
You must be signed in to change notification settings - Fork 16
Possible to use dproto in @safe code. #79
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,8 @@ import std.range; | |
| import std.system : Endian; | ||
| import std.traits; | ||
|
|
||
| @safe: | ||
|
|
||
| /******************************************************************************* | ||
| * Returns whether the given string is a protocol buffer primitive | ||
| * | ||
|
|
@@ -254,6 +256,8 @@ long readVarint(R)(ref R src) | |
| * r = output range | ||
| * src = The value to encode | ||
| * Returns: The created VarInt | ||
| * | ||
| * Note: This is @trusted for compatibility with @system R.put(). | ||
| */ | ||
| void toVarint(R, T)(ref R r, T src) @trusted @property | ||
| if(isOutputRange!(R, ubyte) && isIntegral!T && isUnsigned!T) | ||
|
|
@@ -279,6 +283,7 @@ void toVarint(R, T)(ref R r, T src) @trusted @property | |
| * r = output range | ||
| * src = The value to encode | ||
| * Returns: The created VarInt | ||
| * | ||
| */ | ||
| void toVarint(R)(ref R r, long src) @safe @property | ||
| if(isOutputRange!(R, ubyte)) | ||
|
|
@@ -312,6 +317,8 @@ unittest { | |
| * Params: | ||
| * src = The data stream | ||
| * Returns: The decoded value | ||
| * | ||
| * Note: This is @trusted for compatibility with @system R.put(). | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems potentially problematic to me to blindly trust the code for any arbitrary |
||
| */ | ||
| T fromVarint(T = ulong, R)(R src) @property | ||
| if(isInputRange!R && is(ElementType!R : const ubyte) && | ||
|
|
@@ -460,19 +467,19 @@ void writeProto(string T, R)(ref R r, BuffType!T src) | |
| } | ||
|
|
||
| /// Ditto | ||
| void writeProto(string T, R)(ref R r, const BuffType!T src) | ||
| void writeProto(string T, R)(ref R r, const BuffType!T src) @trusted | ||
| if(isProtoOutputRange!R && | ||
| (T.msgType == "double".msgType || T.msgType == "float".msgType)) | ||
| { | ||
| r.put(src.nativeToLittleEndian!(BuffType!T)[]); | ||
| } | ||
|
|
||
| /// Ditto | ||
| void writeProto(string T, R)(ref R r, const BuffType!T src) | ||
| void writeProto(string T, R)(ref R r, const BuffType!T src) @trusted | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand the rationale for making these
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't feel that comfortable with |
||
| if(isProtoOutputRange!R && T.msgType == "string".msgType) | ||
| { | ||
| toVarint(r, src.length); | ||
| r.put(cast(ubyte[])src); | ||
| r.put(cast(const ubyte[]) src); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the rationale for making this
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't expect |
||
| } | ||
|
|
||
| /******************************************************************************* | ||
|
|
||
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 shouldn't be applied to the templated methods; you can't guarantee it is appropriate.
I would suggest it only be applied to the non-templated
serialize()method. Attribute inference will take care of the rest.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.
OK. Didn't know about attribute inference :)
But still the templated
deserialize()has to be marked as @safe too. Is it appropriate to require that the ProtoInputRange R provides @safe functions? My answer is yes, you should definitively enforce bound checks when parsing data from non-trusted sources.