Source code for geowatchutil.codec.geowatch_codec_list

from geowatchutil.codec.base import GeoWatchCodec


[docs]class GeoWatchCodecList(GeoWatchCodec): """ GeoWatchCodecList is used for encoding/decoding and packaging/unpacking lists. """ separator = "\t"
[docs] def encode(self, message, **kwargs): """ Encode for sending via channel """ return self.encode_channel(self.separator.join(message))
[docs] def decode(self, message): """ Decode messages received via channel """ return self.decode_channel(message).split(self.separator)
[docs] def pack(self, messages, which="all", which_index=0): """ pack messages for store """ if which == "first": return self.separator.join(messages[0]) elif which == "last": return self.separator.join(messages[-1]) elif which == "index": return self.separator.join(messages[which_index]) else: return "\n".join([self.separator.join(m) for m in messages])
[docs] def unpack(self, data): """ unpack data from store into messages """ return [m.split(self.separator) for m in data.split("\n")]
def __init__(self, channel=None, separator="\t"): super(GeoWatchCodecList, self).__init__(channel=channel, content_type="text/plain") self.separator = separator