Delphi DataSnap 流程分析(二)

news2024/11/15 13:50:54

Delphi DataSnap 流程分析(一)_看那山瞧那水的博客-CSDN博客

粗略分析了 创建传统DataSnap的流程,现在再分析下创建现在更常用的 方式:

DataSnap REST Application

这种方式只支持HTTP(普通HTTP和REST HTTP)通信,不支持TCP通信。

 这种方式包含有WebModule,HTTP服务器也是TIdHTTPWebBrokerBridge

 因此其HTTP Server的启动流程和 Delphi Web Server 流程分析_看那山瞧那水的博客-CSDN博客

里分析的一样,只是到了最后,也就是方法TCustomWebDispatcher.DispatchAction(),接着进行后续处理。

代码: 


constructor TCustomWebDispatcher.Create(AOwner: TComponent);
var
  I: Integer;
  Component: TComponent;
  SetAppDispatcher: ISetAppDispatcher;
begin
{$IFDEF MSWINDOWS}
{$ENDIF}
  FDispatchList := TObjectList<TComponent>.Create;//TComponentList.Create;
  FDispatchList.OwnsObjects := False;
  FOnException := nil;
  if AOwner <> nil then
    if AOwner is TCustomWebDispatcher then
      raise EWebBrokerException.Create(sOnlyOneDispatcher)
    else
      for I := 0 to AOwner.ComponentCount - 1 do
        if AOwner.Components[I] is TCustomWebDispatcher then
          raise EWebBrokerException.Create(sOnlyOneDispatcher);
  inherited CreateNew(AOwner, -1);
  FActions := TWebActionItems.Create(Self, TWebActionItem);
  if Owner <> nil then
    for I := 0 to Owner.ComponentCount - 1 do
    begin
      Component := Owner.Components[I];
      if Supports(IInterface(Component), ISetAppDispatcher, SetAppDispatcher) then
        SetAppDispatcher.SetAppDispatcher(Self)
      else if Supports(IInterface(Component), IWebDispatch) then
        FDispatchList.Add(Component);
    end;
end;

TCustomWebDispatcher类创建的时候,会加载支持接口IWebDispatch的组件,TDSHTTPWebDispatcher是支持IWebDispatch接口的:

TDSHTTPWebDispatcher = class(TDSHTTPServerTransport, IWebDispatch) 

所以FDispatchList列表包含了WebModule的组件DSHTTPWebDispatcher1。

 
function TCustomWebDispatcher.DispatchAction(Request: TWebRequest;
  Response: TWebResponse): Boolean;
var
  I: Integer;
  Action, Default: TWebActionItem;
  Dispatch: IWebDispatch;
begin
  FRequest := Request;
  FResponse := Response;
  I := 0;
  Default := nil;
  if Response.Sent then
  begin
    Result := True;
    { Note that WebSnapSvr enabled apps have no way to mark response as sent }
    Exit;
  end;
  Result := DoBeforeDispatch(Request, Response) or Response.Sent;
  while not Result and (I < FActions.Count) do
  begin
    Action := FActions[I];
    Result := Action.DispatchAction(Request, Response, False);
    if Action.Default then Default := Action;
    Inc(I);
  end;
  // Dispatch to self registering components
  I := 0;
  while not Result and (I < FDispatchList.Count) do
  begin
    if Supports(IInterface(FDispatchList.Items[I]), IWebDispatch, Dispatch) then
    begin
      Result := DispatchHandler(Self, Dispatch,
        Request, Response, False);
    end;
    Inc(I);
  end;
 
  if not Result and Assigned(Default) then
    Result := Default.DispatchAction(Request, Response, True);
  if Result and not Response.Sent then
    Result := DoAfterDispatch(Request, Response);
 
end;

如果前面没有中断,则执行下面的代码:

  // Dispatch to self registering components
  I := 0;
  while not Result and (I < FDispatchList.Count) do
  begin
    if Supports(IInterface(FDispatchList.Items[I]), IWebDispatch, Dispatch) then
    begin
      Result := DispatchHandler(Self, Dispatch,
        Request, Response, False);
    end;
    Inc(I);
  end;

因而执行Dispatch := DSHTTPWebDispatcher1(TDSHTTPWebDispatcher类),

DispatchHandler(): 这是一个局部方法


