All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.jeroenr.tepkin.protocol.command.Command.scala Maven / Gradle / Ivy

package com.github.jeroenr.tepkin.protocol.command

import akka.util.ByteString
import com.github.jeroenr.bson.BsonDocument
import com.github.jeroenr.tepkin.protocol.message.Message

/**
 * A MongoDB Command.
 *
 * Basically, it is a query that is performed on any db.\$cmd collection.
 */
trait Command extends Message {

  override val responseTo: Int = 0

  override val opCode: Int = 2004

  def databaseName: String

  def command: BsonDocument

  override def encodeBody: ByteString = {
    val flags: Int = 0

    ByteString.newBuilder
      .putInt(flags)
      .putBytes((databaseName + ".$cmd").getBytes("utf-8"))
      .putByte(0)
      .putInt(0) // numberToSkip
      .putInt(1) // numberToReturn
      .append(command.encode)
      .result()
  }
}

/**
 * A command that targets the admin database only (administrative commands).
 */
trait AdminCommand extends Command {
  override def databaseName: String = "admin"
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy