Atlas  0.7.0
Networking protocol for the Worldforge system.
binary2.py
1 #binary2 codec: nothing really here yet
2 
3 #Copyright 2001 by Aloril
4 
5 #This library is free software; you can redistribute it and/or
6 #modify it under the terms of the GNU Lesser General Public
7 #License as published by the Free Software Foundation; either
8 #version 2.1 of the License, or (at your option) any later version.
9 
10 #This library is distributed in the hope that it will be useful,
11 #but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 #Lesser General Public License for more details.
14 
15 #You should have received a copy of the GNU Lesser General Public
16 #License along with this library; if not, write to the Free Software
17 #Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 
19 
20 from .binary1 import *
21 
22 from . import xml2
23 #attribute_type_dict = {"id": user_type}
24 attribute_type_dict = {}
25 next_type = user_type
26 for name in list(xml2.attribute_type_dict.keys()):
27  attribute_type_dict[name] = next_type
28  next_type = next_type + 1
29 
30 discard_name=""
31 
32 def gen_binary2(obj):
33  gen = GenerateBinary2()
34  return gen.encode(obj)
35 
37  def encode_attribute(self, name, value):
38  #CHEAT!: assuming that type code is 1 byte (which though always is true for binary1...)
39  type = attribute_type_dict.get(name, 0)
40  if type:
41  return encode_pos_int(type) + self.encode(value)[1:]
42  return GenerateBinary1.encode_attribute(self, name, value)
43 
44  def encode_map(self, obj):
45  str_list = [encode_pos_int(map_type) + encode_pos_int(len(obj))]
46  for name, value in list(obj.items()):
47  if name!=discard_name:
48  str_list.append(self.encode_attribute(name, value))
49  return string.join(str_list, "")
50 
51 
71 
72 
73 
75  pass
76 
atlas.codecs.binary1.GenerateBinary1
Definition: binary1.py:57
atlas.codecs.binary2.Binary2Parser
def encode_float(self, value): mant, exp = frexp(value) mant = long(mant *2L**20) exp = exp - 20 if m...
Definition: binary2.py:74
atlas.codecs.binary2.GenerateBinary2
Definition: binary2.py:36
atlas.codecs.binary1.Binary1Parser
Definition: binary1.py:145
atlas.codecs.binary1.GenerateBinary1.encode_attribute
def encode_attribute(self, name, value)
Definition: binary1.py:113
atlas.codecs.binary1.GenerateBinary1.encode
def encode(self, value)
Definition: binary1.py:65