Table of Contents

Class AttachmentPayload

Namespace
Xapi.Client
Assembly
Xapi.Client.dll

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

sha2 string

The SHA-256 of content as hexadecimal text, in either case.

contentType string

The media type, sent as the part's Content-Type.

content ReadOnlyMemory<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

ReadOnlyMemory<byte>

ContentType

The media type, sent as the part's Content-Type.

public string ContentType { get; init; }

Property Value

string

Sha2

The SHA-256 of Content as lowercase hexadecimal text.

public string Sha2 { get; init; }

Property Value

string

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

content ReadOnlyMemory<byte>

The raw bytes. Kept without a copy, so they must not change afterwards.

contentType string

The 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

other AttachmentPayload

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

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

usageType Iri

What the Attachment is for, for example http://adlnet.gov/expapi/attachments/signature.

display LanguageMap

The display name.

Returns

Attachment

The Attachment.