/* If the stream goes backward (toward lower addresses), the bytes written to the stream are not reverted. In the example below, writing "Hello" to the stream will not revert the string. The end of the stream buffer will contain "Hello world!". Stream buffer: +------------ */
EFI_STATUS EFIAPI AmlStreamWrite(IN AML_STREAM *Stream, IN CONST UINT8 *Buffer, IN UINT32 Size)
/* If the stream goes backward (toward lower addresses), the bytes written to the stream are not reverted. In the example below, writing "Hello" to the stream will not revert the string. The end of the stream buffer will contain "Hello world!". Stream buffer: +------------ */
EFI_STATUS EFIAPI AmlStreamWrite(IN AML_STREAM *Stream, IN CONST UINT8 *Buffer, IN UINT32 Size)
{
  UINT8  *CurrPos;
  if (!IS_STREAM (Stream)       ||
      IS_END_OF_STREAM (Stream) ||
      (Buffer == NULL)          ||
      (Size == 0))
  {
    ASSERT (0);
    return EFI_INVALID_PARAMETER;
  }
  if (AmlStreamGetFreeSpace (Stream) < Size) {
    ASSERT (0);
    return EFI_BUFFER_TOO_SMALL;
  }
  CurrPos = AmlStreamGetCurrPos (Stream);
  if (IS_STREAM_BACKWARD (Stream)) {
    CurrPos -= Size;
  }
  CopyMem (CurrPos, Buffer, Size);
  Stream->Index += Size;
  return EFI_SUCCESS;
}