Skip to content

Commit

Permalink
fix: CBOR protocol test assertions / blob serialization (#1198)
Browse files Browse the repository at this point in the history
  • Loading branch information
lauzadis authored Dec 18, 2024
1 parent 80f4538 commit e9d16a9
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changes/1021e75a-45f3-4f3a-820c-700d9ec6e782.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "1021e75a-45f3-4f3a-820c-700d9ec6e782",
"type": "bugfix",
"description": "Fix serialization of CBOR blobs"
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ open class HttpProtocolUnitTestRequestGenerator protected constructor(builder: B
write("return")
}
write("requireNotNull(expectedBytes) { #S }", "expected application/cbor body cannot be null")
write("requireNotNull(expectedBytes) { #S }", "actual application/cbor body cannot be null")
write("requireNotNull(actualBytes) { #S }", "actual application/cbor body cannot be null")

write("")
write("val expectedRequest = #L(#T(expectedBytes))", inputDeserializer.name, RuntimeTypes.Serde.SerdeCbor.CborDeserializer)
write("val actualRequest = #L(#T(expectedBytes))", inputDeserializer.name, RuntimeTypes.Serde.SerdeCbor.CborDeserializer)
write("val actualRequest = #L(#T(actualBytes))", inputDeserializer.name, RuntimeTypes.Serde.SerdeCbor.CborDeserializer)
write("assertEquals(expectedRequest, actualRequest)")
}
writer.write("")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,6 @@ open class SerializeStructGenerator(
val target = member.targetOrSelf(ctx.model)

val encoded = when {
target.type == ShapeType.BLOB -> writer.format("#L.#T()", identifier, RuntimeTypes.Core.Text.Encoding.encodeBase64String)
target.type == ShapeType.TIMESTAMP -> {
writer.addImport(RuntimeTypes.Core.TimestampFormat)
val tsFormat = member
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1822,7 +1822,7 @@ class SerializeStructGeneratorTest {

val expected = """
serializer.serializeStruct(OBJ_DESCRIPTOR) {
input.fooBlob?.let { field(FOOBLOB_DESCRIPTOR, it.encodeBase64String()) }
input.fooBlob?.let { field(FOOBLOB_DESCRIPTOR, it) }
}
""".trimIndent()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public class XmlSerializer(private val xmlWriter: XmlStreamWriter = xmlStreamWri
field(descriptor, value.format(format))

override fun field(descriptor: SdkFieldDescriptor, value: ByteArray): Unit =
field(descriptor, value)
field(descriptor, value.encodeBase64String())

override fun field(descriptor: SdkFieldDescriptor, value: Document?): Unit = throw SerializationException(
"cannot serialize field ${descriptor.serialName}; Document type is not supported by xml encoding",
Expand Down

0 comments on commit e9d16a9

Please sign in to comment.