-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
| ||
namespace MatterDotNet.Protocol.Payloads | ||
{ | ||
public enum GeneralCode | ||
{ | ||
/// <summary> | ||
/// Operation completed successfully. | ||
/// </summary> | ||
SUCCESS = 0, | ||
/// <summary> | ||
/// Generic failure, additional details may be included in the protocol specific status. | ||
/// </summary> | ||
FAILURE = 1, | ||
/// <summary> | ||
/// Operation was rejected by the system because the system is in an invalid state. | ||
/// </summary> | ||
BAD_PRECONDITION = 2, | ||
/// <summary> | ||
/// A value was out of a required range | ||
/// </summary> | ||
OUT_OF_RANGE = 3, | ||
/// <summary> | ||
/// A request was unrecognized or malformed | ||
/// </summary> | ||
BAD_REQUEST = 4, | ||
/// <summary> | ||
/// An unrecognized or unsupported request was received | ||
/// </summary> | ||
UNSUPPORTED = 5, | ||
/// <summary> | ||
/// A request was not expected at this time | ||
/// </summary> | ||
UNEXPECTED = 6, | ||
/// <summary> | ||
/// Insufficient resources to process the given request | ||
/// </summary> | ||
RESOURCE_EXHAUSTED = 7, | ||
/// <summary> | ||
/// Device is busy and cannot handle this request at this time | ||
/// </summary> | ||
BUSY = 8, | ||
/// <summary> | ||
/// A timeout occurred | ||
/// </summary> | ||
TIMEOUT = 9, | ||
/// <summary> | ||
/// Context-specific signal to proceed | ||
/// </summary> | ||
CONTINUE = 10, | ||
/// <summary> | ||
/// Failure, may be due to a concurrency error. | ||
/// </summary> | ||
ABORTED = 11, | ||
/// <summary> | ||
/// An invalid/unsupported argument was provided | ||
/// </summary> | ||
INVALID_ARGUMENT = 12, | ||
/// <summary> | ||
/// Some requested entity was not found | ||
/// </summary> | ||
NOT_FOUND = 13, | ||
/// <summary> | ||
/// The sender attempted to create something that already exists | ||
/// </summary> | ||
ALREADY_EXISTS = 14, | ||
/// <summary> | ||
/// The sender does not have sufficient permissions to execute the requested operations. | ||
/// </summary> | ||
PERMISSION_DENIED = 15, | ||
/// <summary> | ||
/// Unrecoverable data loss or corruption has occurred. | ||
/// </summary> | ||
DATA_LOSS = 16, | ||
/// <summary> | ||
/// Message size is larger than the recipient can handle. | ||
/// </summary> | ||
MESSAGE_TOO_LARGE = 17, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// MatterDotNet Copyright (C) 2024 | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or any later version. | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY, without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
// See the GNU Affero General Public License for more details. | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
using System.Buffers.Binary; | ||
|
||
namespace MatterDotNet.Protocol.Payloads | ||
{ | ||
public class StatusPayload : IPayload | ||
{ | ||
/// <summary> | ||
/// General status codes conveyed in the GeneralCode field are uniform codes that convey both success and failures. | ||
/// </summary> | ||
public ushort GeneralCode { get; set; } | ||
public ushort ProtocolVendor { get; set; } | ||
public ushort ProtocolID { get; set; } | ||
public ushort ProtocolCode { get; set; } | ||
|
||
public StatusPayload(Memory<byte> data) | ||
{ | ||
GeneralCode = BinaryPrimitives.ReadUInt16LittleEndian(data.Span); | ||
ProtocolVendor = BinaryPrimitives.ReadUInt16LittleEndian(data.Slice(2, 2).Span); | ||
ProtocolID = BinaryPrimitives.ReadUInt16LittleEndian(data.Slice(4, 2).Span); | ||
ProtocolCode = BinaryPrimitives.ReadUInt16LittleEndian(data.Slice(6, 2).Span); | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
if (ProtocolVendor == 0) | ||
return $"General Code: {GeneralCode}, Protocol: {(ProtocolType)ProtocolID}, Protocol Code: {ProtocolCode}"; | ||
else | ||
return $"General Code: {GeneralCode}, Vendor: {ProtocolVendor:X2}, Protocol: {ProtocolID:X2}, Protocol Code: {ProtocolCode}"; | ||
} | ||
|
||
public bool Serialize(PayloadWriter stream) | ||
{ | ||
stream.Write(GeneralCode); | ||
stream.Write(ProtocolVendor); | ||
stream.Write(ProtocolID); | ||
stream.Write(ProtocolCode); | ||
return true; | ||
} | ||
} | ||
} |