« first day (3696 days earlier)      last day (1477 days later) » 

06:02
generally speaking, I wouldnt recommend using structs or rely on byte layout
but anyway, why is the header byte 4 bytes in reserved space?
06:14
@Wietlol it's got 3 bytes of padding for data alignment.
You have to rely on byte layout in networking to read out data packets.
well... you dont have to
you can just read the bytes and deserialize them into whatever layout suits you
I am not sure I understand the data alignment tho
cant you just do FieldOffset(1) ?
@Wietlol you can do a field offset of one, but supposedly you should byte align data, but idk why... I havewn't really experienced any issues not doing so.
I might need to do a field offset of one anyways, because GameMaker (my client code) pulls data packets in as buffers with a default alignment of one, that cannot be changed.
The nice thing about structs is I can force explicit (with alignment) or sequential (without alignment) and do quick serialization using an unsafe byte[] in the background to populate the fields. Like Unions in C++.
Keeps you from having to write a serialization method for each packet type.
mr5
mr5
Only problem I can think rn is when you want to debug the serialized data. Would be hard I think.
06:29
@mr5 what do you mean?
mr5
mr5
like, some property/field did not have the value you expect it to have.
06:46
@mr5 wouldn't that just be a serialization code issue then?
mr5
mr5
06:59
I mean, it lacks helper methods to diagnose the header values (for the sake of over engineering). Like method that returns/prints a section from the header, say it prints: "Error flag is SET"
the size of the struct is too much I think?
08:16
[kesarling] BTW, guys, understood why that GitHub clone did not work the other day!
[kesarling] That seems to be a bug in VS
[kesarling] Issue has already been opened up
@mr5 right it's a bit much... Deciding on whether the padding/alignment is necessary or not. If not I can shave off the padded bytes.
I can do testing when a packet is received to check struct validity though.
Any alternatives?
mr5
mr5
The field is private to that struct. How would you check for that? Reflection?
do you own the field? check for another api maybe author had way to access? do things deriveable?
08:32
@mr5 it's private purely to avoid direct unsafe access to it. So you call a method .Serialize(ref byte[] buff) which would just copy the unsafe byte data to the reference byte[]. Or other way around .Deserialize(ref byte[] buff) which would copy from the buffer to the unsafe byte[]. Pretty straight forward to avoid any weird usage cases.
Then you can access the struct's public fields as normal after you've serialized/deserialized it.
@nyconing it's my code, not using someone else's API.
mr5
mr5
08:45
Right, but those are mutating functions, they don't return back any data. It looks like the public fields are missing from your code example though.
@mr5 nothing is missing, small example. 8 bytes, (4-byte alignment). 1 byte header, 4 byte int size, 3 bytes of padding.
Just add more variables, increase the size of the fixed byte[].
mr5
mr5
13 mins ago, by FatalSleep
Then you can access the struct's public fields as normal after you've serialized/deserialized it.
where is this?
Oh.... just realized.
I'm an idiot.
Fixed--the header and size variables should have been public: codereview.stackexchange.com/questions/252730/…
mr5
mr5
Hmm. Also, the common pattern I encounter when I invoke deserialize/serialize method is that they are pure functions. That is, I would expect it to return a data.
@FatalSleep I would make another accessor to it such that it would be a readonly property. If you do: instance.header = something, then instance.bytes is now unsync.
in C# world, it's very uncommon to make the field publicly accessible.
Oh is it??
mr5
mr5
08:53
yeah, we normally do properties.
all fields are private
also, a private property is very rare.
Ah well you could just do: public header { get; private set; }
Nope, I lied.
mr5
mr5
make it public byte Header { get; private set; }
Yeah, typo.
Seems C# doesn't allow it though.
At least with the [FieldOffset()] attribute.
Or not at all.
mr5
mr5
I think it's only for fields, not properties.
then maybe do it like this: public byte Header => _header
Correct, seems like it. And of course it is discouraged to use mutable structs.
So I guess I would need a constructor to create and deserialize a struct, then give it a serializer method and make the fields readonly.
Which is perfectly reasonable.
mr5
mr5
09:01
Yep, and also take out the serializer/deserializer method out of the class and make it a helper methods instead.
// I picture you would end up something like this:
var instance = Serializer.Deserialize<YourStructHere>(bytes);
var bytes = Serializer.Serialize(instance);
Wait, if I take them out of the struct I won't have access to the private unsafe fixed byte[] which is needed to serialize/deserialzie??
mr5
mr5
reflection ^^
@mr5 how would reflection affect performance though?
mr5
mr5
How often would you do this serialization?
is it real time?
Like... a lot. It's for sending/receiving packet data.
Network -> Received Data Packet -> Check Network Stream -> Deserialize Netwokr Stream Bytes to Struct. Struct Serialize to Bytes -> Send over Network Stream.
mr5
mr5
09:09
hmm. not really sure how much it would affect the performance. If you're not really comfortable with it, then just make those methods as static methods inside the struct itself.
Hm I might just do that then.
(static methods).
09:22
@mr5 I think I've got it, thanks man.
mr5
mr5
09:40
wc
bitte
 
7 hours later…
16:24
Hey guys, umm kinda confused between authentication scheme and authentication method
Help please :)
mr5
mr5
16:45
!!tumbleweed
17:04
[Li] Got this link that explains 1/2 things
[kesarling] thanks man 🙂
[kesarling] @li223 also, are the concepts same for razor and MVC?
[Li] No idea. Probably.

« first day (3696 days earlier)      last day (1477 days later) »