2  * Copyright 2017 Google
 
   4  * Licensed under the Apache License, Version 2.0 (the "License");
 
   5  * you may not use this file except in compliance with the License.
 
   6  * You may obtain a copy of the License at
 
   8  *      http://www.apache.org/licenses/LICENSE-2.0
 
  10  * Unless required by applicable law or agreed to in writing, software
 
  11  * distributed under the License is distributed on an "AS IS" BASIS,
 
  12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  13  * See the License for the specific language governing permissions and
 
  14  * limitations under the License.
 
  17 #import "FIRMessagingPacketQueue.h"
 
  19 #import "FIRMessagingDefines.h"
 
  21 @interface FIRMessagingPacket ()
 
  23 @property(nonatomic, readwrite, strong) NSData *data;
 
  24 @property(nonatomic, readwrite, assign) int8_t tag;
 
  25 @property(nonatomic, readwrite, assign) NSString *rmqId;
 
  29 @implementation FIRMessagingPacket
 
  31 + (FIRMessagingPacket *)packetWithTag:(int8_t)tag rmqId:(NSString *)rmqId data:(NSData *)data {
 
  32   return [[self alloc] initWithTag:tag rmqId:rmqId data:data];
 
  35 - (instancetype)init {
 
  36   FIRMessagingInvalidateInitializer();
 
  39 - (instancetype)initWithTag:(int8_t)tag rmqId:(NSString *)rmqId data:(NSData *)data {
 
  49 - (NSString *)description {
 
  50   if ([self.rmqId length]) {
 
  51     return [NSString stringWithFormat:@"<Packet: Tag - %d, Length - %lu>, RmqId - %@",
 
  52             self.tag, _FIRMessaging_UL(self.data.length), self.rmqId];
 
  54     return [NSString stringWithFormat:@"<Packet: Tag - %d, Length - %lu>",
 
  55             self.tag, _FIRMessaging_UL(self.data.length)];
 
  61 @interface FIRMessagingPacketQueue ()
 
  63 @property(nonatomic, readwrite, strong) NSMutableArray *packetsContainer;
 
  68 @implementation FIRMessagingPacketQueue;
 
  73     _packetsContainer = [[NSMutableArray alloc] init];
 
  79   return self.packetsContainer.count == 0;
 
  83   return self.packetsContainer.count;
 
  86 - (void)push:(FIRMessagingPacket *)packet {
 
  87   [self.packetsContainer addObject:packet];
 
  90 - (void)pushHead:(FIRMessagingPacket *)packet {
 
  91   [self.packetsContainer insertObject:packet atIndex:0];
 
  94 - (FIRMessagingPacket *)pop {
 
  96     FIRMessagingPacket *packet = self.packetsContainer[0];
 
  97     [self.packetsContainer removeObjectAtIndex:0];