@@ -63,7 +63,7 @@ private void ensureMaterializedMap() {
6363 for (int i = 0 ; i < objEntry .offsetOrCount (); i ++) {
6464 ESONEntry entry = esonFlat .keys ().get (currentIndex );
6565 if (entry instanceof ESONEntry .FieldEntry fieldEntry ) {
66- materializedMap .put (fieldEntry .key (), fieldEntry .value );
66+ materializedMap .put (fieldEntry .key (), fieldEntry .value () );
6767 currentIndex ++;
6868 } else {
6969 if (entry instanceof ESONEntry .ObjectEntry ) {
@@ -374,7 +374,7 @@ private void ensureMaterializedList() {
374374 for (int i = 0 ; i < arrEntry .offsetOrCount (); i ++) {
375375 ESONEntry entry = esonFlat .keys ().get (currentIndex );
376376 if (entry instanceof ESONEntry .FieldEntry fieldEntry ) {
377- materializedList .add (fieldEntry .value );
377+ materializedList .add (fieldEntry .value () );
378378 currentIndex ++;
379379 } else {
380380 if (entry instanceof ESONEntry .ObjectEntry ) {
@@ -661,7 +661,7 @@ private static void handleObject(List<ESONEntry> flatKeyArray, Object object, St
661661 handleObject (flatKeyArray , value , null , newOffset , newValuesOut );
662662 }
663663 } else {
664- flatKeyArray .add (new ESONEntry . FieldEntry ( key , mutationToValue (newOffset , newValuesOut , obj ) ));
664+ flatKeyArray .add (mutationToValue (newOffset , key , newValuesOut , obj ));
665665 }
666666 }
667667
@@ -717,7 +717,7 @@ private static void flattenArray(
717717 switch (type ) {
718718 case ESONSource .Mutation mutation -> {
719719 // This is a mutated element - create new FieldEntry with mutation
720- flatKeyArray .add (new ESONEntry . FieldEntry ( null , mutationToValue (newOffset , newValuesOut , mutation .object () )));
720+ flatKeyArray .add (mutationToValue (newOffset , null , newValuesOut , mutation .object ()));
721721 elementCount ++;
722722 }
723723 case ESONObject nestedObj -> {
@@ -746,68 +746,69 @@ private static void flattenArray(
746746 }
747747 }
748748
749- private static ESONSource .Value mutationToValue (int newOffset , BytesStreamOutput newValuesOut , Object obj ) throws IOException {
749+ private static ESONEntry .FieldEntry mutationToValue (int newOffset , String fieldName , BytesStreamOutput newValuesOut , Object obj )
750+ throws IOException {
750751 int position = newOffset + Math .toIntExact (newValuesOut .position ());
751- ESONSource . Value value ;
752+ ESONEntry . FieldEntry value ;
752753 if (obj == null ) {
753- value = ESONSource .ConstantValue .NULL ;
754+ value = new ESONEntry . FieldEntry ( fieldName , ESONSource .ConstantValue .NULL ) ;
754755 } else if (obj instanceof Number num ) {
755756 value = switch (num ) {
756757 case Byte byteValue -> {
757758 newValuesOut .writeInt (byteValue .intValue ());
758- yield new ESONSource . FixedValue ( position , ESONEntry .TYPE_INT );
759+ yield new ESONEntry . FieldEntry ( fieldName , ESONEntry .TYPE_INT , position );
759760 }
760761 case Short shortValue -> {
761762 newValuesOut .writeInt (shortValue );
762- yield new ESONSource . FixedValue ( position , ESONEntry .TYPE_INT );
763+ yield new ESONEntry . FieldEntry ( fieldName , ESONEntry .TYPE_INT , position );
763764 }
764765 case Integer intValue -> {
765766 newValuesOut .writeInt (intValue );
766- yield new ESONSource . FixedValue ( position , ESONEntry .TYPE_INT );
767+ yield new ESONEntry . FieldEntry ( fieldName , ESONEntry .TYPE_INT , position );
767768 }
768769 case Long longValue -> {
769770 newValuesOut .writeLong (longValue );
770- yield new ESONSource . FixedValue ( position , ESONEntry .TYPE_LONG );
771+ yield new ESONEntry . FieldEntry ( fieldName , ESONEntry .TYPE_LONG , position );
771772 }
772773 case Float floatValue -> {
773774 newValuesOut .writeFloat (floatValue );
774- yield new ESONSource . FixedValue ( position , ESONEntry .TYPE_FLOAT );
775+ yield new ESONEntry . FieldEntry ( fieldName , ESONEntry .TYPE_FLOAT , position );
775776 }
776777 case Double doubleValue -> {
777778 newValuesOut .writeDouble (doubleValue );
778- yield new ESONSource . FixedValue ( position , ESONEntry .TYPE_DOUBLE );
779+ yield new ESONEntry . FieldEntry ( fieldName , ESONEntry .TYPE_DOUBLE , position );
779780 }
780781 case BigInteger bigInteger -> {
781782 byte [] numberBytes = bigInteger .toString ().getBytes (StandardCharsets .UTF_8 );
782783 newValuesOut .writeVInt (numberBytes .length );
783784 newValuesOut .write (numberBytes );
784- yield new ESONSource . VariableValue ( position , ESONEntry .BIG_INTEGER );
785+ yield new ESONEntry . FieldEntry ( fieldName , ESONEntry .BIG_INTEGER , position );
785786 }
786787 case BigDecimal bigDecimal -> {
787788 byte [] numberBytes = bigDecimal .toString ().getBytes (StandardCharsets .UTF_8 );
788789 newValuesOut .writeVInt (numberBytes .length );
789790 newValuesOut .write (numberBytes );
790- yield new ESONSource . VariableValue ( position , ESONEntry .BIG_DECIMAL );
791+ yield new ESONEntry . FieldEntry ( fieldName , ESONEntry .BIG_DECIMAL , position );
791792 }
792793 default -> {
793794 byte [] utf8Bytes = num .toString ().getBytes (StandardCharsets .UTF_8 );
794795 newValuesOut .writeVInt (utf8Bytes .length );
795796 newValuesOut .write (utf8Bytes );
796- yield new ESONSource . VariableValue ( position , ESONEntry .STRING );
797+ yield new ESONEntry . FieldEntry ( fieldName , ESONEntry .STRING , position );
797798 }
798799 };
799800 } else if (obj instanceof Boolean bool ) {
800- value = bool ? ESONSource .ConstantValue .TRUE : ESONSource .ConstantValue .FALSE ;
801+ value = new ESONEntry . FieldEntry ( fieldName , bool ? ESONSource .ConstantValue .TRUE : ESONSource .ConstantValue .FALSE ) ;
801802 } else if (obj instanceof byte [] bytes ) {
802803 newValuesOut .writeVInt (bytes .length );
803804 newValuesOut .writeBytes (bytes );
804- value = new ESONSource . VariableValue ( position , ESONEntry .BINARY );
805+ value = new ESONEntry . FieldEntry ( fieldName , ESONEntry .BINARY , position );
805806 } else {
806807 String str = obj .toString ();
807808 byte [] bytes = str .getBytes (StandardCharsets .UTF_8 );
808809 newValuesOut .writeVInt (bytes .length );
809810 newValuesOut .writeBytes (bytes );
810- value = new ESONSource . VariableValue ( position , ESONEntry .STRING );
811+ value = new ESONEntry . FieldEntry ( fieldName , ESONEntry .STRING , position );
811812 }
812813
813814 return value ;
0 commit comments