function DispatchHandler(Sender: TObject; Dispatch: IWebDispatch; Request: TWebRequest; Response: TWebResponse;
  DoDefault: Boolean): Boolean;
begin
  Result := False;
  if (Dispatch.Enabled and ((Dispatch.MethodType = mtAny) or
    (Request.MethodType = Dispatch.MethodType)) and
    Dispatch.Mask.Matches(string(Request.InternalPathInfo))) then
  begin
    Result := Dispatch.DispatchRequest(Sender, Request, Response);
  end;
end;

进行一些判断,比如格式 /data、/rest等路径格式,调用:


function TDSHTTPWebDispatcher.DispatchRequest(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse): Boolean;
begin
  try
    if Owner is TWebModule then
      DataSnapWebModule := TWebModule(Owner);
    try
      try
        RequiresServer;
        TDSHTTPServerWebBroker(Self.FHttpServer).DispatchDataSnap(Request, Response);
        Result := True;
      except
        on E: Exception do
        begin
          { Default to 500, like web services. }
          Response.StatusCode := 500;
          Result := True;
        end;
      end;
    except
      { Swallow any unexpected exception, it will bring down some web servers }
      Result := False;
    end;
  finally
    { Reset current DataSnapWebModule }
    DataSnapWebModule := nil;
  end;
end;

这里的RequiresServer()是调用祖先类的:

 
procedure TCustomDSRESTServerTransport.RequiresServer;
begin
  if FRestServer = nil then
  begin
    FRESTServer := CreateRESTServer;
    InitializeRESTServer;
  end;
end;
 
function TCustomDSHTTPServerTransport.CreateRESTServer: TDSRESTServer;
begin
  FHttpServer := CreateHttpServer;
  Result := FHttpServer;
end;
 
 
function TDSHTTPService.CreateHttpServer: TDSHTTPServer;
var
  LHTTPServer: TDSHTTPServerIndy;
begin
  if Assigned(FCertFiles) then
    LHTTPServer := TDSHTTPSServerIndy.Create(Self.Server, IPImplementationID)
  else
    LHTTPServer := TDSHTTPServerIndy.Create(Self.Server, IPImplementationID);
  Result := LHTTPServer;
  LHTTPServer.HTTPOtherContext := HTTPOtherContext;
end;

获得RestServer和httpServer。然后调用:


procedure TDSHTTPServerWebBroker.DispatchDataSnap(ARequest: TWebRequest;
  AResponse: TWebResponse);
var
  LDispatch: TDSHTTPDispatch;
  LContext: TDSHTTPContextWebBroker;
begin
  LDispatch := TDSHTTPApplication.Instance.HTTPDispatch;
  if LDispatch <> nil then
    DoCommand(LDispatch.Context, LDispatch.Request, LDispatch.Response)
  else
  begin
    LContext := TDSHTTPContextWebBroker.Create(ARequest, AResponse);
    try
      DoCommand(LContext, LContext.FRequest, LContext.FResponse);
    finally
      LContext.Free;
    end;
  end;
end;

又到了DoCommand()方法了

DoCommand():


procedure TDSRESTServer.DoCommand(AContext: TDSHTTPContext; ARequestInfo: TDSHTTPRequest;
                                  AResponseInfo: TDSHTTPResponse);
var
  Request: string;
  NextRequest: string;
  NextContext: string;
  RestCtxt: string;
  StartDispatch: Boolean;
