You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			23 lines
		
	
	
		
			788 B
		
	
	
	
		
			TypeScript
		
	
			
		
		
	
	
			23 lines
		
	
	
		
			788 B
		
	
	
	
		
			TypeScript
		
	
| import ByteBuffer from 'bytebuffer';
 | |
| 
 | |
| type Encoding = 'base64' | 'hex' | 'binary' | 'utf8';
 | |
| type BufferType = ByteBuffer | Buffer | ArrayBuffer | Uint8Array;
 | |
| 
 | |
| /**
 | |
|  * Take a string value with the given encoding and converts it to an `ArrayBuffer`.
 | |
|  * @param value The string value.
 | |
|  * @param encoding The encoding of the string value.
 | |
|  */
 | |
| export function encode(value: string, encoding: Encoding): ArrayBuffer {
 | |
|   return ByteBuffer.wrap(value, encoding).toArrayBuffer();
 | |
| }
 | |
| 
 | |
| /**
 | |
|  * Take a buffer and convert it to a string with the given encoding.
 | |
|  * @param buffer The buffer.
 | |
|  * @param stringEncoding The encoding of the converted string value.
 | |
|  */
 | |
| export function decode(buffer: BufferType, stringEncoding: Encoding): string {
 | |
|   return ByteBuffer.wrap(buffer).toString(stringEncoding);
 | |
| }
 |