anchor.diff:  {$M-}
   {$ENDIF}
   
  -  { TContext }
  -
  -  TContext = class
  -  private
  -    FUserData: ICaseInsensitiveHashMap;
  -    function Get(Key: string): Variant;
  -    procedure Put(Key: string; const Value: Variant);
  -  public
  -    constructor Create(AUserData: IMap = nil);
  -    property UserData[Key: string]: Variant read Get write Put; default;
  -  end;
  -
  -  IFilter = interface
  -  ['{4AD7CCF2-1121-4CA4-92A7-5704C5956BA4}']
  -    function InputFilter(const Data: TBytes; const Context: TContext): TBytes;
  -    function OutputFilter(const Data: TBytes; const Context: TContext): TBytes;
  -  end;
  -
  -  TFilter = class(TInterfacedObject, IFilter)
  -  public
  -    function InputFilter(const Data: TBytes; const Context: TContext): TBytes;  virtual; abstract;
  -    function OutputFilter(const Data: TBytes; const Context: TContext): TBytes; virtual; abstract;
  -  end;
  -
  -  { TFilterList }
  -
  -  TFilterList = class
  -  private
  -    FFilters: IList;
  -  public
  -    constructor Create;
  -    function Get(Index: Integer): IFilter;
  -    procedure Put(Index: Integer; const Value: IFilter);
  -    function GetCount: Integer;
  -    function Add(const Filter: IFilter): TFilterList;
  -    function Remove(const Filter: IFilter): TFilterList;
  -    function InputFilter(const Data: TBytes; const Context: TContext): TBytes;
  -    function OutputFilter(const Data: TBytes; const Context: TContext): TBytes;
  -    property Filter[Index: Integer]: IFilter read Get write Put; default;
  -    property Count: Integer read GetCount;
  -  end;
  -
   const
   
   {$IFDEF CPU64}
  
positive.code:   Move(PChar(AString)^, FData[FPosition], Count * SizeOf(Char));
    Inc(FPosition, Count);
    if FPosition > FLength then FLength := FPosition;
  end;
  
  { TContext }
  
  function TContext.Get(Key: string): Variant;
  begin
    Result := FUserData[Key];
  end;
  
  procedure TContext.Put(Key: string; const Value: Variant);
  begin
    FUserData[Key] := Value;
  end;
  
  constructor TContext.Create(AUserData: IMap);
  begin
    FUserData := TCaseInsensitiveHashMap.Create(16, 0.75, False);
    if AUserData <> nil then FUserData.PutAll(AUserData);
  end;
  
  { TFilterList }
  
  constructor TFilterList.Create();
  begin
    FFilters := THashedList.Create;
  end;
  
  function TFilterList.Get(Index: Integer): IFilter;
  var
    F: Variant;
  begin
    Result := nil;
    F := FFilters[Index];
    if (not VarIsNull(F)) and (not VarIsEmpty(F)) then
      VarToIntf(F, IFilter, Result);
  end;
  
  procedure TFilterList.Put(Index: Integer; const Value: IFilter);
  begin
    FFilters[Index] := Value;
  end;
  
  function TFilterList.GetCount: Integer;
  begin
    Result := FFilters.Count;
  end;
  
  function TFilterList.Add(const Filter: IFilter): TFilterList;
  begin
    FFilters.Add(Filter);
    Result := Self;
  end;
  
  function TFilterList.Remove(const Filter: IFilter): TFilterList;
  begin
    FFilters.Remove(Filter);
    Result := Self;
  end;
  
  function TFilterList.InputFilter(const Data: TBytes; const Context: TContext
    ): TBytes;
  var
    I: Integer;
    AFilter: IFilter;
  begin
    Result := Data;
    for I := FFilters.Count - 1 downto 0 do begin
      VarToIntf(FFilters[I], IFilter, AFilter);
      Result := AFilter.InputFilter(Result, Context);
    end;
  end;
  
  function TFilterList.OutputFilter(const Data: TBytes; const Context: TContext
    ): TBytes;
  var
    I: Integer;
    AFilter: IFilter;
  begin
    Result := Data;
    for I := 0 to FFilters.Count - 1 do begin
      VarToIntf(FFilters[I], IFilter, AFilter);
      Result := AFilter.OutputFilter(Result, Context);
    end;
  end;
  
  { TVarObjectType }
  
negative.code:  *                                                        *
   * hprose common unit for delphi.                         *
   *                                                        *
   * LastModified: Nov 7, 2016                              *
   * Author: Ma Bingyao <andot@hprose.com>                  *
   *                                                        *
  \**********************************************************/
  