summaryrefslogtreecommitdiffstats
path: root/src/Port.vala
blob: b67c808c21831cadea3fcc654181d1eba1e958c5 (plain)
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
namespace Eva {
  public class Port : Object, Term {
    public string node {get; construct;}
    public uint id {get; construct;}
    public uint creation {get; construct;}
    
    public Port(Erl.Port port) {
      this.create(array_to_string(port.node, Erl.MAXATOMLEN), port.id, port.creation);
    }
    
    private Port.create(string node0, uint id0, uint creation0) {
      Object(node: node0, id: id0, creation: creation0);
    }
    
    public string to_string() {
      return "#Port";
    }
    
    protected bool do_match(Term o, Gee.Map<string, Term> vars, Gee.Map<string, string> aliases) {
      if(o is Var) {
        return o.do_match(this, vars, aliases);
      }
      
      if(!(o is Port))
        return false;
      
      Port p = o as Port;
      
      return (node == p.node && id == p.id && creation == p.creation);
    }
    
    public void encode(Erl.Buffer buffer) {
      Erl.Port port = Erl.Port();
      char[]? nodedata = string_to_array(node);
      assert(nodedata != null);
      
      Memory.copy(port.node, nodedata, int.min(Erl.MAXATOMLEN, nodedata.length));
      port.node[int.min(Erl.MAXATOMLEN, nodedata.length)] = 0;
      
      port.id = id;
      port.creation = creation;
      
      buffer.encode_port(port);
    }
  }
}