File: PortDecoder.t

package info (click to toggle)
tom 1.1.1-2
  • links: PTS
  • area: main
  • in suites: potato
  • size: 6,340 kB
  • ctags: 2,244
  • sloc: objc: 27,863; ansic: 9,804; sh: 7,411; yacc: 3,377; lex: 966; asm: 208; makefile: 62; cpp: 10
file content (80 lines) | stat: -rw-r--r-- 1,704 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<copyright> Receiving objects over the wire.
    Written by <a href="mailto:tiggr@ics.ele.tue.nl">Pieter J. Schoenmakers</a>

    Copyright &copy; 1997 Pieter J. Schoenmakers.

    This file is part of TOM.  TOM is distributed under the terms of the
    TOM License, a copy of which can be found in the TOM distribution; see
    the file LICENSE.

    <id>$Id: PortDecoder.t,v 1.6 1998/01/22 16:39:39 tiggr Exp $</id>
    </copyright>

implementation class
PortDecoder: BinaryDecoder, PortCoder

end;

implementation instance
PortDecoder

id
  initWithConnection ConnectedConnection c
{
  [super (BinaryDecoder) init];
  = [super (PortCoder) initWithConnection c];
}

<doc> Handle proxy tags before super.  </doc>
Any
  decode byte b
{
  while (b == '~')
    {
      int i = [self readInt];
      [connection localProxyRelease i];
      b = [self readByte];
    }

  if (b == '!')
    {
      = [connection localObject [self readInt]];
      [self nextPrimary ')'];
    }
  else if (b == '$')
    {
      = [connection remoteObject [self readInt]];
      [self nextPrimary ')'];
    }
  else
    = [super decode b];
}

protected byte
  readByte
{
  = [port read];
}

protected void
  readBytes int num
	 to pointer address
{
  // Slow.
  // Sun Dec 29 20:41:23 1996, tiggr@tricky.es.ele.tue.nl
  MutableByteArray buf = [MutableByteArray withCapacity num];
  int read = [port readRange (0, num) into buf];

  if (read != num)
    [[SelectorCondition for self class program-condition
      message [[MutableByteString new]
	       print ("read ", read, " instead of ", num)]
      selector cmd] raise];

  pointer from;
  (from, ) = [buf pointerToElements (0, -1)];

  memcpy (address, from, num);
}

end;