begin

  // HTTPDispatch object if necessary
  StartDispatch := not TDSHTTPApplication.Instance.Dispatching;
  if StartDispatch then
    TDSHTTPApplication.Instance.StartDispatch(AContext, ARequestInfo, AResponseInfo);
  try
{$IFNDEF POSIX}
  if CoInitFlags = -1 then
    CoInitializeEx(nil, COINIT_MULTITHREADED)
  else
    CoInitializeEx(nil, CoInitFlags);
{$ENDIF}
  try
    // check for context, if not found send the appropriate error message
    Request := ARequestInfo.URI;
    if Consume(FDSContext, Request, NextRequest) then
    begin
      Request := NextRequest;
      if Consume(FRESTContext, Request, NextRequest) then
      begin
        // datasnap/rest
        DoDSRESTCommand(ARequestInfo, AResponseInfo, NextRequest);
      end
      else if ConsumeOtherContext(Request, NextContext, NextRequest) then
      begin
        DoDSOtherCommand(AContext, ARequestInfo, AResponseInfo, NextContext, NextRequest, FDSServerName <> EmptyStr);
      end
      else
      begin
        RestCtxt := Trim(FRESTContext);
        if RestCtxt = EmptyStr then
          RestCtxt := SProtocolRestEmpty;

        AResponseInfo.ResponseNo := 501; {rest or other service not found in URI}
        AResponseInfo.ContentText := Format(SProtocolNotSupported, [Request, RestCtxt]);
        AResponseInfo.CloseConnection := true;
      end;
    end
    else
    begin
      // This may dispatch .js files for example
      DoCommandOtherContext(AContext, ARequestInfo, AResponseInfo, Request);
    end;
    if Assigned(Self.FTrace ) then
    begin
      FTrace(Self, AContext, ARequestInfo, AResponseInfo);
    end;
  finally
                                                     
    ClearInvocationMetadata();
{$IFNDEF POSIX}
    CoUnInitialize;
{$ENDIF}
  end;
  finally
    if StartDispatch then
      TDSHTTPApplication.Instance.EndDispatch;
  end;
end;

看到处理路径包含 /datasnap/rest的处理:DoDSRESTCommand():

                            
// Entry point for rest.  Should be able to create session before calling this method
procedure TDSRESTServer.DoDSRESTCommand(ARequestInfo: TDSHTTPRequest;
                                        AResponseInfo: TDSHTTPResponse;
                                        Request: string);
var
  CmdType: TDSHTTPCommandType;
  ResponseOk: Integer;
  RESTService: TDSRESTService;
  Len: Integer;
  ParamName: string;
  SessionID: string;
  Session: TDSSession;
  IsNewSession: Boolean;
  SessionFailure: Boolean;
  RespHandler: TDSServiceResponseHandler;
  OwnService: Boolean;
