[ 
https://issues.apache.org/jira/browse/THRIFT-2640?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14499988#comment-14499988
 ] 

ASF GitHub Bot commented on THRIFT-2640:
----------------------------------------

Github user jeremy-w commented on a diff in the pull request:

    https://github.com/apache/thrift/pull/442#discussion_r28602218
  
    --- Diff: lib/cocoa/src/protocol/TCompactProtocol.m ---
    @@ -0,0 +1,706 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements. See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership. The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License. You may obtain a copy of the License at
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied. See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +
    +#import "TCompactProtocol.h"
    +#import "TObjective-C.h"
    +#import "TProtocolException.h"
    +
    +static const uint8_t COMPACT_PROTOCOL_ID = 0x82;
    +static const uint8_t COMPACT_VERSION = 1;
    +static const uint8_t COMPACT_VERSION_MASK = 0x1F; // 0001 1111
    +static const uint8_t COMPACT_TYPE_MASK = 0xE0; // 1110 0000
    +static const uint8_t COMPACT_TYPE_BITS = 0x07; // 0000 0111
    +static const int COMPACT_TYPE_SHIFT_AMOUNT = 5;
    +
    +static uint8_t ttypeToCompactType[16] = {0};
    +
    +enum
    +{
    +    TCType_STOP = 0x00,
    +    TCType_BOOLEAN_TRUE = 0x01,
    +    TCType_BOOLEAN_FALSE = 0x02,
    +    TCType_BYTE = 0x03,
    +    TCType_I16 = 0x04,
    +    TCType_I32 = 0x05,
    +    TCType_I64 = 0x06,
    +    TCType_DOUBLE = 0x07,
    +    TCType_BINARY = 0x08,
    +    TCType_LIST = 0x09,
    +    TCType_SET = 0x0A,
    +    TCType_MAP = 0x0B,
    +    TCType_STRUCT = 0x0C,
    +};
    +
    +@implementation TCompactProtocolFactory
    +
    ++(TCompactProtocolFactory*)sharedFactory
    +{
    +    static TCompactProtocolFactory* gSharedFactory = nil;
    +    if (gSharedFactory == nil)
    +    {
    +        gSharedFactory = [[TCompactProtocolFactory alloc] init];
    +    }
    +    
    +    return gSharedFactory;
    +}
    +
    +-(TCompactProtocol*)newProtocolOnTransport:(id <TTransport>)transport
    +{
    +    return [[TCompactProtocol alloc] initWithTransport:transport];
    +}
    +
    +@end
    +
    +@implementation TCompactProtocol
    +{
    +    NSMutableArray* lastField;
    +    short lastFieldId;
    +    id <TTransport> mTransport;
    +    
    +    NSString* boolFieldName;
    +    NSNumber* boolFieldType;
    +    NSNumber* boolFieldId;
    +    NSNumber* booleanValue;
    +}
    +
    +-(id)init
    +{
    +    self = [super init];
    +    
    +    if (self != nil)
    +    {
    +        lastField = [[NSMutableArray alloc] init];
    +    }
    +    
    +    return self;
    +}
    +
    +-(id)initWithTransport:(id <TTransport>)transport
    +{
    +    self = [self init];
    +    
    +    if (self != nil)
    +    {
    +        mTransport = [transport retain_stub];
    +        
    +        ttypeToCompactType[TType_STOP] = TCType_STOP;
    --- End diff --
    
    This overwrites the static storage every time a new protocol instance is 
created.
    
    Since it's dealing in enum values anyway, can't you just declare it as:
    
    ```
    static uint8_t ttypeToCompactType[16] = {
        [TType_STOP] = TCType_STOP,
        [TType_BOOL] = TCType_BOOLEAN_FALSE,
        …
    };
    ```
    
    ?


> Compact Protocol in Cocoa
> -------------------------
>
>                 Key: THRIFT-2640
>                 URL: https://issues.apache.org/jira/browse/THRIFT-2640
>             Project: Thrift
>          Issue Type: Sub-task
>          Components: Cocoa - Library
>    Affects Versions: 0.9.1
>            Reporter: Mark Hornsby
>            Assignee: Jens Geyer
>            Priority: Minor
>




--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to