GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [Implement] Naive Buffer.from, and friends by jtenner · Pull Request #6 · AssemblyScript/node

Conversation

@jtenner

@jtenner jtenner commented Jul 19, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Implements Buffer.from<T>(value: T) and a few other convenience functions.

There are lots of obvious problems with not having the function overloads, but there are different paths we can take.

For instance, because there are no optional parameters, we must assume that the default encoding for strings is UTF8.

// utf-16 has a work around in AssemblyScript
let buff = Buffer.from(String.UTF16.encode(value));

// using Buffer.fromString(value, "utf16le");

Things to note about this function:

  • String[] objects do something complicated: string -> f64 -> u8 to remain compatible with node.
> Buffer.from(["3", "257.3", "15", "Infinity", "NaN"])
<Buffer 03 01 0F 00 00>
  • String objects need to be converted to UTF8
  • Buffer objects share their view of the same ArrayBuffer
  • ArrayBuffer objects are simply attached to a new Buffer
  • ArrayBufferView objects need to convert their values to u8.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jtenner
jtenner requested a review from dcodeIO July 19, 2019 18:24
@jtenner jtenner self-assigned this Jul 19, 2019
@jtenner jtenner added the enhancement New feature or request label Jul 19, 2019
@jtenner
[Implement] Naive Buffer.from
62b4dc9
@jtenner
jtenner force-pushed the from branch from 96b1872 to 62b4dc9 Compare July 19, 2019 19:02
jtenner added 9 commits July 20, 2019 14:30
@jtenner
[Cleanup] remove log function
3b67754
@jtenner
[Cleanup] add T extends ArrayBufferView to squelch intellisense
c2a6432
@jtenner
[Chore] merge master
daf9dc1
@jtenner
Merge branch 'from' of https://github.com/AssemblyScript/node into from
ba78bc9
@jtenner
Merge branch 'master' of https://github.com/AssemblyScript/node into …
66af315
…from
@jtenner
[merge] from master
cc536a0
@jtenner
[Fix] array of strings implementation
c6997e1
@jtenner
Merge branch 'master' of https://github.com/assemblyscript/node into …
a333399
…from
@jtenner
[Implement] rest of buffer.from functions per dcode
45a61c5
@jtenner jtenner changed the title [Implement] Naive Buffer.from [Implement] Naive Buffer.from, and friends Aug 22, 2019
@jtenner

jtenner commented Aug 22, 2019

Copy link
Copy Markdown
Contributor Author

@RedDwarfian and @dcodeIO thoughts on this pull request?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@RedDwarfian

RedDwarfian commented Aug 22, 2019

Copy link
Copy Markdown
Contributor

It is not clear in the Naive Buffer.from code where non-string arrays such as Array<u8> are handled. I would suggest adding a comment to clarify that.

jtenner reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jtenner added 2 commits March 12, 2020 23:52
@jtenner
merge master, add helper assembleBuffer function, fix tests
a05852d
@jtenner
remove type info
7f69832
@jtenner

jtenner commented Mar 13, 2020

Copy link
Copy Markdown
Contributor Author

We might like to pull the ASCII encoding pull request first. #27

Otherwise, this is ready for review.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jtenner added 2 commits March 13, 2020 00:14
@jtenner
Merge branch 'master' of https://github.com/assemblyscript/node into …
92c303d
…from
@jtenner
add ascii encoding
11be548
jtenner
jtenner commented Mar 13, 2020
View reviewed changes
Comment thread assembly/buffer/index.ts Outdated
if (i32(byteOffset < 0) | i32(byteOffset > buffer.byteLength - length)) throw new RangeError(E_INDEXOUTOFRANGE);
if (length == 0) return new Buffer(0);

return assembleBuffer(changetype<usize>(buffer), <usize>byteOffset, <u32>length);

@jtenner jtenner Mar 13, 2020

Copy link
Copy Markdown
Contributor Author

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.

@MaxGraey should this be min(length, buffer.byteLength - byteOffset)?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
jtenner
jtenner commented Mar 13, 2020
View reviewed changes
Comment thread assembly/buffer/index.ts
return assembleBuffer(changetype<usize>(buffer), 0, buffer.byteLength);
}

public static fromArray<T extends ArrayBufferView>(value: T, offset: i32 = 0, length: i32 = -1): Buffer {

@jtenner jtenner Mar 13, 2020

Copy link
Copy Markdown
Contributor Author

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.

@dcodeIO what is going to happen to this extends clause? Are we going to detach Array from ArrayBufferView?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
jtenner
jtenner commented Mar 13, 2020
View reviewed changes
Comment thread assembly/buffer/index.ts

// return and retain
return changetype<Buffer>(result);
// @ts-ignore: Buffer returns on all valid branches

@jtenner jtenner Mar 13, 2020

Copy link
Copy Markdown
Contributor Author

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.

We can suppress this error by returning changetype<Buffer>(null) at the bottom here after the ERROR. What is the right way to do this?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jtenner
jtenner requested a review from MaxGraey March 13, 2020 04:23
MaxGraey
MaxGraey reviewed Mar 13, 2020
View reviewed changes
Comment thread assembly/buffer/index.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

@jtenner
rename to allocBuffer
7f3e8c2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@MaxGraey MaxGraey MaxGraey left review comments
@dcodeIO dcodeIO Awaiting requested review from dcodeIO

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@jtenner jtenner

Labels

enhancement New feature or request

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@jtenner @RedDwarfian @MaxGraey
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.