This repository has been archived by the owner on Jul 3, 2022. It is now read-only.
forked from Arman92/go-tdlib
/
textEntity.go
62 lines (52 loc) · 1.64 KB
/
textEntity.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
package tdlib
import (
"encoding/json"
)
// TextEntity Represents a part of the text that needs to be formatted in some unusual way
type TextEntity struct {
tdCommon
Offset int32 `json:"offset"` // Offset of the entity, in UTF-16 code units
Length int32 `json:"length"` // Length of the entity, in UTF-16 code units
Type TextEntityType `json:"type"` // Type of the entity
}
// MessageType return the string telegram-type of TextEntity
func (textEntity *TextEntity) MessageType() string {
return "textEntity"
}
// NewTextEntity creates a new TextEntity
//
// @param offset Offset of the entity, in UTF-16 code units
// @param length Length of the entity, in UTF-16 code units
// @param typeParam Type of the entity
func NewTextEntity(offset int32, length int32, typeParam TextEntityType) *TextEntity {
textEntityTemp := TextEntity{
tdCommon: tdCommon{Type: "textEntity"},
Offset: offset,
Length: length,
Type: typeParam,
}
return &textEntityTemp
}
// UnmarshalJSON unmarshal to json
func (textEntity *TextEntity) UnmarshalJSON(b []byte) error {
var objMap map[string]*json.RawMessage
err := json.Unmarshal(b, &objMap)
if err != nil {
return err
}
tempObj := struct {
tdCommon
Offset int32 `json:"offset"` // Offset of the entity, in UTF-16 code units
Length int32 `json:"length"` // Length of the entity, in UTF-16 code units
}{}
err = json.Unmarshal(b, &tempObj)
if err != nil {
return err
}
textEntity.tdCommon = tempObj.tdCommon
textEntity.Offset = tempObj.Offset
textEntity.Length = tempObj.Length
fieldType, _ := unmarshalTextEntityType(objMap["type"])
textEntity.Type = fieldType
return nil
}