-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathmsg_translator_rules_lde.go
82 lines (74 loc) · 1.63 KB
/
msg_translator_rules_lde.go
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
81
82
/*
This file was autogenerated via
--------------------------------------------------------
ldetool generate --package main msg_translator_rules.lde
--------------------------------------------------------
do not touch it with bare hands!
*/
package main
import (
"fmt"
"strconv"
"unsafe"
)
// Orig ...
type Orig struct {
rest []byte
Line int32
Column int32
Message []byte
}
// Extract ...
func (p *Orig) Extract(line []byte) (bool, error) {
p.rest = line
var err error
var pos int
var tmp []byte
var tmpInt int64
// Checks if the rest starts with `"Line "` and pass it
if len(p.rest) >= 5 && *(*uint64)(unsafe.Pointer(&p.rest[0]))&1099511627775 == 139140688236 {
p.rest = p.rest[5:]
} else {
return false, nil
}
// Take until ':' as Line(int32)
pos = -1
for i, char := range p.rest {
if char == ':' {
pos = i
break
}
}
if pos >= 0 {
tmp = p.rest[:pos]
p.rest = p.rest[pos+1:]
} else {
return false, nil
}
if tmpInt, err = strconv.ParseInt(*(*string)(unsafe.Pointer(&tmp)), 10, 32); err != nil {
return false, fmt.Errorf("Cannot parse `%s`: %s", string(tmp), err)
}
p.Line = int32(tmpInt)
// Take until ' ' as Column(int32)
pos = -1
for i, char := range p.rest {
if char == ' ' {
pos = i
break
}
}
if pos >= 0 {
tmp = p.rest[:pos]
p.rest = p.rest[pos+1:]
} else {
return false, nil
}
if tmpInt, err = strconv.ParseInt(*(*string)(unsafe.Pointer(&tmp)), 10, 32); err != nil {
return false, fmt.Errorf("Cannot parse `%s`: %s", string(tmp), err)
}
p.Column = int32(tmpInt)
// Take the rest as Message(string)
p.Message = p.rest
p.rest = p.rest[len(p.rest):]
return true, nil
}