Class AttachmentPayload
The raw data of an Attachment, sent or received as a part of a multipart/mixed request or response and
matched to its Attachment object by SHA-2 (IEEE 9274.1.1, 4.1.3).
public sealed record AttachmentPayload : IEquatable<AttachmentPayload>
- Inheritance
-
AttachmentPayload
- Implements
- Inherited Members
Remarks
Equality compares the hash, the content type and the bytes.
The payload keeps the memory it is given; the bytes are not copied. Do not change them afterwards: the payload would then send data that no longer matches its Sha2, and an LRS that checks the hash would reject it. Copy the buffer first if it is reused.
Constructors
AttachmentPayload(string, string, ReadOnlyMemory<byte>)
Creates a payload.
public AttachmentPayload(string sha2, string contentType, ReadOnlyMemory<byte> content)
Parameters
sha2stringThe SHA-256 of
contentas hexadecimal text, in either case.contentTypestringThe media type, sent as the part's
Content-Type.contentReadOnlyMemory<byte>The raw bytes. Kept without a copy, so they must not change afterwards.
Properties
Content
The raw bytes. They are not copied, so they must not change while the payload is in use.
public ReadOnlyMemory<byte> Content { get; init; }
Property Value
ContentType
The media type, sent as the part's Content-Type.
public string ContentType { get; init; }
Property Value
Sha2
The SHA-256 of Content as lowercase hexadecimal text.
public string Sha2 { get; init; }
Property Value
Remarks
A hash given in uppercase is stored in lowercase, so equal payloads compare equal whatever its case.
Methods
Create(ReadOnlyMemory<byte>, string)
Creates a payload and computes its SHA-2.
public static AttachmentPayload Create(ReadOnlyMemory<byte> content, string contentType)
Parameters
contentReadOnlyMemory<byte>The raw bytes. Kept without a copy, so they must not change afterwards.
contentTypestringThe media type, for example
image/png.
Returns
- AttachmentPayload
The payload.
Equals(AttachmentPayload?)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(AttachmentPayload? other)
Parameters
otherAttachmentPayloadAn object to compare with this object.
Returns
GetHashCode()
Serves as the default hash function.
public override int GetHashCode()
Returns
- int
A hash code for the current object.
ToAttachment(Iri, LanguageMap)
Creates the Attachment object that describes this payload, with contentType, length and
sha2 taken from it, for the Attachments of the Statement it is sent with.
public Attachment ToAttachment(Iri usageType, LanguageMap display)
Parameters
usageTypeIriWhat the Attachment is for, for example
http://adlnet.gov/expapi/attachments/signature.displayLanguageMapThe display name.
Returns
- Attachment
The Attachment.