应用场景
在字节数组的开头(或结尾)添加(或删除)一个字节
函数代码
function PopByteArray(var A: TBytes): Byte;
begin
Assert(Length(A) > 0, 'A must be a non-empty array');
Result := A[Pred(Length(A))];
SetLength(A, Length(A) - 1);
end;
procedure PushByteArray(const B: Byte; var A: TBytes);
begin
SetLength(A, Length(A) + 1);
A[Pred(Length(A))] := B;
end;
function ShiftByteArray(var A: TBytes): Byte;
begin
Assert(Length(A) > 0, 'A must be a non-empty array');
Result := A[0];
Move(A[1], A[0], Length(A) - 1);
SetLength(A, Length(A) - 1);
end;
procedure UnShiftByteArray(const B: Byte; var A: TBytes);
begin
SetLength(A, Length(A) + 1);
Move(A[0], A[1], Length(A) - 1);
A[0] := B;
end;
994

被折叠的 条评论
为什么被折叠?



