Skip to content

Commit

Permalink
Merge pull request #236 from disneystreaming/update-protobufTimestamp…
Browse files Browse the repository at this point in the history
…Format-translation

Update translation of protoTimestampFormat
  • Loading branch information
Baccata committed Mar 14, 2024
2 parents e3f72b1 + 047ce84 commit 5502e0c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
2 changes: 1 addition & 1 deletion buildDeps.sc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import mill.define._
import mill.scalalib._

object alloy {
val alloyVersion = "0.3.3"
val alloyVersion = "0.3.3-1-88e46a-SNAPSHOT"
val core =
ivy"com.disneystreaming.alloy:alloy-core:$alloyVersion"
val protobuf =
Expand Down
8 changes: 8 additions & 0 deletions buildSetup.sc
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ trait BaseScala213Module extends BaseScalaModule with ScalafmtModule {

trait BaseScalaModule extends ScalaModule with BaseModule {

override def repositoriesTask = T.task {
super.repositoriesTask() ++ Seq(
coursier.maven.MavenRepository(
"https://s01.oss.sonatype.org/content/repositories/snapshots/"
)
)
}

override def scalacPluginIvyDeps = T {
val sv = scalaVersion()
val plugins =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import software.amazon.smithy.model.neighbor.Walker
import alloy.OpenEnumTrait
import software.amazon.smithy.model.traits.EnumValueTrait
import alloy.proto.ProtoTimestampFormatTrait
import alloy.proto.ProtoTimestampFormatTrait.TimestampFormat

private[proto3] class Compiler(model: Model, allShapes: Boolean) {

Expand Down Expand Up @@ -659,13 +660,14 @@ private[proto3] class Compiler(model: Model, allShapes: Boolean) {
extractTimestampFormat(shape)
.orElse(timestampFormat)
.getOrElse(ProtoTimestampFormatTrait.TimestampFormat.PROTOBUF)
val isEpochMillis =
(format == ProtoTimestampFormatTrait.TimestampFormat.EPOCH_MILLIS)
if (!isWrapped) {
if (isEpochMillis) Type.Int64 else Type.GoogleTimestamp
} else {
if (isEpochMillis) Type.GoogleWrappers.Int64
else Type.AlloyWrappers.Timestamp

format match {
case TimestampFormat.PROTOBUF | TimestampFormat.UNKNOWN =>
if (isWrapped) Type.AlloyWrappers.Timestamp
else Type.GoogleTimestamp
case TimestampFormat.EPOCH_MILLIS =>
if (isWrapped) Type.AlloyWrappers.EpochMillisTimestamp
else Type.AlloyTypes.EpochMillisTimestamp
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ private[internals] object ProtoIR {
alloyFqn("CompactUUID"),
alloyTypesImport
)
val EpochMillisTimestamp = RefType(
alloyFqn("EpochMillisTimestamp"),
alloyTypesImport
)
}

object AlloyWrappers {
Expand Down Expand Up @@ -204,6 +208,10 @@ private[internals] object ProtoIR {
alloyFqn("TimestampValue"),
alloyWrappersImport
)
val EpochMillisTimestamp = RefType(
alloyFqn("EpochMillisTimestampValue"),
alloyWrappersImport
)
val CompactUUID = RefType(
alloyFqn("CompactUUIDValue"),
alloyWrappersImport
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ class CompilerRendererSuite extends FunSuite {
|
|import "google/protobuf/timestamp.proto";
|
|import "alloy/protobuf/types.proto";
|
|message Struct {
| bool boolean = 1;
| int32 int = 2;
Expand All @@ -221,7 +223,7 @@ class CompilerRendererSuite extends FunSuite {
| google.protobuf.Value document = 11;
| string string = 12;
| google.protobuf.Timestamp timestamp = 13;
| int64 epoch = 14;
| alloy.protobuf.EpochMillisTimestamp epoch = 14;
|}
|""".stripMargin
convertCheck(source, Map("com/example/example.proto" -> expected))
Expand Down Expand Up @@ -288,7 +290,7 @@ class CompilerRendererSuite extends FunSuite {
| alloy.protobuf.DocumentValue document = 11;
| google.protobuf.StringValue string = 12;
| alloy.protobuf.TimestampValue timestamp = 13;
| google.protobuf.Int64Value epoch = 14;
| alloy.protobuf.EpochMillisTimestampValue epoch = 14;
|}
|""".stripMargin
convertCheck(source, Map("com/example/example.proto" -> expected))
Expand Down

0 comments on commit 5502e0c

Please sign in to comment.