34 lines
1.0 KiB
C#
34 lines
1.0 KiB
C#
using Qrakhen.Qamp.Core.Execution;
|
|
using System.Text;
|
|
|
|
namespace Qrakhen.Qamp.Core.Values.Objects;
|
|
|
|
public class Function(string name, Segment segment, int outerCount, int argumentCount) : Obj(ValueType.Function)
|
|
{
|
|
public readonly string Name = name;
|
|
public Segment Segment = segment;
|
|
public readonly int OuterCount = outerCount;
|
|
public readonly int ArgumentCount = argumentCount;
|
|
|
|
public override string ToString() => $"{Name}()";
|
|
|
|
public byte[] Serialize(bool topLevel = false)
|
|
{
|
|
List<byte> result =
|
|
[
|
|
.. string.IsNullOrEmpty(Name) ? [] : Encoding.ASCII.GetBytes(Name),
|
|
0,
|
|
(byte)ArgumentCount,
|
|
.. OuterCount.GetBytes(),
|
|
.. Segment.Serialize()
|
|
];
|
|
if (topLevel) {
|
|
result.AddRange([0xFF, 0xF0]);
|
|
result.AddRange(String.SerializeStrings());
|
|
result.AddRange([0x0F, 0xFF, 0xFF, 0xF1]);
|
|
result.AddRange(Ptr.SerializeFunctions());
|
|
result.AddRange([0x0F, 0xFF]);
|
|
}
|
|
return result.ToArray();
|
|
}
|
|
} |