-
Notifications
You must be signed in to change notification settings - Fork 7
feat: add support for utf8view type #225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NguyenHoangSon96
wants to merge
3
commits into
apache:main
Choose a base branch
from
NguyenHoangSon96:feat/support-utf8view-type
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,44 @@ | ||||||||||||||||||||||||||
// Licensed to the Apache Software Foundation (ASF) under one | ||||||||||||||||||||||||||
// or more contributor license agreements. See the NOTICE file | ||||||||||||||||||||||||||
// distributed with this work for additional information | ||||||||||||||||||||||||||
// regarding copyright ownership. The ASF licenses this file | ||||||||||||||||||||||||||
// to you under the Apache License, Version 2.0 (the | ||||||||||||||||||||||||||
// "License"); you may not use this file except in compliance | ||||||||||||||||||||||||||
// with the License. You may obtain a copy of the License at | ||||||||||||||||||||||||||
// | ||||||||||||||||||||||||||
// http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||||||||||||
// | ||||||||||||||||||||||||||
// Unless required by applicable law or agreed to in writing, | ||||||||||||||||||||||||||
// software distributed under the License is distributed on an | ||||||||||||||||||||||||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||||||||||||||||||||||||||
// KIND, either express or implied. See the License for the | ||||||||||||||||||||||||||
// specific language governing permissions and limitations | ||||||||||||||||||||||||||
// under the License. | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
import { Utf8View } from '../type.js'; | ||||||||||||||||||||||||||
import { encodeUtf8 } from '../util/utf8.js'; | ||||||||||||||||||||||||||
import { BinaryBuilder } from './binary.js'; | ||||||||||||||||||||||||||
import { BufferBuilder } from './buffer.js'; | ||||||||||||||||||||||||||
import { VariableWidthBuilder, BuilderOptions } from '../builder.js'; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
/** @ignore */ | ||||||||||||||||||||||||||
export class Utf8ViewBuilder<TNull = any> extends VariableWidthBuilder<Utf8View, TNull> { | ||||||||||||||||||||||||||
constructor(opts: BuilderOptions<Utf8View, TNull>) { | ||||||||||||||||||||||||||
super(opts); | ||||||||||||||||||||||||||
this._values = new BufferBuilder(Uint8Array); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
public get byteLength(): number { | ||||||||||||||||||||||||||
let size = this._pendingLength + (this.length * 4); | ||||||||||||||||||||||||||
this._offsets && (size += this._offsets.byteLength); | ||||||||||||||||||||||||||
this._values && (size += this._values.byteLength); | ||||||||||||||||||||||||||
this._nulls && (size += this._nulls.byteLength); | ||||||||||||||||||||||||||
return size; | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
public setValue(index: number, value: string) { | ||||||||||||||||||||||||||
return super.setValue(index, encodeUtf8(value) as any); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
// @ts-ignore | ||||||||||||||||||||||||||
protected _flushPending(pending: Map<number, Uint8Array | undefined>, pendingLength: number): void { } | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
(Utf8ViewBuilder.prototype as any)._flushPending = (BinaryBuilder.prototype as any)._flushPending; | ||||||||||||||||||||||||||
Comment on lines
+40
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using prototype copying with type assertions to share implementation between builders is fragile and makes the code harder to maintain. Consider using composition or inheritance instead of prototype manipulation.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// automatically generated by the FlatBuffers compiler, do not modify | ||
|
||
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ | ||
|
||
import * as flatbuffers from 'flatbuffers'; | ||
|
||
/** | ||
* Logically the same as Utf8, but the internal representation uses a view | ||
* struct that contains the string length and either the string's entire data | ||
* inline (for small strings) or an inlined prefix, an index of another buffer, | ||
* and an offset pointing to a slice in that buffer (for non-small strings). | ||
* | ||
* Since it uses a variable number of data buffers, each Field with this type | ||
* must have a corresponding entry in `variadicBufferCounts`. | ||
*/ | ||
export class Utf8View { | ||
bb: flatbuffers.ByteBuffer|null = null; | ||
bb_pos = 0; | ||
__init(i:number, bb:flatbuffers.ByteBuffer):Utf8View { | ||
this.bb_pos = i; | ||
this.bb = bb; | ||
return this; | ||
} | ||
|
||
static getRootAsUtf8View(bb:flatbuffers.ByteBuffer, obj?:Utf8View):Utf8View { | ||
return (obj || new Utf8View()).__init(bb.readInt32(bb.position()) + bb.position(), bb); | ||
} | ||
|
||
static getSizePrefixedRootAsUtf8View(bb:flatbuffers.ByteBuffer, obj?:Utf8View):Utf8View { | ||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); | ||
return (obj || new Utf8View()).__init(bb.readInt32(bb.position()) + bb.position(), bb); | ||
} | ||
|
||
static startUtf8View(builder:flatbuffers.Builder) { | ||
builder.startObject(0); | ||
} | ||
|
||
static endUtf8View(builder:flatbuffers.Builder):flatbuffers.Offset { | ||
const offset = builder.endObject(); | ||
return offset; | ||
} | ||
|
||
static createUtf8View(builder:flatbuffers.Builder):flatbuffers.Offset { | ||
Utf8View.startUtf8View(builder); | ||
return Utf8View.endUtf8View(builder); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The @ts-ignore comment suppresses TypeScript errors without explanation. This makes it difficult to understand what error is being suppressed and why it's safe to ignore.
Copilot uses AI. Check for mistakes.