@@ -47,20 +47,23 @@ function parseFieldBitmaps(allFields, fieldBitmapsAsHex) {
4747 if ( fieldBitmapsAsHex . length === 0 ) {
4848 return [ ] ;
4949 }
50+
5051 let fieldNames = [ ] ;
5152 // Replace top field level bitmap with list of fields
5253 if ( fieldBitmapsAsHex [ 0 ] . startsWith ( '0x' ) ) {
53- fieldNames = fieldNames . concat (
54- getFieldNamesFromBitmap ( allFields , fieldBitmapsAsHex [ 0 ] )
55- ) ;
54+ fieldNames = getFieldNamesFromBitmap ( allFields , fieldBitmapsAsHex [ 0 ] ) ;
5655 }
5756 // Process compound fields
58- if ( fieldBitmapsAsHex [ fieldBitmapsAsHex . length - 1 ] . indexOf ( '-' ) !== - 1 ) {
57+ if (
58+ fieldBitmapsAsHex . length > 1 &&
59+ fieldBitmapsAsHex [ fieldBitmapsAsHex . length - 1 ] . indexOf ( '-' ) !== - 1
60+ ) {
5961 fieldBitmapsAsHex . forEach ( ( fieldBitmapAsHex ) => {
6062 const bitmapMapStrings = fieldBitmapAsHex . split ( '-' ) ;
6163 // Ignore top level field bitmap
6264 if ( bitmapMapStrings . length >= 2 ) {
63- const parentField = allFields [ parseInt ( bitmapMapStrings [ 0 ] ) ] ;
65+ const parentField =
66+ allFields [ parseInt ( bitmapMapStrings [ 0 ] , 10 ) ] ;
6467 const childFields = getChildFields ( parentField ) ;
6568 const childFieldNames = getFieldNamesFromBitmap (
6669 childFields ,
@@ -83,8 +86,6 @@ function getChildFields(parentField) {
8386 types . forEach ( ( type ) => {
8487 if ( type instanceof avro . types . RecordType ) {
8588 fields = fields . concat ( type . getFields ( ) ) ;
86- } else if ( type instanceof avro . types . NullType ) {
87- fields . push ( null ) ;
8889 }
8990 } ) ;
9091 return fields ;
@@ -94,10 +95,12 @@ function getChildFields(parentField) {
9495 * Loads field names from a bitmap
9596 * @param {Field[] } fields list of Avro Field
9697 * @param {string } fieldBitmapAsHex
98+ * @returns {string[] } field names
9799 */
98100function getFieldNamesFromBitmap ( fields , fieldBitmapAsHex ) {
101+ // Convert hex to binary and reverse bits
99102 let binValue = hexToBin ( fieldBitmapAsHex ) ;
100- binValue = reverseBytes ( binValue ) ; // Reverse byte order to match expected format
103+ binValue = binValue . split ( '' ) . reverse ( ) . join ( '' ) ;
101104 // Use bitmap to figure out field names based on index
102105 const fieldNames = [ ] ;
103106 for ( let i = 0 ; i < binValue . length && i < fields . length ; i ++ ) {
@@ -108,14 +111,6 @@ function getFieldNamesFromBitmap(fields, fieldBitmapAsHex) {
108111 return fieldNames ;
109112}
110113
111- function reverseBytes ( input ) {
112- let output = '' ;
113- for ( let i = input . length / 8 - 1 ; i >= 0 ; i -- ) {
114- output += input . substring ( i * 8 , ( i + 1 ) * 8 ) ;
115- }
116- return output ;
117- }
118-
119114/**
120115 * Decodes the value of a replay ID from a buffer
121116 * @param {Buffer } encodedReplayId
@@ -139,7 +134,7 @@ export function encodeReplayId(replayId) {
139134/**
140135 * Converts a hexadecimal string into a string binary representation
141136 * @param {string } hex
142- * @returns
137+ * @returns { string }
143138 */
144139function hexToBin ( hex ) {
145140 let bin = hex . substring ( 2 ) ; // Remove 0x prefix
0 commit comments