-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reference commit: 19985bc98f Co-authored-by: Canton <[email protected]>
- Loading branch information
1 parent
8068166
commit 85b4647
Showing
543 changed files
with
4,126 additions
and
2,726 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...se/src/main/scala/com/digitalasset/canton/console/commands/ByteStringStreamObserver.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.digitalasset.canton.console.commands | ||
|
||
import com.digitalasset.canton.discard.Implicits.DiscardOps | ||
import com.google.protobuf.ByteString | ||
import io.grpc.stub.StreamObserver | ||
|
||
import java.util.concurrent.atomic.AtomicReference | ||
import scala.concurrent.{Future, Promise} | ||
import scala.language.reflectiveCalls | ||
|
||
private[commands] class ByteStringStreamObserver[ | ||
T <: ByteStringStreamObserver.ByteStringChunk | ||
] extends StreamObserver[T] { | ||
private val byteBuffer = new AtomicReference(Vector.empty[Byte]) | ||
private val requestComplete: Promise[ByteString] = Promise[ByteString]() | ||
|
||
def result: Future[ByteString] = | ||
requestComplete.future | ||
|
||
override def onNext(value: T): Unit = | ||
byteBuffer.getAndUpdate(_ ++ value.chunk.toByteArray).discard | ||
|
||
override def onError(t: Throwable): Unit = { | ||
requestComplete.tryFailure(t).discard | ||
} | ||
|
||
override def onCompleted(): Unit = { | ||
val finalByteString = ByteString.copyFrom(byteBuffer.get().toArray) | ||
requestComplete.trySuccess(finalByteString).discard | ||
} | ||
} | ||
|
||
private[commands] object ByteStringStreamObserver { | ||
type ByteStringChunk = { val chunk: ByteString } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.