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
use handlebars::{ | |
to_json, BlockContext, BlockParams, Context, Handlebars, Helper, HelperDef, HelperResult, | |
Output, PathAndJson, RenderContext, RenderError, RenderErrorReason, Renderable, | |
}; | |
use serde_json::value::Value as Json; | |
use std::collections::HashMap; | |
use std::fmt::format; | |
use sxd_document::parser; | |
use sxd_xpath::evaluate_xpath; | |
use sxd_xpath::nodeset::Node; |
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
.evalMap(req => { | |
println(req.headers) | |
println(req) | |
httpClientBuilder.resource | |
.map(Metrics(Prometheus(registry, "client").unsafeRunSync(), requestMethodClassifier)(_)) | |
.use(.expect[String](req)) //.map(.withContentType(Content-Type.apply(MediaType.text))) | |
}) |
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
implicit val config: Configuration = Configuration.default | |
implicit val eventTypeDecoder = ProtobufEnumDecoder.create(PointerEvent.forNumber) | |
@ConfiguredJsonCodec(decodeOnly = true) case class SingleEvent( | |
@JsonKey("ts") timestamp: Long, | |
@JsonKey("x") x: Float, | |
@JsonKey("y") y: Float, | |
@JsonKey("pe") pointerEvent: PointerEvent | |
) |
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
implicit val singleEventDecoder = deriveDecoder[SingleEvent] | |
implicit val eventTypeDecoder = ProtobufEnumDecoder.create(PointerEvent.forNumber) | |
case class SingleEvent( | |
timestamp: Long, | |
x: Float, | |
y: Float, | |
pointerEvent: PointerEvent | |
) |
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
object ProtobufEnumDecoder { | |
def create[T](decodingFunction: Int => T)(implicit manifest: Manifest[T]) = new Decoder[T] { | |
private val enumName = manifest.runtimeClass.getSimpleName | |
override def apply(c: HCursor): Result[T] = | |
c.value.as[Int].right flatMap { i => | |
val enum = decodingFunction(i) | |
if (enum == null) | |
Left(DecodingFailure(s"$i is not a valid value for this enum '$enumName'", Nil)) | |
else Right(enum) | |
} |
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
case class CustomStructure(a: Int) | |
object MyDecoders { | |
implicit customDecoder = deriveDecoder[CustomStructure] | |
} | |
object Main { | |
import MyDecoders._ | |
val decoded: CustomStructure = decode[CustomStructure]("{a:1}") | |
} |
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
/* | |
* Class used to generically deserialize Protobuf enums in Jackson | |
* The exception thrown is caught by Jackson, and error messages belong to the same layer | |
* as the other json deserialization errors. | |
*/ | |
class EnumFieldWrapper[T <: ProtocolMessageEnum](forNumber: Int => T, underlying: Int) { | |
val underlyingEnum = { | |
val enum = forNumber(underlying) | |
if (enum == null) | |
throw new Exception(s"$underlying is not a valid value for this enum") |
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
case class RawPointerEvent( | |
@JsonProperty("ts") timestamp: Int, | |
@JsonProperty("x") x: Int, | |
@JsonProperty("y") y: Int, | |
@JsonProperty("pe") pointerEvent: Int //Protobuf enum | |
) |