Skip to content

Commit

Permalink
Make struct layouts explicit for persistence (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
chitsaw committed Oct 20, 2023
1 parent ef4b2a6 commit d4420d6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
6 changes: 6 additions & 0 deletions Sources/Runtime/Microsoft.Psi/Common/Envelope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,39 @@
namespace Microsoft.Psi
{
using System;
using System.Runtime.InteropServices;

/// <summary>
/// Represents the envelope of a message published to a data stream.
/// See <see cref="Message{T}"/> for details.
/// </summary>
[StructLayout(LayoutKind.Explicit)]
public struct Envelope
{
/// <summary>
/// The id of the stream that generated the message.
/// </summary>
[FieldOffset(0)]
public int SourceId;

/// <summary>
/// The sequence number of this message, unique within the stream identified by <see cref="SourceId"/>.
/// </summary>
[FieldOffset(4)]
public int SequenceId;

/// <summary>
/// The originating time of the message, representing the time of the real-world event that led to the creation of this message.
/// This value is used as a key when synchronizing messages across streams.
/// This value must be propagated with any message derived from this message.
/// </summary>
[FieldOffset(8)]
public DateTime OriginatingTime;

/// <summary>
/// The message creation time.
/// </summary>
[FieldOffset(16)]
public DateTime CreationTime;

/// <summary>
Expand Down
24 changes: 15 additions & 9 deletions Sources/Runtime/Microsoft.Psi/Data/IndexEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Microsoft.Psi.Data
{
using System;
using System.Runtime.InteropServices;

/// <summary>
/// Structure describing a position in a data file.
Expand All @@ -21,28 +22,33 @@ namespace Microsoft.Psi.Data
/// When writing large messages, an index entry is written into the main data file,
/// pointing to a location in the large data file where the actual message resides.
/// </remarks>
[StructLayout(LayoutKind.Explicit)]
public struct IndexEntry
{
/// <summary>
/// The largest time value seen up to the position specified by this entry.
/// The id of the extent this index entry refers to.
/// A negative extentId indicates an entry in the large file for \psi stores.
/// </summary>
public DateTime CreationTime;
[FieldOffset(0)]
public int ExtentId;

/// <summary>
/// The largest originating time value seen up to the position specified by this entry.
/// The position within the extent to which this index entry points.
/// </summary>
public DateTime OriginatingTime;
[FieldOffset(4)]
public int Position;

/// <summary>
/// The id of the extent this index entry refers to.
/// A negative extentId indicates an entry in the large file for \psi stores.
/// The largest time value seen up to the position specified by this entry.
/// </summary>
public int ExtentId;
[FieldOffset(8)]
public DateTime CreationTime;

/// <summary>
/// The position within the extent to which this index entry points.
/// The largest originating time value seen up to the position specified by this entry.
/// </summary>
public int Position;
[FieldOffset(16)]
public DateTime OriginatingTime;

/// <summary>
/// Initializes a new instance of the <see cref="IndexEntry"/> struct.
Expand Down

0 comments on commit d4420d6

Please sign in to comment.