private void WriteFooter(Schema schema) { Builder.Clear(); long offset = BaseStream.Position; // Serialize the schema FlatBuffers.Offset <Flatbuf.Schema> schemaOffset = SerializeSchema(schema); // Serialize all record batches Flatbuf.Footer.StartRecordBatchesVector(Builder, RecordBatchBlocks.Count); // flatbuffer struct vectors have to be created in reverse order for (int i = RecordBatchBlocks.Count - 1; i >= 0; i--) { Block recordBatch = RecordBatchBlocks[i]; Flatbuf.Block.CreateBlock( Builder, recordBatch.Offset, recordBatch.MetadataLength, recordBatch.BodyLength); } FlatBuffers.VectorOffset recordBatchesVectorOffset = Builder.EndVector(); // Serialize all dictionaries // NOTE: Currently unsupported. Flatbuf.Footer.StartDictionariesVector(Builder, 0); FlatBuffers.VectorOffset dictionaryBatchesOffset = Builder.EndVector(); // Serialize and write the footer flatbuffer FlatBuffers.Offset <Flatbuf.Footer> footerOffset = Flatbuf.Footer.CreateFooter(Builder, CurrentMetadataVersion, schemaOffset, dictionaryBatchesOffset, recordBatchesVectorOffset); Builder.Finish(footerOffset.Value); WriteFlatBuffer(); // Write footer length Buffers.RentReturn(4, (buffer) => { int footerLength; checked { footerLength = (int)(BaseStream.Position - offset); } BinaryPrimitives.WriteInt32LittleEndian(buffer.Span, footerLength); BaseStream.Write(buffer); }); // Write magic WriteMagic(); }
static void WriteBackInstance(ILRuntime.Runtime.Enviorment.AppDomain __domain, StackObject *ptr_of_this_method, IList <object> __mStack, ref FlatBuffers.Offset <ILRuntime.Runtime.GeneratedAdapter.TableAdapter.Adapter> instance_of_this_method) { ptr_of_this_method = ILIntepreter.GetObjectAndResolveReference(ptr_of_this_method); switch (ptr_of_this_method->ObjectType) { case ObjectTypes.Object: { __mStack[ptr_of_this_method->Value] = instance_of_this_method; } break; case ObjectTypes.FieldReference: { var ___obj = __mStack[ptr_of_this_method->Value]; if (___obj is ILTypeInstance) { ((ILTypeInstance)___obj)[ptr_of_this_method->ValueLow] = instance_of_this_method; } else { var t = __domain.GetType(___obj.GetType()) as CLRType; t.SetFieldValue(ptr_of_this_method->ValueLow, ref ___obj, instance_of_this_method); } } break; case ObjectTypes.StaticFieldReference: { var t = __domain.GetType(ptr_of_this_method->Value); if (t is ILType) { ((ILType)t).StaticInstance[ptr_of_this_method->ValueLow] = instance_of_this_method; } else { ((CLRType)t).SetStaticFieldValue(ptr_of_this_method->ValueLow, instance_of_this_method); } } break; case ObjectTypes.ArrayReference: { var instance_of_arrayReference = __mStack[ptr_of_this_method->Value] as FlatBuffers.Offset <ILRuntime.Runtime.GeneratedAdapter.TableAdapter.Adapter>[]; instance_of_arrayReference[ptr_of_this_method->ValueLow] = instance_of_this_method; } break; } }
static StackObject *Ctor_0(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj) { ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain; StackObject *ptr_of_this_method; StackObject *__ret = ILIntepreter.Minus(__esp, 1); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); System.Int32 @value = ptr_of_this_method->Value; var result_of_this_method = new FlatBuffers.Offset <ILRuntime.Runtime.GeneratedAdapter.TableAdapter.Adapter>(@value); if (!isNewObj) { __ret--; WriteBackInstance(__domain, __ret, __mStack, ref result_of_this_method); return(__ret); } return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method)); }
} // set in Timestamp // not implemented: user_metadata (see: https://github.com/wesm/feather/blob/master/cpp/src/feather/metadata.fbs#L106) public void CreateMetadata(FlatBuffers.FlatBufferBuilder builder, FeatherWriter writer, out int metadataOffset, out feather.fbs.TypeMetadata metadata, out FlatBuffers.Offset <feather.fbs.PrimitiveArray> categoryLevels) { var isCategoryType = Type == ColumnType.Category || Type == ColumnType.NullableCategory; var isDateType = Type == ColumnType.Date || Type == ColumnType.NullableDate; var isTimeType = Type == ColumnType.Time_Microsecond || Type == ColumnType.Time_Millisecond || Type == ColumnType.Time_Second || Type == ColumnType.Time_Nanosecond || Type == ColumnType.NullableTime_Microsecond || Type == ColumnType.NullableTime_Millisecond || Type == ColumnType.NullableTime_Second || Type == ColumnType.NullableTime_Nanosecond; var isTimestampType = Type == ColumnType.Timestamp_Microsecond || Type == ColumnType.Timestamp_Millisecond || Type == ColumnType.Timestamp_Second || Type == ColumnType.Timestamp_Nanosecond || Type == ColumnType.NullableTimestamp_Microsecond || Type == ColumnType.NullableTimestamp_Millisecond || Type == ColumnType.NullableTimestamp_Second || Type == ColumnType.NullableTimestamp_Nanosecond; if (isDateType) { throw new InvalidOperationException($"Mapping to a Date on disk doesn't make sense from .NET"); } if (isTimestampType) { var offsetMeta = feather.fbs.TimestampMetadata.CreateTimestampMetadata( builder, Unit.MapToDiskType(), builder.CreateString("GMT") ); metadataOffset = offsetMeta.Value; metadata = feather.fbs.TypeMetadata.TimestampMetadata; categoryLevels = default(FlatBuffers.Offset <feather.fbs.PrimitiveArray>); return; } if (isTimeType) { var offsetMeta = feather.fbs.TimeMetadata.CreateTimeMetadata( builder, Unit.MapToDiskType() ); metadataOffset = offsetMeta.Value; metadata = feather.fbs.TypeMetadata.TimeMetadata; categoryLevels = default(FlatBuffers.Offset <feather.fbs.PrimitiveArray>); return; } if (isCategoryType) { long startIx; long numBytes; writer.WriteLevels(Levels, out startIx, out numBytes); categoryLevels = feather.fbs.PrimitiveArray.CreatePrimitiveArray( builder, feather.fbs.Type.UTF8, feather.fbs.Encoding.PLAIN, startIx, Levels.LongLength, 0, numBytes ); var offsetMeta = feather.fbs.CategoryMetadata.CreateCategoryMetadata( builder, categoryLevels, Ordered ); metadataOffset = offsetMeta.Value; metadata = feather.fbs.TypeMetadata.CategoryMetadata; return; } metadataOffset = 0; metadata = feather.fbs.TypeMetadata.NONE; categoryLevels = default(FlatBuffers.Offset <feather.fbs.PrimitiveArray>); }
private async Task WriteFooterAsync(Schema schema, CancellationToken cancellationToken) { Builder.Clear(); long offset = BaseStream.Position; // Serialize the schema FlatBuffers.Offset <Flatbuf.Schema> schemaOffset = SerializeSchema(schema); // Serialize all record batches Flatbuf.Footer.StartRecordBatchesVector(Builder, RecordBatchBlocks.Count); foreach (Block recordBatch in RecordBatchBlocks) { Flatbuf.Block.CreateBlock( Builder, recordBatch.Offset, recordBatch.MetadataLength, recordBatch.BodyLength); } FlatBuffers.VectorOffset recordBatchesVectorOffset = Builder.EndVector(); // Serialize all dictionaries // NOTE: Currently unsupported. Flatbuf.Footer.StartDictionariesVector(Builder, 0); FlatBuffers.VectorOffset dictionaryBatchesOffset = Builder.EndVector(); // Serialize and write the footer flatbuffer FlatBuffers.Offset <Flatbuf.Footer> footerOffset = Flatbuf.Footer.CreateFooter(Builder, CurrentMetadataVersion, schemaOffset, dictionaryBatchesOffset, recordBatchesVectorOffset); Builder.Finish(footerOffset.Value); cancellationToken.ThrowIfCancellationRequested(); await WriteFlatBufferAsync(cancellationToken).ConfigureAwait(false); // Write footer length cancellationToken.ThrowIfCancellationRequested(); await Buffers.RentReturnAsync(4, async (buffer) => { int footerLength; checked { footerLength = (int)(BaseStream.Position - offset); } BinaryPrimitives.WriteInt32LittleEndian(buffer.Span, footerLength); await BaseStream.WriteAsync(buffer, cancellationToken).ConfigureAwait(false); }).ConfigureAwait(false); // Write magic await WriteMagicAsync(cancellationToken).ConfigureAwait(false); }
static StackObject *AssignFromStack_Value_0(ref object o, ILIntepreter __intp, StackObject *ptr_of_this_method, IList <object> __mStack) { ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain; System.Int32 @Value = ptr_of_this_method->Value; FlatBuffers.Offset <ILRuntime.Runtime.GeneratedAdapter.TableAdapter.Adapter> ins = (FlatBuffers.Offset <ILRuntime.Runtime.GeneratedAdapter.TableAdapter.Adapter>)o; ins.Value = @Value; o = ins; return(ptr_of_this_method); }
static void set_Value_0(ref object o, object v) { FlatBuffers.Offset <ILRuntime.Runtime.GeneratedAdapter.TableAdapter.Adapter> ins = (FlatBuffers.Offset <ILRuntime.Runtime.GeneratedAdapter.TableAdapter.Adapter>)o; ins.Value = (System.Int32)v; o = ins; }