def fromBytes()

in s2core/src/main/scala/org/apache/s2graph/core/types/v1/InnerVal.scala [69:116]


  def fromBytes(bytes: Array[Byte], offset: Int, len: Int, version: String = DEFAULT_VERSION, isVertexId: Boolean = false): (InnerVal, Int) = {
    var pos = offset
    //
    val header = bytes(pos)
    //      logger.debug(s"${bytes(offset)}: ${bytes.toList.slice(pos, bytes.length)}")
    pos += 1

    var numOfBytesUsed = 0
    val (longV, strV, boolV) = metaByteRev.get(header) match {
      case Some(s) =>
        s match {
          case "default" =>
            (None, None, None)
          case "true" =>
            numOfBytesUsed = 0
            (None, None, Some(true))
          case "false" =>
            numOfBytesUsed = 0
            (None, None, Some(false))
          case "byte" =>
            numOfBytesUsed = 1
            val b = bytes(pos)
            val value = if (b >= 0) Byte.MaxValue - b else Byte.MinValue - b - 1
            (Some(value.toLong), None, None)
          case "short" =>
            numOfBytesUsed = 2
            val b = Bytes.toShort(bytes, pos, 2)
            val value = if (b >= 0) Short.MaxValue - b else Short.MinValue - b - 1
            (Some(value.toLong), None, None)
          case "int" =>
            numOfBytesUsed = 4
            val b = Bytes.toInt(bytes, pos, 4)
            val value = if (b >= 0) Int.MaxValue - b else Int.MinValue - b - 1
            (Some(value.toLong), None, None)
          case "long" =>
            numOfBytesUsed = 8
            val b = Bytes.toLong(bytes, pos, 8)
            val value = if (b >= 0) Long.MaxValue - b else Long.MinValue - b - 1
            (Some(value.toLong), None, None)
        }
      case _ => // string
        val strLen = header - stringLenOffset
        numOfBytesUsed = strLen
        (None, Some(Bytes.toString(bytes, pos, strLen)), None)
    }

    (InnerVal(longV, strV, boolV), numOfBytesUsed + 1)
  }