@@ -138,7 +138,7 @@ trait Connector extends Serializable {
138138 getSchema : Long => Option [Schema ]
139139 ): (Schema , Array [Byte ]) = {
140140 if (AvroSingleObjectEncodingUtils .isAvroSingleObjectEncoded(avroSingleObjectEncoded)) {
141- val id = AvroSingleObjectEncodingUtils . extractId(avroSingleObjectEncoded, endianness)
141+ val id = extractId(avroSingleObjectEncoded, endianness)
142142 getSchema(id) match {
143143 case Some (schema) =>
144144 schema -> AvroSingleObjectEncodingUtils .dropHeader(avroSingleObjectEncoded)
@@ -163,7 +163,7 @@ trait Connector extends Serializable {
163163 getSchema : Long => Option [Schema ]
164164 ): Schema = {
165165 if (AvroSingleObjectEncodingUtils .isAvroSingleObjectEncoded(avroSingleObjectEncoded)) {
166- val id = AvroSingleObjectEncodingUtils . extractId(avroSingleObjectEncoded, endianness)
166+ val id = extractId(avroSingleObjectEncoded, endianness)
167167 getSchema(id) match {
168168 case Some (schema) => schema
169169 case _ => throw new DarwinException (s " No schema found for ID $id" )
@@ -187,7 +187,7 @@ trait Connector extends Serializable {
187187 endianness : ByteOrder ,
188188 getSchema : Long => Option [Schema ]
189189 ): Either [Array [Byte ], Schema ] = {
190- AvroSingleObjectEncodingUtils . extractId(inputStream, endianness).rightMap { id =>
190+ extractId(inputStream, endianness).rightMap { id =>
191191 getSchema(id).getOrElse(throw new DarwinException (s " No schema found for ID $id" ))
192192 }
193193 }
@@ -204,14 +204,54 @@ trait Connector extends Serializable {
204204 getSchema : Long => Option [Schema ]
205205 ): Either [Exception , Schema ] = {
206206 try {
207- val id = AvroSingleObjectEncodingUtils . extractId(array, endianness)
207+ val id = extractId(array, endianness)
208208 getSchema(id)
209209 .toRight(new RuntimeException (s " Cannot find schema with id $id" ))
210210 } catch {
211211 case ie : IllegalArgumentException => Left (ie)
212212 }
213213 }
214214
215+ /**
216+ * Extracts the schema ID from the avro single-object encoded byte array
217+ *
218+ * @param array avro single-object encoded byte array
219+ * @param endianness the endianness that will be used to read fingerprint bytes,
220+ * it won't affect how avro payload is read, that is up to the darwin user
221+ * @return the schema ID extracted from the input data
222+ */
223+ def extractId (array : Array [Byte ], endianness : ByteOrder ): Long = {
224+ AvroSingleObjectEncodingUtils .extractId(array, endianness)
225+ }
226+
227+ /**
228+ * Extracts the schema ID from the avro single-object encoded at the head of this input stream.
229+ * The input stream will have 10 bytes consumed if the first two bytes correspond to the single object encoded
230+ * header, or zero bytes consumed if the InputStream supports marking; if it doesn't, the first bytes (up to 2) will
231+ * be consumed and returned in the Left part of the Either.
232+ *
233+ * @param inputStream avro single-object encoded input stream
234+ * @param endianness the endianness that will be used to read fingerprint bytes,
235+ * it won't affect how avro payload is read, that is up to the darwin user
236+ * @return the schema ID extracted from the input data
237+ */
238+ def extractId (inputStream : InputStream , endianness : ByteOrder ): Either [Array [Byte ], Long ] = {
239+ AvroSingleObjectEncodingUtils .extractId(inputStream, endianness)
240+ }
241+
242+ /**
243+ * Extracts the schema ID from the avro single-object encoded ByteBuffer, the ByteBuffer position will be after the
244+ * header when this method returns
245+ *
246+ * @param avroSingleObjectEncoded avro single-object encoded byte array
247+ * @param endianness the endianness that will be used to read fingerprint bytes,
248+ * it won't affect how avro payload is read, that is up to the darwin user
249+ * @return the schema ID extracted from the input data
250+ */
251+ def extractId (avroSingleObjectEncoded : ByteBuffer , endianness : ByteOrder ): Long = {
252+ AvroSingleObjectEncodingUtils .extractId(avroSingleObjectEncoded, endianness)
253+ }
254+
215255 /**
216256 * Extracts a SchemaPayloadPair that contains the Schema and the Avro-encoded payload
217257 *
0 commit comments