C# Class SharpOS.Kernel.Foundation.BinaryTool

Datei anzeigen Open project: sharpos/SharpOS

Public Methods

Method Description
Read7BitInt ( void ptr, int ret_len ) : int
ReadPrefixedString ( void ptr, byte buffer, int bufferLen ) : int
ReadPrefixedString ( void ptr, byte buffer, int bufferLen, int error ) : int

Reads a length-prefixed string as generated by a .NET BinaryReader class. This involves first reading a variable-size 7-bit integer, then the string, placing it in the provided buffer. If the buffer is not large enough, the 'error' parameter is set to 1. The string is still readable in 'buffer', but it is shortened. To prevent this, you can call Read7BitEncodedInt first and size the buffer appropriately. Returns the amount of bytes that the length-prefixed string took up (including the bytes that contained the length), so it can be skipped when reading more data. The 'buffer' will be null-terminated, even if it is too small. The returned value is not reduced if the buffer is too small (IE, it represents the entire string, not the shortened version).

Method Details

Read7BitInt() public static method

public static Read7BitInt ( void ptr, int ret_len ) : int
ptr void
ret_len int
return int

ReadPrefixedString() public static method

public static ReadPrefixedString ( void ptr, byte buffer, int bufferLen ) : int
ptr void
buffer byte
bufferLen int
return int

ReadPrefixedString() public static method

Reads a length-prefixed string as generated by a .NET BinaryReader class. This involves first reading a variable-size 7-bit integer, then the string, placing it in the provided buffer. If the buffer is not large enough, the 'error' parameter is set to 1. The string is still readable in 'buffer', but it is shortened. To prevent this, you can call Read7BitEncodedInt first and size the buffer appropriately. Returns the amount of bytes that the length-prefixed string took up (including the bytes that contained the length), so it can be skipped when reading more data. The 'buffer' will be null-terminated, even if it is too small. The returned value is not reduced if the buffer is too small (IE, it represents the entire string, not the shortened version).
public static ReadPrefixedString ( void ptr, byte buffer, int bufferLen, int error ) : int
ptr void
buffer byte
bufferLen int
error int
return int