Allow for an absolute mode for the FieldOffset attribute
I've been trying to circumvent this a lot recently, but the current API I'm working with requires the use of absolute offsets. for example, a class may be created as
class SomeClass
{
[FieldOrder(0)] public SomeType A;
[FieldOrder(1)] public Int Offset;
[FieldOrder(2)] public SomeType C;
}
But let's say that we C is behind where the class has started (but member C is still tied to this Class) .e.g. When SomeClass started being deserialized, it started at offset 0x10, and we want member C to start at offset 0x7 because the value of the member Offset is 0x7 (an absolute offset).
Currently, this is not possible without using custom serialization.
Have you tried using FieldOffset? Also, at some point if you’re jumping around in the file it isn’t really serialization anymore :)
— Planning for failure is even dumber than regular planning
From: Waelwindows [email protected] Sent: Sunday, February 11, 2018 6:41:49 PM To: jefffhaynes/BinarySerializer Cc: Subscribed Subject: [jefffhaynes/BinarySerializer] Allow for an absolute mode for the FieldOffset attribute (#94)
I've been trying to circumvent this a lot recently, but the current API I'm working with requires the use of absolute offsets. for example, a class may be created as class SomeClass { [FieldOrder(0)] public SomeType A; [FieldOrder(1)] public SomeType B; [FieldOrder(2)] public SomeType C; }
But let's say that we C is behind where the class has started (but member C is still tied to this Class) .e.g. When SomeClass started being deserialized, it started at offset 0x10, and we want member C to start at offset 0x7.
Currently, this is not possible without using custom serialization.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/jefffhaynes/BinarySerializer/issues/94, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AJSKR77cvgU8XSz4MkoRlaYCbCOyuaAuks5tT3q8gaJpZM4SBkNX.
I tried, but FieldOffset doesn't really allow for negative offset
FieldOffset is for specifying an absolute offset. The stream will reset to where you started after the offset so it should work.
— Planning for failure is even dumber than regular planning
From: Waelwindows [email protected] Sent: Sunday, February 11, 2018 6:56:51 PM To: jefffhaynes/BinarySerializer Cc: Jeff Haynes; Comment Subject: Re: [jefffhaynes/BinarySerializer] Allow for an absolute mode for the FieldOffset attribute (#94)
I tried, but FieldOffset doesn't really allow for negative offset
— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/jefffhaynes/BinarySerializer/issues/94#issuecomment-364802550, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AJSKR1F9_hcteEVrlqb-5IpNJX1i3ShDks5tT35DgaJpZM4SBkNX.
Here are some example code and a test file.
When deserializing the file you can see that you get this
https://i.imgur.com/IyDAdBd.png
But if you look at an entry,

The string is the same as the ID (with FieldOffset set to 0) meaning that the FieldOffest is relative to where the class is being deserialized.
You get the same results when you explicitly deserialize at the starting position of the Entries
file.Position = 21;
var tst = serial.Deserialize<Entries>(file);
It also seems like that when a member is deserialized, a unique stream is created for them, without any data from behind (tried with custom deserialization)
You're right, I had forgotten about that. Offsets are relative to the parent. So are you saying you want offsets that are relative to the global zero position?
Yes, even though I managed to find a hack around it. But it would be better to have native support for that
So I was thinking about it and I'm not sure that's right. You actually want to offset from an object further up in the graph, right? If you offset from the beginning of the stream I think it would deserialize incorrectly, wouldn't it? I started working on this and I realized it's a difficult problem to solve generically since you may want to offset from any arbitrary parent in the graph (including the root).
On Sun, Feb 25, 2018 at 10:31 AM, Waelwindows [email protected] wrote:
Yes
— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/jefffhaynes/BinarySerializer/issues/94#issuecomment-368318404, or mute the thread https://github.com/notifications/unsubscribe-auth/AJSKR7tLxBAY6z0_q05vyyR8CbBE1uMYks5tYXzWgaJpZM4SBkNX .
-- If you want to build a ship, don't drum up people together to collect wood and don't assign them tasks and work, but rather teach them to long for the endless immensity of the sea.
Antoine de Saint-Exupery
I don't think there's any thing that could go wrong with deserialization. Shouldn't it just act as if you set the steam offset to that location?
Yes but aren’t there a few ints at the beginning of the stream before the offset starts? Or do I have it wrong.
— If you want to build a ship, don't drum up people to collect wood and don't assign them tasks and work, but rather teach them to long for the endless immensity of the sea.
Antoine de Saint-Exupery
From: Waelwindows [email protected] Sent: Monday, February 26, 2018 3:53:00 PM To: jefffhaynes/BinarySerializer Cc: Jeff Haynes; Assign Subject: Re: [jefffhaynes/BinarySerializer] Allow for an absolute mode for the FieldOffset attribute (#94)
I don't think there's any thing that could go wrong with deserialization. Shouldn't it just act as if you set the steam offset to that location?
— You are receiving this because you were assigned. Reply to this email directly, view it on GitHubhttps://github.com/jefffhaynes/BinarySerializer/issues/94#issuecomment-368646213, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AJSKRz0tYd8niFTsYzrklfaC8caAzNfUks5tYxmjgaJpZM4SBkNX.
There are some ints. But don't forget that the strings will always come after those ints, so it wouldn't conflict with the previous ints locations, That way, deserialization and serialization aren't affected. (For serialization, before serializing the parent class, write 00 bytes till you reach the specified offset)
But my point is that the offset is relative to the end of the ints, not the start of the file.
On Thu, Mar 1, 2018 at 10:22 AM, Waelwindows [email protected] wrote:
There are some ints. But don't forget that the strings will always come after those ints, so it wouldn't conflict with the previous ints locations, That way, deserialization and serialization aren't affected. (For serialization, before serializing the parent class, write 00 bytes till you reach the specified offset)
— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/jefffhaynes/BinarySerializer/issues/94#issuecomment-369626075, or mute the thread https://github.com/notifications/unsubscribe-auth/AJSKR2xG8ZXvSyicXX457p5mb9kxYF0Mks5taBI4gaJpZM4SBkNX .
-- If you want to build a ship, don't drum up people together to collect wood and don't assign them tasks and work, but rather teach them to long for the endless immensity of the sea.
Antoine de Saint-Exupery
The AbsoluteOffset should start from the beginning of the file. Yeah, but how I would use this would be relative to the end of the ints
Sorry, I'm still not following. If it's relative to the beginning of the file how can it also be relative to the end of the ints?
On Mon, Mar 5, 2018 at 12:52 PM, Waelwindows [email protected] wrote:
The AbsoluteOffset should start from the beginning of the file. Yeah, but how I would use this would be relative to the end of the ints
— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/jefffhaynes/BinarySerializer/issues/94#issuecomment-370504555, or mute the thread https://github.com/notifications/unsubscribe-auth/AJSKRzEb1nRWkfa9xjMlJ547eASHhRB3ks5tbXtKgaJpZM4SBkNX .
-- If you want to build a ship, don't drum up people together to collect wood and don't assign them tasks and work, but rather teach them to long for the endless immensity of the sea.
Antoine de Saint-Exupery
The ints are at the beginning of the file, the data structure I'm trying to deserialize will always start after the ints. Which means that my struct is directly after the ints and is relative to both the start of the file and the end of the ints. Of course, it's closer to the end of the ints than it is to the start of the file
Hello, I#m just run in the same problem. I tried to decode a TIFF header and inside the IFD of the TIFF header are absolute offsets. So it would be good to heave the absolut offset or get the current offset of parent some how.