ledger-offset: Add a conversion to ByteString. (#11491)

* ledger-offset: Add a conversion to ByteString.

I seem to be doing this a lot.

CHANGELOG_BEGIN
CHANGELOG_END

* ledger-offset: Add a conversion from ByteString.
This commit is contained in:
Samir Talwar 2021-11-03 10:54:23 +01:00 committed by GitHub
parent 8a9f15b8de
commit bda35ca234
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,6 +7,7 @@ import java.io.InputStream
import com.daml.lf.data.{Bytes, Ref}
import com.daml.logging.entries.{LoggingValue, ToLoggingValue}
import com.google.protobuf.ByteString
/** Offsets into streams with hierarchical addressing.
*
@ -25,6 +26,8 @@ final case class Offset(bytes: Bytes) extends Ordered[Offset] {
override def compare(that: Offset): Int =
Bytes.ordering.compare(this.bytes, that.bytes)
def toByteString: ByteString = bytes.toByteString
def toByteArray: Array[Byte] = bytes.toByteArray
def toInputStream: InputStream = bytes.toInputStream
@ -33,7 +36,9 @@ final case class Offset(bytes: Bytes) extends Ordered[Offset] {
}
object Offset {
val beforeBegin: Offset = Offset.fromByteArray(Array.empty[Byte])
val beforeBegin: Offset = new Offset(Bytes.Empty)
def fromByteString(bytes: ByteString) = new Offset(Bytes.fromByteString(bytes))
def fromByteArray(bytes: Array[Byte]) = new Offset(Bytes.fromByteArray(bytes))