Google.Protobuf.ByteString

Immutable array of bytes.

Summary

Inheritance

Inherits from: IEnumerable< byte >, IEquatable< ByteString >

Properties

Empty
ByteString
Returns an empty ByteString.
IsEmpty
bool
Returns true if this byte string is empty, false otherwise.
Length
int
Returns the length of this ByteString in bytes.
this[int index]
byte
Returns the byte at the given index.

Public functions

CopyTo(byte[] array, int position)
void
Copies the entire byte array to the destination array provided at the offset specified.
CreateCodedInput()
CodedInputStream
Creates a CodedInputStream from this ByteString's data.
Equals(object obj)
override bool
Compares this byte string with another object.
Equals(ByteString other)
bool
Compares this byte string with another.
GetEnumerator()
IEnumerator< byte >
Returns an iterator over the bytes in this ByteString.
GetHashCode()
override int
Returns a hash code for this object.
ToBase64()
string
Converts this ByteString into a standard base64 representation.
ToByteArray()
byte[]
Converts this ByteString into a byte array.
ToString(Encoding encoding)
string
Converts this ByteString into a string by applying the given encoding.
ToStringUtf8()
string
Converts this ByteString into a string by applying the UTF-8 encoding.
WriteTo(Stream outputStream)
void
Writes the entire byte array to the provided stream

Public static functions

CopyFrom(params byte[] bytes)
ByteString
Constructs a ByteString from the given array.
CopyFrom(byte[] bytes, int offset, int count)
ByteString
Constructs a ByteString from a portion of a byte array.
CopyFrom(string text, Encoding encoding)
ByteString
Creates a new ByteString by encoding the specified text with the given encoding.
CopyFromUtf8(string text)
ByteString
Creates a new ByteString by encoding the specified text in UTF-8.
FromBase64(string bytes)
ByteString
Constructs a ByteString from the Base64 Encoded String.
operator!=(ByteString lhs, ByteString rhs)
bool
Compares two byte strings for inequality.
operator==(ByteString lhs, ByteString rhs)
bool
Compares two byte strings for equality.

Properties

Empty

ByteString Empty

Returns an empty ByteString.

IsEmpty

bool IsEmpty

Returns true if this byte string is empty, false otherwise.

Length

int Length

Returns the length of this ByteString in bytes.

this[int index]

byte this[int index]

Returns the byte at the given index.

Public functions

CopyTo

void CopyTo(
  byte[] array,
  int position
)

Copies the entire byte array to the destination array provided at the offset specified.

CreateCodedInput

CodedInputStream CreateCodedInput()

Creates a CodedInputStream from this ByteString's data.

Equals

override bool Equals(
  object obj
)

Compares this byte string with another object.

Details
Parameters
obj
The object to compare this with.
Returns
true if obj refers to an equal ByteString; false otherwise.

Equals

bool Equals(
  ByteString other
)

Compares this byte string with another.

Details
Parameters
other
The ByteString to compare this with.
Returns
true if other refers to an equal byte string; false otherwise.

GetEnumerator

IEnumerator< byte > GetEnumerator()

Returns an iterator over the bytes in this ByteString.

Details
Returns
An iterator over the bytes in this object.

GetHashCode

override int GetHashCode()

Returns a hash code for this object.

Two equal byte strings will return the same hash code.

Details
Returns
A hash code for this object.

ToBase64

string ToBase64()

Converts this ByteString into a standard base64 representation.

Details
Returns
A base64 representation of this ByteString.

ToByteArray

byte[] ToByteArray()

Converts this ByteString into a byte array.

The data is copied - changes to the returned array will not be reflected in this ByteString.

Details
Returns
A byte array with the same data as this ByteString.

ToString

string ToString(
  Encoding encoding
)

Converts this ByteString into a string by applying the given encoding.

This method should only be used to convert binary data which was the result of encoding text with the given encoding.

Details
Parameters
encoding
The encoding to use to decode the binary data into text.
Returns
The result of decoding the binary data with the given decoding.

ToStringUtf8

string ToStringUtf8()

Converts this ByteString into a string by applying the UTF-8 encoding.

This method should only be used to convert binary data which was the result of encoding text with UTF-8.

Details
Returns
The result of decoding the binary data with the given decoding.

WriteTo

void WriteTo(
  Stream outputStream
)

Writes the entire byte array to the provided stream

Public static functions

CopyFrom

ByteString CopyFrom(
  params byte[] bytes
)

Constructs a ByteString from the given array.

The contents are copied, so further modifications to the array will not be reflected in the returned ByteString. This method can also be invoked in ByteString.CopyFrom(0xaa, 0xbb, ...) form which is primarily useful for testing.

CopyFrom

ByteString CopyFrom(
  byte[] bytes,
  int offset,
  int count
)

Constructs a ByteString from a portion of a byte array.

CopyFrom

ByteString CopyFrom(
  string text,
  Encoding encoding
)

Creates a new ByteString by encoding the specified text with the given encoding.

CopyFromUtf8

ByteString CopyFromUtf8(
  string text
)

Creates a new ByteString by encoding the specified text in UTF-8.

FromBase64

ByteString FromBase64(
  string bytes
)

Constructs a ByteString from the Base64 Encoded String.

operator!=

bool operator!=(
  ByteString lhs,
  ByteString rhs
)

Compares two byte strings for inequality.

Details
Parameters
lhs
The first byte string to compare.
rhs
The second byte string to compare.
Returns
false if the byte strings are equal; true otherwise.

operator==

bool operator==(
  ByteString lhs,
  ByteString rhs
)

Compares two byte strings for equality.

Details
Parameters
lhs
The first byte string to compare.
rhs
The second byte string to compare.
Returns
true if the byte strings are equal; false otherwise.