Prajna


StreamExtension

Extension Methods for System.IO.Stream

Static members

Static memberDescription
ReadBoolean(x)
Signature: x:Stream -> bool

Read a boolean from bytestream. If the end of the stream is reached, the function will return true.

ReadBytes(x, len)
Signature: (x:Stream * len:int) -> byte []

Read a bytearray of len bytes to the current stream. The function always return a bytearray of size len even if the number of bytes that is currently available is less (or even zero if the end of the stream is reached before any bytes are read). In such a case, the remainder of the bytearray is filled with zero.

ReadBytes(x, buf)
Signature: (x:Stream * buf:byte []) -> int

Read a bytearray from the current stream. The length of bytes to be read is determined by the size of the bytearray.

ReadBytesToEnd(x)
Signature: x:Stream -> byte []

Attempt to read the remainder of the bytestream as a single bytearray.

ReadBytesWLen(x)
Signature: x:Stream -> byte []

Read a bytearray from bytestream that is prefixed with length of the bytearray. If the bytestream is truncated prematurely, the returned bytearray will be a bytearray of remainder of the bytestram.

ReadBytesWVLen(x)
Signature: x:Stream -> byte []

Read a bytearray from bytestream that is prefixed with length of the bytearray. If the bytestream is truncated prematurely, the returned bytearray will be a bytearray of remainder of the bytestram.

ReadDouble(x)
Signature: x:Stream -> float

Read a double float value from bytestream. If the number of bytes that is currently available is less (or if the end of the stream is reached before any bytes are read), the late read bytes of double will be fillled with zero.

ReadGuid(x)
Signature: x:Stream -> Guid

Read a Guid from bytestream. If the number of bytes that is currently available is less (or if the end of the stream is reached before any bytes are read), the remainder of Guid will be fillled with zero.

ReadInt16(x)
Signature: x:Stream -> int16

Read a int16 from bytestream. If the number of bytes that is currently available is less (or if the end of the stream is reached before any bytes are read), the high order bytes of int16 will be fillled with zero.

ReadInt32(x)
Signature: x:Stream -> int

Read a int32 from bytestream. If the number of bytes that is currently available is less (or if the end of the stream is reached before any bytes are read), the high order bytes of uint32 will be fillled with zero.

ReadInt64(x)
Signature: x:Stream -> int64

Read a int64 from bytestream. If the number of bytes that is currently available is less (or if the end of the stream is reached before any bytes are read), the high order bytes of int64 will be fillled with zero.

ReadIPEndPoint(x)
Signature: x:Stream -> IPEndPoint

Read IPEndPoint from bytestream, if the bytestream is truncated prematurely, the later IPAddress and port information will be 0.

ReadJson(x)
Signature: x:Stream -> 'T
Type parameters: 'T

Read a json object from bytestream

ReadSingle(x)
Signature: x:Stream -> float32

Read a single float value from bytestream. If the number of bytes that is currently available is less (or if the end of the stream is reached before any bytes are read), the late read bytes of single will be fillled with zero.

ReadString(x)
Signature: x:Stream -> string

Read a string (UTF8Encoded) from bytestream with prefix of the bytearray. If the bytestream is truncated prematurely, the returned string will be ""

ReadStringV(x)
Signature: x:Stream -> string

Read a string (UTF8Encoded) from bytestream with prefix (VLC coded) of the bytearray. If the bytestream is truncated prematurely, the returned string will be ""

ReadUInt16(x)
Signature: x:Stream -> uint16

Read a uint16 from bytestream. If the number of bytes that is currently available is less (or if the end of the stream is reached before any bytes are read), the high order bytes of uint16 will be fillled with zero.

ReadUInt32(x)
Signature: x:Stream -> uint32

Read a uint32 from bytestream. If the number of bytes that is currently available is less (or if the end of the stream is reached before any bytes are read), the high order bytes of uint32 will be fillled with zero.

ReadUInt64(x)
Signature: x:Stream -> uint64

Read a uint64 from bytestream. If the number of bytes that is currently available is less (or if the end of the stream is reached before any bytes are read), the high order bytes of uint64 will be fillled with zero.

ReadVInt32(x)
Signature: x:Stream -> int

Read a int32 from bytestream with variable length coding (VLC). For value between -127..+127 -> one byte is used to encode the int32 For other value -> 0x80 + 4Byte (5 bytes are used to encode the int32) If the end of the stream has been reached at the moment of read, ReadVInt32() will return 0. If at least one byte is read, but the number of bytes that is currently available is less (or if the end of the stream is reached before any bytes are read), the high order bytes of int32 will be fillled with zero.

WriteBoolean(x, b)
Signature: (x:Stream * b:bool) -> unit

Write a boolean into bytestream, with 1uy represents true and 0uy represents false

WriteBytes(x, buf)
Signature: (x:Stream * buf:byte []) -> unit

Writes a bytearray to the current stream.

WriteBytesWithOffset(...)
Signature: (x:Stream * buf:byte [] * offset:int * count:int) -> unit

Writes a bytearray with offset and count to the current stream.

WriteBytesWLen(x, buf)
Signature: (x:Stream * buf:byte []) -> unit

Write a bytearray to bytestream and prefix with length of the bytearray.

WriteBytesWVLen(x, buf)
Signature: (x:Stream * buf:byte []) -> unit

Write a bytearray to bytestream and prefix with a length (VLC coded) of the bytearray. If the bytearray is null, the bytestream is written to indicate that is a bytearray of size 0.

WriteDouble(x, b)
Signature: (x:Stream * b:float) -> unit

Write a double float value to bytestream.

WriteGuid(x, id)
Signature: (x:Stream * id:Guid) -> unit

Write a Guid to bytestream.

WriteInt16(x, b)
Signature: (x:Stream * b:int16) -> unit

Write a int16 to bytestream.

WriteInt32(x, b)
Signature: (x:Stream * b:int32) -> unit

Write a int32 to bytestream.

WriteInt64(x, b)
Signature: (x:Stream * b:int64) -> unit

Write a int64 to bytestream.

WriteIPEndPoint(x, addr)
Signature: (x:Stream * addr:IPEndPoint) -> unit

Write IPEndPoint to bytestream

WriteJson(x, data)
Signature: (x:Stream * data:'T) -> unit
Type parameters: 'T

Write a json object to bytestream

WriteSingle(x, b)
Signature: (x:Stream * b:float32) -> unit

Write a single float value to bytestream.

WriteString(x, s)
Signature: (x:Stream * s:string) -> unit

Write a string (UTF8Encoded) to bytestream and prefix with a length of the bytearray. If the string is null, the bytestream is written to indicate that is a string of length 0.

WriteStringV(x, s)
Signature: (x:Stream * s:string) -> unit

Write a string (UTF8Encoded) to bytestream and prefix with a length (VLC coded) of the bytearray. If the string is null, the bytestream is written to indicate that is a string of length 0.

WriteUInt16(x, b)
Signature: (x:Stream * b:uint16) -> unit

Write a uint16 to bytestream.

WriteUInt32(x, b)
Signature: (x:Stream * b:uint32) -> unit

Write a uint32 to bytestream.

WriteUInt64(x, b)
Signature: (x:Stream * b:uint64) -> unit

Write a uint64 to bytestream.

WriteVInt32(x, b)
Signature: (x:Stream * b:int32) -> unit

Write a int32 to bytestream with variable length coding (VLC). For value between -127..+127 -> one byte is used to encode the int32 For other value -> 0x80 + 4Byte (5 bytes are used to encode the int32)

Fork me on GitHub