示例#1
0
void cParser::Parse(unsigned char *data, int datasize, bool pusi)
{
  // get available data
  int length = 0;
  uint8_t* buffer = Get(length);

  // do we have a sync ?
  int framesize = 0;
  if(length > m_headersize && buffer != NULL && CheckAlignmentHeader(buffer, framesize))
  {
    if(framesize > 0 && length >= framesize)
    {
      ParsePayload(buffer, framesize);
      SendPayload(buffer, framesize);

      m_curPTS = PtsAdd(m_curPTS, m_duration);
      m_curDTS = PtsAdd(m_curDTS, m_duration);

      Del(framesize);
    }

    PutData(data, datasize, pusi);
    return;
  }

  // try to find sync
  int offset = FindAlignmentOffset(buffer, length, 0, framesize);
  if(offset != -1)
  {
    INFOLOG("sync found at offset %i (streamtype: %s / %i bytes in buffer / framesize: %i bytes)", offset, m_demuxer->TypeName(), Available(), framesize);
    Del(offset);
  }

  PutData(data, datasize, pusi);
}
const FirebaseError FirebaseCloudMessaging::SendMessageToUser(
    const std::string& registration_id,
    const FirebaseCloudMessage& message) {
  DynamicJsonBuffer buffer;
  JsonObject& root = buffer.createObject();
  root["to"] = registration_id.c_str();

  AddToJson(message, root);

  char payload[root.measureLength() + 1];
  root.printTo(payload, sizeof(payload));
  return SendPayload(payload);
}
const FirebaseError FirebaseCloudMessaging::SendMessageToTopic(
    const std::string& topic, const FirebaseCloudMessage& message) {
  std::string to("/topics/");
  to += topic;

  DynamicJsonBuffer buffer;
  JsonObject& root = buffer.createObject();
  root["to"] = to.c_str();

  AddToJson(message, root);

  char payload[root.measureLength() + 1];
  root.printTo(payload, sizeof(payload));
  return SendPayload(payload);
}
const FirebaseError FirebaseCloudMessaging::SendMessageToUsers(
    const std::vector<std::string>& registration_ids,
    const FirebaseCloudMessage& message) {
  DynamicJsonBuffer buffer;
  JsonObject& root = buffer.createObject();
  JsonArray& ids = root.createNestedArray("registration_ids");
  for (const std::string& id : registration_ids) {
    ids.add(id.c_str());
  }

  AddToJson(message, root);

  char payload[root.measureLength() + 1];
  root.printTo(payload, sizeof(payload));
  return SendPayload(payload);
}
bool FNetworkFileServerClientConnection::ProcessPayload(FArchive& Ar)
{
	FBufferArchive Out;
	bool Result = true;

	// first part of the payload is always the command
	uint32 Cmd;
	Ar << Cmd;

	UE_LOG(LogFileServer, Verbose, TEXT("Processing payload with Cmd %d"), Cmd);

	// what type of message is this?
	NFS_Messages::Type Msg = NFS_Messages::Type(Cmd);

	// make sure the first thing is GetFileList which initializes the game/platform
	checkf(Msg == NFS_Messages::GetFileList || Msg == NFS_Messages::Heartbeat || Sandbox != NULL, TEXT("The first client message MUST be GetFileList, not %d"), (int32)Msg);

	// process the message!
	bool bSendUnsolicitedFiles = false;

	{
		FScopeLock SocketLock(&SocketCriticalSection);

		switch (Msg)
		{
		case NFS_Messages::OpenRead:
			ProcessOpenFile(Ar, Out, false);
			break;

		case NFS_Messages::OpenWrite:
			ProcessOpenFile(Ar, Out, true);
			break;

		case NFS_Messages::Read:
			ProcessReadFile(Ar, Out);
			break;

		case NFS_Messages::Write:
			ProcessWriteFile(Ar, Out);
			break;

		case NFS_Messages::Seek:
			ProcessSeekFile(Ar, Out);
			break;

		case NFS_Messages::Close:
			ProcessCloseFile(Ar, Out);
			break;

		case NFS_Messages::MoveFile:
			ProcessMoveFile(Ar, Out);
			break;

		case NFS_Messages::DeleteFile:
			ProcessDeleteFile(Ar, Out);
			break;

		case NFS_Messages::GetFileInfo:
			ProcessGetFileInfo(Ar, Out);
			break;

		case NFS_Messages::CopyFile:
			ProcessCopyFile(Ar, Out);
			break;

		case NFS_Messages::SetTimeStamp:
			ProcessSetTimeStamp(Ar, Out);
			break;

		case NFS_Messages::SetReadOnly:
			ProcessSetReadOnly(Ar, Out);
			break;

		case NFS_Messages::CreateDirectory:
			ProcessCreateDirectory(Ar, Out);
			break;

		case NFS_Messages::DeleteDirectory:
			ProcessDeleteDirectory(Ar, Out);
			break;

		case NFS_Messages::DeleteDirectoryRecursively:
			ProcessDeleteDirectoryRecursively(Ar, Out);
			break;

		case NFS_Messages::ToAbsolutePathForRead:
			ProcessToAbsolutePathForRead(Ar, Out);
			break;

		case NFS_Messages::ToAbsolutePathForWrite:
			ProcessToAbsolutePathForWrite(Ar, Out);
			break;

		case NFS_Messages::ReportLocalFiles:
			ProcessReportLocalFiles(Ar, Out);
			break;

		case NFS_Messages::GetFileList:
			Result = ProcessGetFileList(Ar, Out);
			break;

		case NFS_Messages::Heartbeat:
			ProcessHeartbeat(Ar, Out);
			break;

		case NFS_Messages::SyncFile:
			ProcessSyncFile(Ar, Out);
			bSendUnsolicitedFiles = true;
			break;

		case NFS_Messages::RecompileShaders:
			ProcessRecompileShaders(Ar, Out);
			break;

		default:

			UE_LOG(LogFileServer, Error, TEXT("Bad incomming message tag (%d)."), (int32)Msg);
		}
	}


	// send back a reply if the command wrote anything back out
	if (Out.Num() && Result )
	{
		int32 NumUnsolictedFiles = UnsolictedFiles.Num();
		if (bSendUnsolicitedFiles)
		{
			Out << NumUnsolictedFiles;
		}

		UE_LOG(LogFileServer, Verbose, TEXT("Returning payload with %d bytes"), Out.Num());

		// send back a reply
		Result &= SendPayload( Out );

		if (bSendUnsolicitedFiles && Result )
		{
			for (int32 Index = 0; Index < NumUnsolictedFiles; Index++)
			{
				FBufferArchive OutUnsolicitedFile;
				PackageFile(UnsolictedFiles[Index], OutUnsolicitedFile);

				UE_LOG(LogFileServer, Display, TEXT("Returning unsolicited file %s with %d bytes"), *UnsolictedFiles[Index], OutUnsolicitedFile.Num());

				Result &= SendPayload(OutUnsolicitedFile);
			}

			UnsolictedFiles.Empty();
		}
	}

	UE_LOG(LogFileServer, Verbose, TEXT("Done Processing payload with Cmd %d Total Size sending %d "), Cmd,Out.TotalSize());

	return Result;
}
示例#6
0
		void Send(Connection *pConnection) const
		{
			send_context_t ctxt=BeginSend(pConnection);
			SendPayload(pConnection);
			EndSend(pConnection, ctxt);
		}