private static CodedInputStream GetInputSteam(Stream input) { #if POOL if (_sharedInputSteam == null) { byte[] result = new byte[input.Length]; _sharedInputSteam = new CodedInputStream(input, result, 0, 0, false); } else { long size = input.Length; if (_sharedInputSteam.Capacity == size) { _sharedInputSteam.Reset(input, 0, 0, false); } else { _sharedInputSteam.Reset(input, new byte[size], 0, 0, false); } } return(_sharedInputSteam); #else return(new CodedInputStream(input)); #endif }
/// <summary> /// Merges data from the given byte array into an existing message. /// </summary> /// <param name="message">The message to merge the data into.</param> /// <param name="data">The data to merge, which must be protobuf-encoded binary data.</param> public static void MergeFrom(this IMessage message, byte[] data) { ProtoPreconditions.CheckNotNull(message, "message"); ProtoPreconditions.CheckNotNull(data, "data"); inputStream.Reset(data, 0, data.Length); CodedInputStream input = inputStream; message.MergeFrom(input); input.CheckReadEndOfStreamTag(); }