private void ReadSchema(Memory <byte> buffer) { // Deserialize the footer from the footer flatbuffer _footer = new ArrowFooter(Flatbuf.Footer.GetRootAsFooter(CreateByteBuffer(buffer))); Schema = _footer.Schema; }
protected override async Task <Schema> ReadSchemaAsync() { if (HasReadSchema) { return(Schema); } await ValidateFileAsync(); var bytesRead = 0; var footerLength = 0; await Buffers.RentReturnAsync(4, async (buffer) => { BaseStream.Position = BaseStream.Length - ArrowFileConstants.Magic.Length - 4; bytesRead = await BaseStream.ReadAsync(buffer, 0, 4); footerLength = BinaryPrimitives.ReadInt32LittleEndian(buffer); if (bytesRead != 4) { throw new InvalidDataException( $"Failed to read footer length. Read <{bytesRead}>, expected 4."); } if (footerLength <= 0) { throw new InvalidDataException( $"Footer length has invalid size <{footerLength}>"); } }); await Buffers.RentReturnAsync(footerLength, async (buffer) => { _footerStartPostion = (int)BaseStream.Length - footerLength - ArrowFileConstants.Magic.Length - 4; BaseStream.Position = _footerStartPostion; bytesRead = await BaseStream.ReadAsync(buffer, 0, footerLength); if (bytesRead != footerLength) { throw new InvalidDataException( $"Failed to read footer. Read <{bytesRead}> bytes, expected <{footerLength}>."); } // Deserialize the footer from the footer flatbuffer _footer = new ArrowFooter(Flatbuf.Footer.GetRootAsFooter(new ByteBuffer(buffer))); Schema = _footer.Schema; }); return(Schema); }