public void SetConnectionMeteringContentHandles(ConnectionMeteringContentHandles handles, LocalStorageAPI localStorage) { if (((handles == null) || !handles.IsInitialized) || (handles.ContentHandleCount == 0)) { this.m_cmLogSource.LogWarning("Invalid connection metering content handle received."); } else { if (handles.ContentHandleCount != 1) { this.m_cmLogSource.LogWarning("More than 1 connection metering content handle specified!"); } bnet.protocol.ContentHandle contentHandle = handles.ContentHandle[0]; if ((contentHandle == null) || !contentHandle.IsInitialized) { this.m_cmLogSource.LogWarning("The content handle received is not valid!"); } else { this.m_cmLogSource.LogDebug("Received request to enable connection metering."); ContentHandle ch = ContentHandle.FromProtocol(contentHandle); object[] args = new object[] { ch }; this.m_cmLogSource.LogDebug("Requesting file from local storage. ContentHandle={0}", args); localStorage.GetFile(ch, new LocalStorageAPI.DownloadCompletedCallback(this.DownloadCompletedCallback)); } } }
public static ContentHandle DeserializeLengthDelimited(Stream stream) { ContentHandle contentHandle = new ContentHandle(); ContentHandle.DeserializeLengthDelimited(stream, contentHandle); return(contentHandle); }
public static ContentHandle DeserializeLengthDelimited(Stream stream, ContentHandle instance) { long num = (long)((ulong)ProtocolParser.ReadUInt32(stream)); num += stream.get_Position(); return(ContentHandle.Deserialize(stream, instance, num)); }
public void SetConnectionMeteringContentHandles(ConnectionMeteringContentHandles handles, LocalStorageAPI localStorage) { if (handles == null || !handles.IsInitialized || handles.ContentHandleCount == 0) { this.m_cmLogSource.LogWarning("Invalid connection metering content handle received."); return; } if (handles.ContentHandleCount != 1) { this.m_cmLogSource.LogWarning("More than 1 connection metering content handle specified!"); } bnet.protocol.ContentHandle contentHandle = handles.ContentHandle.get_Item(0); if (contentHandle == null || !contentHandle.IsInitialized) { this.m_cmLogSource.LogWarning("The content handle received is not valid!"); return; } this.m_cmLogSource.LogDebug("Received request to enable connection metering."); ContentHandle contentHandle2 = ContentHandle.FromProtocol(contentHandle); this.m_cmLogSource.LogDebug("Requesting file from local storage. ContentHandle={0}", new object[] { contentHandle2 }); localStorage.GetFile(contentHandle2, new LocalStorageAPI.DownloadCompletedCallback(this.DownloadCompletedCallback), null); }
private void GetContentHandleCallback(RPCContext context) { ResourcesAPIPendingState resourcesAPIPendingState = null; if (!this.m_pendingLookups.TryGetValue(context.Header.Token, out resourcesAPIPendingState)) { base.ApiLog.LogWarning("Received unmatched lookup response"); return; } this.m_pendingLookups.Remove(context.Header.Token); bnet.protocol.ContentHandle contentHandle = bnet.protocol.ContentHandle.ParseFrom(context.Payload); if (contentHandle == null || !contentHandle.IsInitialized) { base.ApiLog.LogWarning("Received invalid response"); resourcesAPIPendingState.Callback(null, resourcesAPIPendingState.UserContext); return; } BattleNetErrors status = (BattleNetErrors)context.Header.Status; if (status != BattleNetErrors.ERROR_OK) { base.ApiLog.LogWarning("Battle.net Resources API C#: Failed lookup. Error={0}", new object[] { status }); resourcesAPIPendingState.Callback(null, resourcesAPIPendingState.UserContext); return; } ContentHandle contentHandle2 = ContentHandle.FromProtocol(contentHandle); resourcesAPIPendingState.Callback(contentHandle2, resourcesAPIPendingState.UserContext); }
public override bool Equals(object obj) { ContentHandle contentHandle = obj as ContentHandle; if (contentHandle == null) { return(false); } if (!this.Region.Equals(contentHandle.Region)) { return(false); } if (!this.Usage.Equals(contentHandle.Usage)) { return(false); } if (!this.Hash.Equals(contentHandle.Hash)) { return(false); } if (this.HasProtoUrl == contentHandle.HasProtoUrl && (!this.HasProtoUrl || this.ProtoUrl.Equals(contentHandle.ProtoUrl))) { return(true); } return(false); }
public static ContentHandle DeserializeLengthDelimited(Stream stream, ContentHandle instance) { long position = (long)ProtocolParser.ReadUInt32(stream); position += stream.Position; return(ContentHandle.Deserialize(stream, instance, position)); }
public static ContentHandle Deserialize(Stream stream, ContentHandle instance, long limit) { BinaryReader binaryReader = new BinaryReader(stream); while (limit < 0L || stream.Position < limit) { int num = stream.ReadByte(); if (num == -1) { if (limit >= 0L) { throw new EndOfStreamException(); } return(instance); } else if (num != 13) { if (num != 21) { if (num != 26) { if (num != 34) { Key key = ProtocolParser.ReadKey((byte)num, stream); uint field = key.Field; if (field == 0u) { throw new ProtocolBufferException("Invalid field id: 0, something went wrong in the stream"); } ProtocolParser.SkipKey(stream, key); } else { instance.ProtoUrl = ProtocolParser.ReadString(stream); } } else { instance.Hash = ProtocolParser.ReadBytes(stream); } } else { instance.Usage = binaryReader.ReadUInt32(); } } else { instance.Region = binaryReader.ReadUInt32(); } } if (stream.Position == limit) { return(instance); } throw new ProtocolBufferException("Read past max limit"); }
public static ContentHandle FromProtocol(bnet.protocol.ContentHandle contentHandle) { if ((contentHandle == null) || !contentHandle.IsInitialized) { return(null); } return(new ContentHandle { Region = new FourCC(contentHandle.Region).ToString(), Usage = new FourCC(contentHandle.Usage).ToString(), Sha256Digest = ByteArrayToString(contentHandle.Hash) }); }
public static bgs.ContentHandle FromProtocol(bnet.protocol.ContentHandle contentHandle) { if (contentHandle == null || !contentHandle.IsInitialized) { return(null); } bgs.ContentHandle contentHandle1 = new bgs.ContentHandle() { Region = (new FourCC(contentHandle.Region)).ToString(), Usage = (new FourCC(contentHandle.Usage)).ToString(), Sha256Digest = bgs.ContentHandle.ByteArrayToString(contentHandle.Hash) }; return(contentHandle1); }
public static void Serialize(Stream stream, ContentHandle instance) { BinaryWriter binaryWriter = new BinaryWriter(stream); stream.WriteByte(13); binaryWriter.Write(instance.Region); stream.WriteByte(21); binaryWriter.Write(instance.Usage); if (instance.Hash == null) { throw new ArgumentNullException("Hash", "Required by proto specification."); } stream.WriteByte(26); ProtocolParser.WriteBytes(stream, instance.Hash); if (instance.HasProtoUrl) { stream.WriteByte(34); ProtocolParser.WriteBytes(stream, Encoding.get_UTF8().GetBytes(instance.ProtoUrl)); } }
public void AddContentHandle(bnet.protocol.ContentHandle val) { this._ContentHandle.Add(val); }
public static ContentHandle Deserialize(Stream stream, ContentHandle instance) { return(ContentHandle.Deserialize(stream, instance, -1L)); }
public void Deserialize(Stream stream) { ContentHandle.Deserialize(stream, this); }
public override bool Equals(object obj) { ContentHandle contentHandle = obj as ContentHandle; return(contentHandle != null && this.Region.Equals(contentHandle.Region) && this.Usage.Equals(contentHandle.Usage) && this.Hash.Equals(contentHandle.Hash) && this.HasProtoUrl == contentHandle.HasProtoUrl && (!this.HasProtoUrl || this.ProtoUrl.Equals(contentHandle.ProtoUrl))); }