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

Improve the FieldOffset #193

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

sn4k3
Copy link

@sn4k3 sn4k3 commented Sep 5, 2022

This pull request implements #178 which allows to jump to addresses and make use of stream.Seek() with SeekOrigin.
The default behaviour of FieldOffset has not changed and then it will rewind by default.

Since i have files pointing to tables this will help having a master class rather that multiple classes and jump in between.

Arguments

  • offset|path
  • SeekOrigin: Specifies the position in a stream to use for seeking the field (Default: SeekOrigin.Begin)
  • Rewind: If true it will seek back to position where it was before seek, otherwise stream will continue from the current position (Default: true)

Example:

public class FileSpec
{
    [FieldOrder(0)]
    [FieldLength(12)]
    [SerializeAs(SerializedType.TerminatedString)]
    public string FileVersion { get; set; } = "FileMarking";

    [FieldOrder(1)]
    public uint FileVersion { get; set; }

    [FieldOrder(2)]
    public uint HeaderAddress { get; set; }

    [FieldOrder(3)]
    public uint SettingsAddress { get; set; }

    [FieldOrder(4)]
    public uint PreviewAddress { get; set; }

    [FieldOrder(5)]
    public uint LayersAddress { get; set; }

    [FieldOrder(6)]
    [FieldOffset(nameof(HeaderAddress), false)]
    public uint HeaderField1 { get; set; }

    [FieldOrder(7)]
    public uint HeaderField2 { get; set; }

    [FieldOrder(8)]
    public uint HeaderField3 { get; set; }

    [FieldOrder(9)]
    [FieldOffset(nameof(SettingsAddress), false)]
    public uint SettingsField1 { get; set; }

    [FieldOrder(10)]
    public uint SettingsField2 { get; set; }

    [FieldOrder(11)]
    [FieldOffset(nameof(PreviewAddress), false)]
    public uint PreviewSize { get; set; }

    [FieldOrder(12)]
    [FieldCount(nameof(PreviewSize))]
    public byte[] PreviewData {get; set; }

    [FieldOrder(13)]
    [FieldOffset(nameof(LayersAddress), false)]
    public uint LayerCount { get; set; }

    [FieldOrder(14)]
    [FieldCount(nameof(LayerCount))]
    public Layer[] Layers { get; set; }

    [FieldOrder(15)]
    [FieldOffset(4, SeekOrigin.Current, false)] // Skip unused 4 bytes first, same as declaring uint Padding
    public uint FileChecksum { get; set; }
}

@stumpy1029
Copy link

Any updates on this feature? I have a chunk file format (that I cannot change) who uses absolute file offsets for each chunk.

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.

3 participants