首页 > 解决方案 > Datastax中分页状态(作为字符串)的格式是什么

问题描述

对于我的单元测试,我需要创建一个虚拟PagingState值。

https://docs.datastax.com/en/latest-java-driver-api/com/datastax/driver/core/PagingState.html

我可以看到有一种fromString方法可以PagingState为我创建对象。但我需要以正确的格式提供字符串。

的格式是PagingState什么?

我读到了The paging state is a array of 16 bytes。我尝试执行以下操作

val pagingStateByteArray = Array[Byte](1.toByte,2.toByte,3.toByte,4.toByte,5.toByte,6.toByte,7.toByte,8.toByte,9.toByte,10.toByte,11.toByte,12.toByte,13.toByte,14.toByte,15.toByte,16.toByte)
  val pagingState = PagingState.fromBytes(pagingStateByteArray) //make this more accurate. instance of PagingState

但有错误

Cannot deserialize paging state, invalid format. The serialized form was corrupted, or not initially generated from a PagingState object.
com.datastax.driver.core.exceptions.PagingStateException: Cannot deserialize paging state, invalid format. The serialized form was corrupted, or not initially generated from a PagingState object.
    at com.datastax.driver.core.PagingState.<init>(PagingState.java:60)
    at com.datastax.driver.core.PagingState.fromBytes(PagingState.java:170)

标签: datastax-java-driver

解决方案


分页状态对驱动程序(源代码)有意义,因此您需要提供有意义的值。

但是对于您的测试,您可以使用Java 驱动程序测试中使用的相同值:

PagingState emptyStatement = PagingState.fromString("00000000");;

推荐阅读