本文整理汇总了C#中Google.ToByteArray方法的典型用法代码示例。如果您正苦于以下问题:C# Google.ToByteArray方法的具体用法?C# Google.ToByteArray怎么用?C# Google.ToByteArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Google
的用法示例。
在下文中一共展示了Google.ToByteArray方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SavePersonImage
public string SavePersonImage( Google.Protobuf.ByteString bytes, long personid)
{
string filename = DateTime.Now.Ticks.ToString() + ".jpg";
string localPath = String.Format("media\\person\\{0}\\photo\\{1}", personid, filename );
string fullPath = String.Format("{0}{1}", LocalStorage, localPath );
SaveFile(bytes.ToByteArray(), fullPath);
return localPath;
}
示例2: SendProtobuf
public void SendProtobuf(Google.ProtocolBuffers.IMessage message, PACKET_TYPE packet_type)
{
if (m_socket == null || m_socket.Connected == false)
{
Disconnect();
return;
}
byte[] type_bytes = BitConverter.GetBytes((int)packet_type);
byte[] packet_buffer = message.ToByteArray();
int size = packet_buffer.Length;
byte[] size_bytes = BitConverter.GetBytes(size);
int buf_size = packet_buffer.Length + size_bytes.Length + type_bytes.Length;
byte[] send_buf = new byte[buf_size];
System.Buffer.BlockCopy(size_bytes, 0, send_buf, 0, size_bytes.Length);
System.Buffer.BlockCopy(type_bytes, 0, send_buf, size_bytes.Length, type_bytes.Length);
System.Buffer.BlockCopy(packet_buffer, 0, send_buf, size_bytes.Length + type_bytes.Length, packet_buffer.Length);
m_socket.Send(send_buf);
// Console.WriteLine("Send len({0}) = header({1} + {2}) + body({3})", buf_size, size_bytes.Length, type_bytes.Length, packet_buffer.Length);
}
示例3: prepareMessage
/// <summary>
/// Prepares the Protobuf message for sending via Cometd.
/// </summary>
/// <param name="message">Google ProtocolBuffers message</param>
/// <returns>A dictionary with two elements.</returns>
public static Dictionary<string, Object> prepareMessage(Google.ProtocolBuffers.IMessage message)
{
Dictionary<string, Object> output = new Dictionary<string, Object>();
if (message != null)
{
output.Add("type", message.GetType().ToString());
output.Add("s", Convert.ToBase64String(message.ToByteArray()));
}
return output;
}