begin
  OwnService := True;
  RespHandler := nil;

  CmdType := ARequestInfo.CommandType;
  ResponseOk := 200;

  RESTService := CreateRESTService(ARequestInfo.AuthUserName, ARequestInfo.AuthPassword);

  // process query parameters
  Len := 0;
  while (Len < ARequestInfo.Params.Count) and (ResponseOk < 300) do
  begin
    ParamName := ARequestInfo.Params.Names[Len];
    //check for session ID parameter in the URL
    if (Uppercase(ParamName) = 'SESSIONID') or (Uppercase(ParamName) = 'SID') then
    begin
      SessionID := ARequestInfo.Params.Values[ParamName]
    end
    else if not RESTService.ProcessQueryParameter(ParamName, ARequestInfo.Params.ValueFromIndex[Len]) then
    begin
      ResponseOK := 409;
      AResponseInfo.ResponseText := Format(CANNOT_PROCESS_PARAM, [ARequestInfo.Params.Names[Len],
                                           ARequestInfo.Params.Values[ARequestInfo.Params.Names[Len]]]);
    end;
    Inc(Len);
  end;
  if (ResponseOK < 300) and not RESTService.CheckConvertersForConsistency then
  begin
    // 409 - Indicates that the request could not be processed because of conflict in the request
    AResponseInfo.ResponseNo := 409;
    AResponseInfo.ResponseText := QUERY_PARAM_CONFLICT;
  end;

  //if no session ID is given in the URL, then try to load it from the Pragma header field
  if SessionID = EmptyStr then
  begin
    SessionID := TDSHTTPApplication.Instance.GetRequestSessionId(aRequestInfo, False);
  end;

  //Try to load the session with the given session ID into the current thread
  SessionFailure :=
     not TDSHTTPApplication.FInstance.LoadRESTSession(SessionID, ARequestInfo.AuthUserName, FSessionTimeout, FSessionLifetime,
                           nil (*FTunnelService*), FDSHTTPAuthenticationManager, ARequestInfo,
                           IsNewSession);
  Session := TDSSessionManager.GetThreadSession;

  //free any stream which was stored from a previous execution
  if Session <> nil then
  begin
    Session.LastResultStream.Free;
    Session.LastResultStream := nil;

    if not SessionFailure then
      UpdateSessionTunnelHook(Request, Session, ARequestInfo);
  end;

  if not SessionFailure and IsClosingSession(Request) then
  begin
    try
      CloseRESTSession(Session, AResponseInfo);
    finally
      FreeAndNil(RESTService);
                                                                         
      TDSSessionManager.ClearThreadSession;
    end;
    exit;
  end;

  try
    if SessionFailure then
    begin
      AResponseInfo.ResponseNo := 403; //Forbidden
      AResponseInfo.ResponseText := SESSION_EXPIRED;
      AResponseInfo.ContentText := '{"SessionExpired":"' + SSessionExpiredMsg + '"}';
    end
    else if ResponseOK >= 300 then
    begin
      // pre-parsing failed and the decision is in ResponseOK, response text already set
      AResponseInfo.ResponseNo := ResponseOK;
    end
    //don't need to authenticate if returning to a previously authenticated session
    else if (FDSHTTPAuthenticationManager <> nil) and IsNewSession and not FDSHTTPAuthenticationManager.Authenticate(
                    DATASNAP_CONTEXT, RESTContext, ARequestInfo.AuthUserName, ARequestInfo.AuthPassword,
                      ARequestInfo, AResponseInfo) then
      if ARequestInfo.AuthUserName <> EmptyStr then
        AResponseInfo.ResponseNo := 403
      else
      begin
        AResponseInfo.SetHeaderAuthentication('Basic', 'REST');
        AResponseInfo.ResponseNo := 401
      end
    else
    begin
      if Session <> nil then
      begin
        AResponseInfo.Pragma := 'dssession=' + Session.SessionName;
        AResponseInfo.Pragma := AResponseInfo.Pragma + ',dssessionexpires=' + IntToStr(Session.ExpiresIn);
      end;

      OwnService := False;
      //create the response handler for populating the response info
      RespHandler := TDSResponseHandlerFactory.CreateResponseHandler(RESTService, ARequestInfo, TDSHTTPCommandType.hcUnknown, Self);
      if RespHandler = nil then
      begin
        AResponseInfo.ResponseNo := 406; //Not Acceptable
      end
      else
      begin
        if RespHandler is  TDSServiceResponseHandler then
        begin
          TDSServiceResponseHandler(RespHandler).OnParseRequest := Self.OnParseRequest;
          TDSServiceResponseHandler(RespHandler).OnParsingRequest := Self.OnParsingRequest;
        end;

        //add the query parameters to invocation metadata
        if ARequestInfo.Params.Count > 0 then
          GetInvocationMetadata().QueryParams.AddStrings(ARequestInfo.Params);

        // dispatch to the appropriate service
        case CmdType of
          TDSHTTPCommandType.hcGET:
            RESTService.ProcessGETRequest(Request, nil, nil, OnNameMap, RespHandler);
          TDSHTTPCommandType.hcPOST:
            RESTService.ProcessPOSTRequest(Request, ARequestInfo.Params,
              ByteContent(ARequestInfo.PostStream), OnNameMap, RespHandler);
          TDSHTTPCommandType.hcPUT:
            RESTService.ProcessPUTRequest(Request, ARequestInfo.Params,
              ByteContent(ARequestInfo.PostStream), OnNameMap, RespHandler);
          TDSHTTPCommandType.hcDELETE:
            RESTService.ProcessDELETERequest(Request, nil, nil, OnNameMap, RespHandler);
          else
          begin
            GetInvocationMetadata().ResponseCode := 501;
            GetInvocationMetadata().ResponseContent := Format(SCommandNotSupported, [ARequestInfo.Command]);
          end;
        end;

        //populate the Response Info from the execution result
        RespHandler.PopulateResponse(AResponseInfo, GetInvocationMetadata());
      end;
    end;
  finally
    if RespHandler = nil then
      FreeAndNil(RESTService);

    if RespHandler <> nil then
      RespHandler.Close;

    if OwnService then
      FreeAndNil(RESTService);

                                    
    if (GetInvocationMetadata(False) <> nil) and
         GetInvocationMetadata.CloseSession and
        (TDSSessionManager.GetThreadSession <> nil) then
    begin
      if TDSSessionManager.GetThreadSession.SessionName <> '' then
        TDSSessionManager.Instance.CloseSession(TDSSessionManager.GetThreadSession.SessionName);
      TDSSessionManager.ClearThreadSession;
    end;
    // Session cleared by TDSHTTPApplication.EndDispatch
    // TDSSessionManager.ClearThreadSession;
  end;
