Skip to content

Commit 61daf06

Browse files
authored
[Schema Registry Avro] Remove old format compatability (Azure#21648)
### Packages impacted by this PR @azure/schema-registry-avro ### Issues associated with this PR Fixes Azure#20063 ### Describe the problem that is addressed by this PR The old payload format was planned to be supported until the last beta before the first stable release and since the first stable release is scheduled for May, the compatability should be removed now. ### What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen? ### Are there test cases added in this PR? _(If not, why?)_ ### Provide a list of related PRs _(if any)_ ### Command used to generate this PR:**_(Applicable only to SDK release request PRs)_ ### Checklists - [x] Added impacted package name to the issue description - [ ] Does this PR needs any fixes in the SDK Generator?** _(If so, create an Issue in the [Autorest/typescript](https://github.com/Azure/autorest.typescript) repository and link it here)_ - [x] Added a changelog (if necessary)
1 parent f8cd963 commit 61daf06

File tree

5 files changed

+11
-69
lines changed

5 files changed

+11
-69
lines changed

sdk/schemaregistry/schema-registry-avro/CHANGELOG.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
# Release History
22

3-
## 1.0.0-beta.9 (Unreleased)
4-
5-
### Features Added
6-
7-
### Breaking Changes
8-
9-
### Bugs Fixed
3+
## 1.0.0 (2022-05-10)
104

115
### Other Changes
126

7+
- Compatability for old payload format has been removed.
8+
- Errors may include a `cause` field that stores inner errors if any.
9+
1310
## 1.0.0-beta.8 (2022-04-05)
1411

1512
### Features Added

sdk/schemaregistry/schema-registry-avro/README.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,6 @@ by setting the `messageAdapter` option in the constructor with a corresponding
5858
message producer and consumer. Azure messaging client libraries export default
5959
adapters for their message types.
6060

61-
### Backward Compatibility
62-
63-
The serializer v1.0.0-beta.5 and under serializes data into binary arrays. Starting from
64-
v1.0.0-beta.6, the serializer returns messages instead that contain the serialized payload.
65-
For a smooth transition to using the newer versions, the serializer also supports
66-
deserializing messages with payloads that follow the old format where the schema ID
67-
is part of the payload.
68-
69-
This backward compatibility is temporary and will be removed in v1.0.0.
70-
7161
## Examples
7262

7363
### Serialize and deserialize an `@azure/event-hubs`'s `EventData`

sdk/schemaregistry/schema-registry-avro/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@azure/schema-registry-avro",
3-
"version": "1.0.0-beta.9",
3+
"version": "1.0.0",
44
"description": "Schema Registry Avro Serializer Library with typescript type definitions for node.js and browser.",
55
"sdk-type": "client",
66
"main": "dist/index.js",

sdk/schemaregistry/schema-registry-avro/src/avroSerializer.ts

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -224,67 +224,22 @@ function getSchemaId(contentType: string): string {
224224
return contentTypeParts[1];
225225
}
226226

227-
/**
228-
* Tries to deserialize data in the preamble format. If that does not succeed, it
229-
* returns it as is.
230-
* @param data - The message content
231-
* @param contentType - The message content type
232-
* @returns a message
233-
*/
234-
function convertPayload(data: Uint8Array, contentType: string): MessageContent {
235-
try {
236-
return tryReadingPreambleFormat(Buffer.from(data));
237-
} catch (_e: unknown) {
238-
return {
239-
data,
240-
contentType,
241-
};
242-
}
243-
}
244-
245227
function convertMessage<MessageT>(
246228
message: MessageT,
247229
adapter?: MessageAdapter<MessageT>
248230
): MessageContent {
249231
const messageConsumer = adapter?.consume;
250232
if (messageConsumer) {
251-
const { data, contentType } = messageConsumer(message);
252-
return convertPayload(data, contentType);
233+
return messageConsumer(message);
253234
} else if (isMessageContent(message)) {
254-
return convertPayload(message.data, message.contentType);
235+
return message;
255236
} else {
256237
throw new Error(
257238
`Expected either a message adapter to be provided to the serializer or the input message to have data and contentType fields`
258239
);
259240
}
260241
}
261242

262-
/**
263-
* Maintains backward compatability by supporting the serialized value format created
264-
* by earlier beta serializers
265-
* @param buffer - The input buffer
266-
* @returns a message that contains the data and content type with the schema ID
267-
*/
268-
function tryReadingPreambleFormat(buffer: Buffer): MessageContent {
269-
const FORMAT_INDICATOR = 0;
270-
const SCHEMA_ID_OFFSET = 4;
271-
const PAYLOAD_OFFSET = 36;
272-
if (buffer.length < PAYLOAD_OFFSET) {
273-
throw new RangeError("Buffer is too small to have the correct format.");
274-
}
275-
const format = buffer.readUInt32BE(0);
276-
if (format !== FORMAT_INDICATOR) {
277-
throw new TypeError(`Buffer has unknown format indicator.`);
278-
}
279-
const schemaIdBuffer = buffer.slice(SCHEMA_ID_OFFSET, PAYLOAD_OFFSET);
280-
const schemaId = schemaIdBuffer.toString("utf-8");
281-
const payloadBuffer = buffer.slice(PAYLOAD_OFFSET);
282-
return {
283-
data: payloadBuffer,
284-
contentType: `${avroMimeType}+${schemaId}`,
285-
};
286-
}
287-
288243
function getSerializerForSchema(schema: string): AVSCSerializer {
289244
return wrapError(
290245
() => avro.Type.forSchema(JSON.parse(schema), { omitRecordMethods: true }),

sdk/schemaregistry/schema-registry-avro/test/public/avroSerializer.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ describe("AvroSerializer", function () {
130130
assert.equal(deserializedValue.age, 30);
131131
});
132132

133-
it("deserializes from the old format", async () => {
133+
it("ignores the old format", async () => {
134134
const registry = createTestRegistry();
135135
const schemaId = await registerTestSchema(registry);
136136
const serializer = await createTestSerializer<MessageContent>({
@@ -142,12 +142,12 @@ describe("AvroSerializer", function () {
142142

143143
data.write(schemaId, 4, 32, "utf-8");
144144
payload.copy(data, 36);
145-
assert.deepStrictEqual(
146-
await serializer.deserialize({
145+
await assert.isRejected(
146+
serializer.deserialize({
147147
data,
148148
contentType: "avro/binary+000",
149149
}),
150-
testValue
150+
`Schema does not exist`
151151
);
152152
});
153153

0 commit comments

Comments
 (0)