René's URL Explorer Experiment


Title: More flexible extension support · Issue #192 · msgpack/msgpack-javascript · GitHub

Open Graph Title: More flexible extension support · Issue #192 · msgpack/msgpack-javascript

X Title: More flexible extension support · Issue #192 · msgpack/msgpack-javascript

Description: TLDR: I'd like to suggest a tweak to the extension API. As well as the current process where an extension returns a blob which the encoder copies, I propose allowing an extension to use the "private" API of the encoder to directly perfor...

Open Graph Description: TLDR: I'd like to suggest a tweak to the extension API. As well as the current process where an extension returns a blob which the encoder copies, I propose allowing an extension to use the "privat...

X Description: TLDR: I'd like to suggest a tweak to the extension API. As well as the current process where an extension returns a blob which the encoder copies, I propose allowing an extension to use the &qu...

Opengraph URL: https://github.com/msgpack/msgpack-javascript/issues/192

X: @github

direct link

Domain: redirect.github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"More flexible extension support","articleBody":"**TLDR:**\r\n\r\nI'd like to suggest a tweak to the extension API. As well as the current process where an extension returns a blob which the encoder copies, I propose allowing an extension to use the \"private\" API of the encoder to directly perform writes.\r\n\r\nI have prototyped this extension mechanism in a fork. The changes are minimal. See comparison [here](https://github.com/msgpack/msgpack-javascript/compare/main...crabmusket:typed-arrays-plugin#diff-2b07fa9965c82a4be8829b5cdcaff0dbd4e71fe8e601e353efcd72eee2e0c243).\r\n\r\nIf you agree that this idea is desirable I'm happy to clean up my branch, add tests and make a PR.\r\n\r\n---\r\n\r\nI came across this need when I was trying to design an extension to handle TypedArrays natively, but also to _align_ them to the correct byte indexes so that they can be used efficiently after decoding. You can see my extension [here](https://github.com/crabmusket/msgpack-javascript/tree/typed-arrays-plugin/example/typed-arrays) - the readme explains the alignment situation. (And my original comment [here](https://github.com/msgpack/msgpack-javascript/issues/76#issuecomment-922411931).)\r\n\r\n```js\r\n// Encoding and decoding a TypedArray with no boilerplate:\r\nconst floatArray = new Float32Array([1, 2, 3, 4, 5]);\r\nconst encoded = encode({ floatArray }, { extensionCodec });\r\nassert.deepStrictEqual(decode(encoded, { extensionCodec }), { floatArray });\r\n```\r\n\r\nUsing the _current_ extension API to do this, I would need to:\r\n\r\n1. Do an extra copy, from the TypedArray to a Uint8Array containing my extra wrapper and alignment bytes\r\n2. Predict which of MsgPack's extension headers the base encoder will use when writing my extension data, and adjust alignment accordingly\r\n3. Use a reference to the encoder _anyway_, to get the current value of `pos`. I'd have to send this circular reference into the extension codec's context object\r\n\r\nProblem 1 isn't such a big deal; there's a lot of copying during encoding anyway, though I minimise it by choosing appropriate initial buffer sizes. And if copying can be avoided, why not?\r\n\r\nProblem 2 is the main issue I am interested in; I was frankly too lazy to do the maths required to predict the ext header size and then modify the alignment accordingly. My fork allows extensions to directly call the encoder's `write` methods, which means that I was able to always choose an `ext 32` header. This makes it easy to predict the alignment requirements. A small amount of bytes are wasted, but my use-case is for large data arrays where a handful of bytes will make almost no difference to the final payload size.\r\n\r\n---\r\n\r\nIn order to implement this extension efficiently, I added a [write method](https://github.com/crabmusket/msgpack-javascript/blob/7f84239463b162358ec11a39ced36fdb878b35a4/src/ExtData.ts#L9-L11) to ExtData. My plugin returns a [subclass](https://github.com/crabmusket/msgpack-javascript/blob/7f84239463b162358ec11a39ced36fdb878b35a4/example/typed-arrays/plugin.ts#L78) of ExtData which has its own implementation of `write`.\r\n\r\nThis was just a rough cut to see if the concept worked. If I were designing this properly, I'd replace the use of the `ExtData` class with an interface to avoid mandatory inheritance hierarchies. You can see in my `TypedArrayExtData` I'm already being silly by calling the parent constructor with a `new Uint8Array()` which is completely unused.\r\n\r\n---\r\n\r\nPros of this idea:\r\n\r\n- Allows fewer copies during encoding\r\n- Allows me to implement alignment much more easily by controlling which `ext` header is written\r\n\r\nCons of this idea:\r\n\r\n- Introduces an additional method call during the encoding process (`extData.write`, which currently calls straight back to `encoder.encodeExtension`. I think this is an example of \"double dispatch\" in OOP parlance?)\r\n- Extensions using this approach rely on the private API of the Encoder\r\n- I haven't thought about recursive encoding 🤔 \r\n\r\nFor my use case, I didn't mind using the private API. This library seems stable enough. But for my use-case, I would _also_ have to depend on internal implementation details when guessing alignment: if the library ever used different ext headers for the same data size, then my alignment guesses would be wrong. I see no reason why that logic would ever change, but it's still an implementation detail.\r\n\r\nHowever, you might not want to allow clients to depend on this behaviour. It could be worked around, e.g. by providing an adapter with stable public methods which call the encoder's `write` methods.","author":{"url":"https://github.com/crabmusket","@type":"Person","name":"crabmusket"},"datePublished":"2021-09-21T02:11:47.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/192/msgpack-javascript/issues/192"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:aa85cd98-11ca-4fc4-aef5-89a20fe2074a
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idCF88:1FB1C7:5750A:763CA:6A5232C7
html-safe-nonce8dfa8fa6bc2d8b775e51e96d13b896747332a5a954de056bd93db1b51f55a7d3
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRjg4OjFGQjFDNzo1NzUwQTo3NjNDQTo2QTUyMzJDNyIsInZpc2l0b3JfaWQiOiI3NDU2MTYxNzk3MTM5MjE1MDQ3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac5e51065a18a0fcb67305d24949c390c65c2f937aa302f3db0e4286fcc11c0b2f
hovercard-subject-tagissue:1001685990
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/msgpack/msgpack-javascript/192/issue_layout
twitter:imagehttps://opengraph.githubassets.com/d1b3a7c62f67bd01ebf2b3a75dcebb3ea7cec274cb143037de4a8f5fbcc03380/msgpack/msgpack-javascript/issues/192
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/d1b3a7c62f67bd01ebf2b3a75dcebb3ea7cec274cb143037de4a8f5fbcc03380/msgpack/msgpack-javascript/issues/192
og:image:altTLDR: I'd like to suggest a tweak to the extension API. As well as the current process where an extension returns a blob which the encoder copies, I propose allowing an extension to use the "privat...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamecrabmusket
hostnamegithub.com
expected-hostnamegithub.com
Noneb9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb
turbo-cache-controlno-preview
go-importgithub.com/msgpack/msgpack-javascript git https://github.com/msgpack/msgpack-javascript.git
octolytics-dimension-user_id198264
octolytics-dimension-user_loginmsgpack
octolytics-dimension-repository_id2761854
octolytics-dimension-repository_nwomsgpack/msgpack-javascript
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id2761854
octolytics-dimension-repository_network_root_nwomsgpack/msgpack-javascript
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release7aed05249554b889eb33d002851a973eebcc7e91
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://redirect.github.com/msgpack/msgpack-javascript/issues/192#start-of-content
https://redirect.github.com/
Sign in https://redirect.github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmsgpack%2Fmsgpack-javascript%2Fissues%2F192
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://redirect.github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmsgpack%2Fmsgpack-javascript%2Fissues%2F192
Sign up https://redirect.github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=msgpack%2Fmsgpack-javascript
Reloadhttps://redirect.github.com/msgpack/msgpack-javascript/issues/192
Reloadhttps://redirect.github.com/msgpack/msgpack-javascript/issues/192
Reloadhttps://redirect.github.com/msgpack/msgpack-javascript/issues/192
Please reload this pagehttps://redirect.github.com/msgpack/msgpack-javascript/issues/192
msgpack https://redirect.github.com/msgpack
msgpack-javascripthttps://redirect.github.com/msgpack/msgpack-javascript
Notifications https://redirect.github.com/login?return_to=%2Fmsgpack%2Fmsgpack-javascript
Fork 177 https://redirect.github.com/login?return_to=%2Fmsgpack%2Fmsgpack-javascript
Star 1.6k https://redirect.github.com/login?return_to=%2Fmsgpack%2Fmsgpack-javascript
Code https://redirect.github.com/msgpack/msgpack-javascript
Issues 17 https://redirect.github.com/msgpack/msgpack-javascript/issues
Pull requests 5 https://redirect.github.com/msgpack/msgpack-javascript/pulls
Discussions https://redirect.github.com/msgpack/msgpack-javascript/discussions
Actions https://redirect.github.com/msgpack/msgpack-javascript/actions
Security and quality 0 https://redirect.github.com/msgpack/msgpack-javascript/security
Insights https://redirect.github.com/msgpack/msgpack-javascript/pulse
Code https://redirect.github.com/msgpack/msgpack-javascript
Issues https://redirect.github.com/msgpack/msgpack-javascript/issues
Pull requests https://redirect.github.com/msgpack/msgpack-javascript/pulls
Discussions https://redirect.github.com/msgpack/msgpack-javascript/discussions
Actions https://redirect.github.com/msgpack/msgpack-javascript/actions
Security and quality https://redirect.github.com/msgpack/msgpack-javascript/security
Insights https://redirect.github.com/msgpack/msgpack-javascript/pulse
More flexible extension supporthttps://redirect.github.com/msgpack/msgpack-javascript/issues/192#top
https://github.com/crabmusket
crabmuskethttps://github.com/crabmusket
on Sep 21, 2021https://github.com/msgpack/msgpack-javascript/issues/192#issue-1001685990
herehttps://github.com/msgpack/msgpack-javascript/compare/main...crabmusket:typed-arrays-plugin#diff-2b07fa9965c82a4be8829b5cdcaff0dbd4e71fe8e601e353efcd72eee2e0c243
herehttps://github.com/crabmusket/msgpack-javascript/tree/typed-arrays-plugin/example/typed-arrays
herehttps://github.com/msgpack/msgpack-javascript/issues/76#issuecomment-922411931
write methodhttps://github.com/crabmusket/msgpack-javascript/blob/7f84239463b162358ec11a39ced36fdb878b35a4/src/ExtData.ts#L9-L11
subclasshttps://github.com/crabmusket/msgpack-javascript/blob/7f84239463b162358ec11a39ced36fdb878b35a4/example/typed-arrays/plugin.ts#L78
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.