end;

这个方法比较啰嗦,要处理各种情况和格式

自动判别命令类型并分别处理:

        // dispatch to the appropriate service
        case CmdType of
          TDSHTTPCommandType.hcGET:
            RESTService.ProcessGETRequest(Request, nil, nil, OnNameMap, RespHandler);
          TDSHTTPCommandType.hcPOST:
            RESTService.ProcessPOSTRequest(Request, ARequestInfo.Params,
              ByteContent(ARequestInfo.PostStream), OnNameMap, RespHandler);
          TDSHTTPCommandType.hcPUT:
            RESTService.ProcessPUTRequest(Request, ARequestInfo.Params,
              ByteContent(ARequestInfo.PostStream), OnNameMap, RespHandler);
          TDSHTTPCommandType.hcDELETE:
            RESTService.ProcessDELETERequest(Request, nil, nil, OnNameMap, RespHandler);
          else
          begin
            GetInvocationMetadata().ResponseCode := 501;
            GetInvocationMetadata().ResponseContent := Format(SCommandNotSupported, [ARequestInfo.Command]);
          end;
        end;

比如Get:


procedure TDSRESTService.ProcessGETRequest(const Request: string; Params: TStrings; Content: TArray<Byte>;
  const NameMapEvent: TDSRESTMethodNameMapEvent; ResponseHandler: TRequestCommandHandler);
begin
  ProcessREST('GET', Request, nil, NameMapEvent, ResponseHandler);
end;


procedure TDSRESTService.ProcessREST(const RequestType: string;
                                     const RestRequest: string;
                                     const Content: TArray<Byte>;
                                     const NameMapEvent: TDSRESTMethodNameMapEvent;
                                     const ResponseHandler: TRequestCommandHandler);

var
  Params, Segments: TStrings;
  ClassName, MethodName, DSMethodName: string;
  LHandled: Boolean;
  I: Integer;
begin
  Segments := TStringList.Create;
  Params := TStringList.Create;
  try
    try
      // get class, method name, parameters
      LHandled := False;

      ParseRequestSegments(RestRequest, Segments);
      if ResponseHandler is TDSServiceResponseHandler then
        TDSServiceResponseHandler(ResponseHandler).DoParsingRequest(Self,
          RequestType, Segments, DSMethodName, Params, LHandled);
      if not LHandled then
      begin
        if Segments.Count < 2 then
          raise TDSServiceException.Create(SInvalidRequestFormat);
        ClassName := Segments[0];
        MethodName := Segments[1];
        if (ClassName = '') or (MethodName = '') then
          raise TDSServiceException.Create(SInvalidRequestFormat);
        for I := 2 to Segments.Count - 1 do
          Params.Add(Segments[I]);
        SetMethodNameWithPrefix(RequestType, ClassName, MethodName, NameMapEvent, DSMethodName);
      end;
      if ResponseHandler is TDSServiceResponseHandler then
        TDSServiceResponseHandler(ResponseHandler).DoParseRequest(Self,
          RequestType, Segments, DSMethodName, Params);

      ProcessRequest(DSMethodName, ResponseHandler,
        procedure(var AConnection: TDBXConnection; var ACommand: TDBXCommand;
          const ResponseHandler: TRequestCommandHandler)
        begin
          ProcessParameters(DSMethodName, Params, Content, ACommand);
          ACommand.ExecuteUpdate;

          ResponseHandler.AddCommand(ACommand, AConnection); // Owns
          ACommand := nil;
          AConnection := nil;

        end);
    except
      on ex: Exception do
        ProcessException(ResponseHandler, ex);
    end;
  finally
    Params.Free;
    Segments.Free;
  end;
end;

转到:


procedure TDSService.ProcessRequest(const ACommand: string; const AResponseHandler: TRequestCommandHandler; ACallback: TExecuteCallback);
begin
  try
    Execute(ACommand, AResponseHandler, ACallback) //, ResponseHandler);
  except
    on ex: Exception do
      ProcessException(AResponseHandler, ex);
  end;
end;

                                                                                            
procedure TDSService.Execute(const ACommand: string; const AResponseHandler: TRequestCommandHandler; ACallback: TExecuteCallback);
var
    DBXConnection: TDBXConnection;
    DBXCommand: TDBXCommand;
