-
-
Save lojjic/94d7b5f5f374598fe0e9761be45ebb2b to your computer and use it in GitHub Desktop.
Typr._bin using DataView
This file contains 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
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)); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
POC of Typr._bin using DataView to read the various number formats rather than several typed arrays sharing a single buffer