OSDP.Net 5.2.1
A .NET library for implementing the Open Supervised Device Protocol (OSDP)
Loading...
Searching...
No Matches
FileTransferFragment.cs
1using System;
2using System.Collections.Generic;
3using System.Text;
6
8
17{
23 public FileTransferFragment(byte type, MessageDataFragment fragment)
24 {
25 Type = type;
26 Fragment = fragment;
27 }
28
32 public byte Type { get; }
33
38
40 public override CommandType CommandType => CommandType.FileTransfer;
41
43 public override byte Code => (byte)CommandType;
44
46 public override ReadOnlySpan<byte> SecurityControlBlock() => SecurityBlock.CommandMessageWithDataSecurity;
47
49 public override byte[] BuildData()
50 {
51 var data = new List<byte> {Type};
52 data.AddRange(Fragment.BuildData().ToArray());
53 return data.ToArray();
54 }
55
57 public override string ToString()
58 {
59 var build = new StringBuilder();
60 build.AppendLine($" Transfer Type: 0x{Type:X2} ({DescribeType(Type)})");
61 build.AppendLine($" Total Size: {Fragment.TotalSize}");
62 build.AppendLine($" Offset: {Fragment.Offset}");
63 build.AppendLine($" Fragment Size: {Fragment.FragmentSize}");
64 return build.ToString();
65 }
66
70 private static string DescribeType(byte type) => type switch
71 {
72 0x01 => "Opaque file contents",
73 0x02 => "Template for the next osdp_BIOMATCH",
74 0x03 => "PD-specific opaque data for display",
75 <= 0x7F => "Reserved for future use",
76 _ => "Reserved for private use"
77 };
78
82 public static FileTransferFragment ParseData(ReadOnlySpan<byte> data)
83 {
84 return new FileTransferFragment(data[0], MessageDataFragment.ParseData(data.Slice(1), MessageDataFragmentFieldSize.FourBytes));
85 }
86}
Contains standard Security Control Block data that can be used when building messages.
Base class representing a payload of a PD command message.
FileTransferFragment(byte type, MessageDataFragment fragment)
Initializes a new instance of the FileTransferFragment class.
override ReadOnlySpan< byte > SecurityControlBlock()
MessageDataFragment Fragment
Get the message data fragment.
static FileTransferFragment ParseData(ReadOnlySpan< byte > data)
Parses the message payload bytes.
Represents a fragment of data for a multipart message.
static MessageDataFragment ParseData(ReadOnlySpan< byte > data, MessageDataFragmentFieldSize sizeAndOffsetFieldSize)
Parses the message payload bytes.
MessageDataFragmentFieldSize
Defines the field size used for the MessageDataFragment.TotalSize and MessageDataFragment....