begin
  DBXCommand := nil;

  DBXConnection := GetDBXConnection;
  try
    DBXCommand := DBXConnection.CreateCommand;
    DBXCommand.CommandType := TDBXCommandTypes.DSServerMethod;

    DBXCommand.Text := ACommand;
    DBXCommand.Prepare;

    ACallback(DBXConnection, DBXCommand, AResponseHandler);
  finally

    if DBXCommand <> nil then
      DBXCommand.Close;

    if DBXConnection <> nil then
      DBXConnection.Close;

    DBXCommand.Free;

    DBXConnection.Free;
  end;
end;

客户端的方法调用处理比较繁杂

可以看到DataSnap内部的处理还是依赖 DBX框架。
 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/441329.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

详解C语言string.h中常见的13个库函数(上)

我计划讲解C语言string.h这个头文件中&#xff0c;最常见的13个库函数。为了让大家更加深入的理解这些函数&#xff0c;部分函数我会模拟实现。篇幅所限&#xff0c;如果文章太长了&#xff0c;可能会较难坚持读完&#xff0c;所以我会分几篇博客来讲述。本篇博客主要讲解的函数…

什么是全民开发?|概念、技能和优势

注&#xff1a;全民开发的英文是Citizen Development&#xff0c;由咨询公司Gartner在2010年提出的概念&#xff0c;指非专业开发人员使用低代码或无代码平台创建应用程序&#xff0c;无需IT部门的支持&#xff0c;旨在提高生产力并降低开发成本。 国内普遍将Citizen Developme…

【ROS】单目摄像机的标定

在上节: ROS 教程之 vision : 用笔记本摄像头获取图像 能够使用相机后&#xff0c;就需要对相机进行标定&#xff0c;在ROS上使用原始图像校准单目相机。 操作步骤 1、首先将catkin_ws/src/usb_cam/launch/usb_cam-test.launch的文件内容修改掉。 原有内容&#xff1a; <…

docker 使用Dockerfile 部署springboot项目

1、先准备好你的springboot项目jar包。拉取 openjdk docker pull openjdk:8-jdk-alpine 2、上传你的springboot项目&#xff0c;然后配置 Dockerfile&#xff1a; FROM openjdk:8-jdk-alpine ADD ./springbootstudy.jar.jar /app.jar ENTRYPOINT ["java","-jar…

【源码】Spring Cloud Gateway 是在哪里匹配路由的?

我们知道&#xff0c;经过网关的业务请求会被路由到后端真实的业务服务上去&#xff0c;假如我们使用的是Spring Cloud Gateway&#xff0c;那么你知道Spring Cloud Gateway是在哪一步去匹配路由的吗&#xff1f; 源码之下无秘密&#xff0c;让我们一起从源码中寻找答案。 入…

Ant Design 常见用法与坑点总结(二):Form 表单下拉框设置初始值

前言 Ant Design 是蚂蚁出品的出色优秀的 React 组件库&#xff0c;相信使用 React 进行管理系统开发的小伙伴们或多或少都接触过 Ant Design。很多公司基于 React 开发的管理端系统也都是使用 Ant Design 的组件库。 因此&#xff0c;了解 Ant Design 的常见用法与坑点还是有…

react中如何系统化的处理时间操作?

在 Web 开发中&#xff0c;我们经常需要处理日期和时间的格式化。 在 React 中&#xff0c;这个过程变得更加容易和直观&#xff0c;因为我们可以使用一个叫做 moment 的 npm 包来帮助我们完成这个任务。 什么是 Moment? Moment.js是一个JavaScript库&#xff0c;用于处理日…

使用FFMPEG库将PCM编码为AAC

准备 ffmpeg 版本4.4 准备一段48000Hz 2 channel f32le 格式的PCM原始数据 这里我们直接使用ffmpeg命令行提取 ffmpeg -i beautlWorld.mp4 -ar 48000 -ac 2 -f f32le 48000_2_f32le.pcm -ac 采样率 -ac 音频通道 -f f32le 音频样本数据存储格式&#xff08;f32 ---- float…

【OJ比赛日历】快周末了,不来一场比赛吗? #04.22-04.28 #11场

