Skip to content

Instantly share code, notes, and snippets.

@lojjic
Created October 23, 2021 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lojjic/94d7b5f5f374598fe0e9761be45ebb2b to your computer and use it in GitHub Desktop.
Save lojjic/94d7b5f5f374598fe0e9761be45ebb2b to your computer and use it in GitHub Desktop.
Typr._bin using DataView
Typr._bin = {
//...
readInt : function(buff, p)
{
return Typr._bin._view(buff).getInt32(p);
},
readInt8 : function(buff, p)
{
return Typr._bin._view(buff).getInt8(p);
},
readShort : function(buff, p)
{
return Typr._bin._view(buff).getInt16(p);
},
readUshort : function(buff, p)
{
return Typr._bin._view(buff).getUint16(p);
},
readUint : function(buff, p)
{
return Typr._bin._view(buff).getUint32(p);
},
//...
_view: function(buff) {
return buff._dataView || (buff._dataView = new DataView(buff.buffer, buff.byteOffset, buff.byteLength));
}
};
@lojjic
Copy link
Author

lojjic commented Oct 23, 2021

POC of Typr._bin using DataView to read the various number formats rather than several typed arrays sharing a single buffer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment