zoukankan      html  css  js  c++  java
  • TRawByteStringStream

    TRawByteStringStream

      TRawByteStringStream = class(TStream)
      protected
        fDataString: RawByteString;
        fPosition: Integer;
        procedure SetSize(NewSize: Longint); override;
      public
        constructor Create(const aString: RawByteString = ''); overload;
        function Read(var Buffer; Count: Longint): Longint; override;
        function Seek(Offset: Longint; Origin: Word): Longint; override;
        function Write(const Buffer; Count: Longint): Longint; override;
        property DataString: RawByteString read fDataString write fDataString;
      end;
    { TRawByteStringStream }
    
    constructor TRawByteStringStream.Create(const aString: RawByteString);
    begin
      fDataString := aString;
    end;
    
    function TRawByteStringStream.Read(var Buffer; Count: Integer): Longint;
    begin
      if Count <= 0 then
        Result := 0
      else
      begin
        Result := Length(fDataString) - fPosition;
        if Result > Count then
          Result := Count;
        Move(PByteArray(fDataString)[fPosition], Buffer, Result);
        inc(fPosition, Result);
      end;
    end;
    
    function TRawByteStringStream.Seek(Offset: Integer; Origin: Word): Longint;
    begin
      case Origin of
        soFromBeginning:
          fPosition := Offset;
        soFromCurrent:
          fPosition := fPosition + Offset;
        soFromEnd:
          fPosition := Length(fDataString) - Offset;
      end;
      if fPosition > Length(fDataString) then
        fPosition := Length(fDataString)
      else if fPosition < 0 then
        fPosition := 0;
      result := fPosition;
    end;
    
    procedure TRawByteStringStream.SetSize(NewSize: Integer);
    begin
      SetLength(fDataString, NewSize);
      if fPosition > NewSize then
        fPosition := NewSize;
    end;
    
    function TRawByteStringStream.Write(const Buffer; Count: Integer): Longint;
    begin
      if Count <= 0 then
        Result := 0
      else
      begin
        Result := Count;
        SetLength(fDataString, fPosition + Result);
        Move(Buffer, PByteArray(fDataString)[fPosition], Result);
        inc(FPosition, Result);
      end;
    end;
    

      

  • 相关阅读:
    android的左右滑动效果实现-ViewFlipper
    ios学习之UISwipeGestureRecognizer手势识别
    iOS使用AVFoundation实现二维码扫描
    IOS开发之Core Location
    iOS中如何创建一个滑出式导航面板(1)
    消息推送之百度云推送Android集成与使用方法
    IOS开发之Storyboard应用
    用CocoaPods做iOS程序的依赖管理
    RelativeLayout 布局参数
    Android中获取应用程序(包)的信息-----PackageManager的使用
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/13733625.html
Copyright © 2011-2022 走看看