CompHub 实时聚合多平台的数据类(Kaggle、天池…)和OJ类(Leetcode、牛客…&#xff09;比赛。本账号同时会推送最新的比赛消息&#xff0c;欢迎关注&#xff01; 更多比赛信息见 CompHub主页 或 点击文末阅读原文 以下信息仅供参考&#xff0c;以比赛官网为准 目录 2023-04-22&…

程序员最新赚钱指南!

程序员们的主要收入来源 1️⃣首先&#xff0c;我们要明白程序员无论编程开发多么努力&#xff0c;随着时间推移&#xff0c;受年龄、生活、健康等因素&#xff0c;程序员们都会面临职业天花板&#xff0c;这是大多数人不可规避的一个事实。 2️⃣其次&#xff0c;这几年因为…

【Python】【进阶篇】二十三、Python爬虫的Selenium库

目录 二十三、Python爬虫的Selenium库23.1 Selenium下载安装23.2 安装浏览器驱动23.3 自动访问百度 二十三、Python爬虫的Selenium库 Selenium 是一个用于测试 Web 应用程序的自动化测试工具&#xff0c;它直接运行在浏览器中&#xff0c;实现了对浏览器的自动化&#xff0c;它…

集群和分布式

本文以即时通讯软件&#xff08;IM&#xff09;为例&#xff0c;介绍单机、集群、分布式的区别&#xff0c;以及它们各自的优缺点。 假设现在开发一款IM&#xff0c;刚开始业务比较简单&#xff0c;用户量也较少&#xff0c;我们将服务部署在一台单机服务器上足矣。软件开发过程…

【从零开始学Skynet】实战篇《球球大作战》(十):agent代码设计

现在开发登录流程涉及的最后一个服务agent&#xff0c;完成后就可以真正地把框架运行起来了。还会演示agent的单机功能&#xff0c;做个“打工”小游戏。 1、消息分发 玩家登录后&#xff0c;gateway会将客户端协议转发给agent&#xff08;流程图的阶段⑨&#xff09;。 新建se…

第五章-数字水印-1-位平面

数字水印概念 数字水印是一种将特定数字信息嵌入到数字作品中从而实现信息隐藏、版权认证、完整性认证、数字签名等功能的技术。 以图片水印为例: 水印嵌入过程:版权信息水印A嵌入到图像B中,得到含有水印的图像C,图像C与图像B在外观上基本一致&#xff0c;肉眼无法区分差异。…

OpenHarmony的线程间通信EventHandler

一、初识EventHandler ​ 在OpenHarmony的开发过程中&#xff0c;如果遇到处理下载、运算等较为耗时的操作时&#xff0c;会阻塞当前线程&#xff0c;但是实际操作中又不希望当前线程受到阻塞。比如&#xff1a;我们的app在界面上有一个下载文件的处理按钮&#xff0c;如果在按…

计算机网络基础 第三章练习题

计算机网络基础 第三章练习题 现在大量的计算机是通过诸如以太网这样的局域网连入广域网的&#xff0c;而局域网与广城网的互联是通过( A)实现的。 A. 路由器B. 资源子网C. 桥接器D. 中继器 下列不属于数据链路层功能的是(B )。 A. 帧定界功能B. 电路管理功能C. 差错控制功能D…

HCIP——交换

交换 园区网架构 交换机实现了一下功能 无限的传输距离——识别&#xff0c;重写电信号&#xff08;帧&#xff09;保证信息完整彻底解决了冲突二层单播——MAC地址表提高端口密度 MAC 单播地址&#xff1a;MAC地址第一个字节第8位为0 组播地址&#xff1a;MAC地址第一个字…

Camera | 8.让rk3568支持前后置摄像头

一、目标 本文主要目标是&#xff0c;支持前置摄像头0v5648、后置摄像头ov13850&#xff0c;以及移植过程遇到的一些小问题的解决。 1. 摄像头连接图 参考上图&#xff0c;摄像头详细信息如下&#xff1a; 2个摄像头均连接在I2C通道42个摄像头共用同一个MIPI数据通道2个摄像…

C++——探究引用

文章目录 概述引用的概念引用特性引用的作用**引用做参数****引用作为函数返回值** 常引用引用的底层实现总结一下引用和指针的不同点 概述 本篇博客将讲述c相对于c新增的一个重要的内容——引用&#xff0c;深入研究其语法细节以及其需要注意的一些要点。 引用的概念 竟然要学…