protolib.py (10107:524afa92d940) | protolib.py (10269:82773ace39fa) |
---|---|
1#!/usr/bin/env python 2 3# Copyright (c) 2013 ARM Limited 4# All rights reserved 5# 6# The license below extends only to copyright in the software and shall 7# not be construed as granting a license to any other intellectual 8# property including but not limited to intellectual property relating --- 57 unchanged lines hidden (view full) --- 66# 67# Authors: Andreas Hansson 68# Radhika Jagtap 69 70# This file is a library of commonly used functions used when interfacing 71# with protobuf python messages. For eg, the decode scripts for different 72# types of proto objects can use the same function to decode a single message 73 | 1#!/usr/bin/env python 2 3# Copyright (c) 2013 ARM Limited 4# All rights reserved 5# 6# The license below extends only to copyright in the software and shall 7# not be construed as granting a license to any other intellectual 8# property including but not limited to intellectual property relating --- 57 unchanged lines hidden (view full) --- 66# 67# Authors: Andreas Hansson 68# Radhika Jagtap 69 70# This file is a library of commonly used functions used when interfacing 71# with protobuf python messages. For eg, the decode scripts for different 72# types of proto objects can use the same function to decode a single message 73 |
74import gzip |
|
74import struct 75 | 75import struct 76 |
77def openFileRd(in_file): 78 """ 79 This opens the file passed as argument for reading using an appropriate 80 function depending on if it is gzipped or not. It returns the file 81 handle. 82 """ 83 try: 84 # First see if this file is gzipped 85 try: 86 # Opening the file works even if it is not a gzip file 87 proto_in = gzip.open(in_file, 'rb') 88 89 # Force a check of the magic number by seeking in the 90 # file. If we do not do it here the error will occur when 91 # reading the first message. 92 proto_in.seek(1) 93 proto_in.seek(0) 94 except IOError: 95 proto_in = open(in_file, 'rb') 96 except IOError: 97 print "Failed to open ", in_file, " for reading" 98 exit(-1) 99 return proto_in 100 |
|
76def DecodeVarint(in_file): 77 """ 78 The decoding of the Varint32 is copied from 79 google.protobuf.internal.decoder and is only repeated here to 80 avoid depending on the internal functions in the library. If the 81 end of file is reached, return (0, 0). 82 """ 83 result = 0 --- 58 unchanged lines hidden --- | 101def DecodeVarint(in_file): 102 """ 103 The decoding of the Varint32 is copied from 104 google.protobuf.internal.decoder and is only repeated here to 105 avoid depending on the internal functions in the library. If the 106 end of file is reached, return (0, 0). 107 """ 108 result = 0 --- 58 unchanged lines hidden --- |