fix(message-protocol;tracker;player): use uint for StringDict keys
This commit is contained in:
parent
8fe01ac46e
commit
e0ea7d511f
14 changed files with 54 additions and 54 deletions
|
|
@ -1320,15 +1320,15 @@ func (msg *PerformanceTrack) TypeID() int {
|
|||
|
||||
type StringDict struct {
|
||||
message
|
||||
Key string
|
||||
Key uint64
|
||||
Value string
|
||||
}
|
||||
|
||||
func (msg *StringDict) Encode() []byte {
|
||||
buf := make([]byte, 21+len(msg.Key)+len(msg.Value))
|
||||
buf := make([]byte, 21+len(msg.Value))
|
||||
buf[0] = 50
|
||||
p := 1
|
||||
p = WriteString(msg.Key, buf, p)
|
||||
p = WriteUint(msg.Key, buf, p)
|
||||
p = WriteString(msg.Value, buf, p)
|
||||
return buf[:p]
|
||||
}
|
||||
|
|
@ -1343,18 +1343,18 @@ func (msg *StringDict) TypeID() int {
|
|||
|
||||
type SetNodeAttributeDict struct {
|
||||
message
|
||||
ID uint64
|
||||
Name string
|
||||
Value string
|
||||
ID uint64
|
||||
NameKey uint64
|
||||
ValueKey uint64
|
||||
}
|
||||
|
||||
func (msg *SetNodeAttributeDict) Encode() []byte {
|
||||
buf := make([]byte, 31+len(msg.Name)+len(msg.Value))
|
||||
buf := make([]byte, 31)
|
||||
buf[0] = 51
|
||||
p := 1
|
||||
p = WriteUint(msg.ID, buf, p)
|
||||
p = WriteString(msg.Name, buf, p)
|
||||
p = WriteString(msg.Value, buf, p)
|
||||
p = WriteUint(msg.NameKey, buf, p)
|
||||
p = WriteUint(msg.ValueKey, buf, p)
|
||||
return buf[:p]
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -795,7 +795,7 @@ func DecodePerformanceTrack(reader BytesReader) (Message, error) {
|
|||
func DecodeStringDict(reader BytesReader) (Message, error) {
|
||||
var err error = nil
|
||||
msg := &StringDict{}
|
||||
if msg.Key, err = reader.ReadString(); err != nil {
|
||||
if msg.Key, err = reader.ReadUint(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if msg.Value, err = reader.ReadString(); err != nil {
|
||||
|
|
@ -810,10 +810,10 @@ func DecodeSetNodeAttributeDict(reader BytesReader) (Message, error) {
|
|||
if msg.ID, err = reader.ReadUint(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if msg.Name, err = reader.ReadString(); err != nil {
|
||||
if msg.NameKey, err = reader.ReadUint(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if msg.Value, err = reader.ReadString(); err != nil {
|
||||
if msg.ValueKey, err = reader.ReadUint(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return msg, err
|
||||
|
|
|
|||
|
|
@ -464,10 +464,10 @@ class StringDict(Message):
|
|||
class SetNodeAttributeDict(Message):
|
||||
__id__ = 51
|
||||
|
||||
def __init__(self, id, name, value):
|
||||
def __init__(self, id, name_key, value_key):
|
||||
self.id = id
|
||||
self.name = name
|
||||
self.value = value
|
||||
self.name_key = name_key
|
||||
self.value_key = value_key
|
||||
|
||||
|
||||
class DOMDrop(Message):
|
||||
|
|
|
|||
|
|
@ -433,15 +433,15 @@ class MessageCodec(Codec):
|
|||
|
||||
if message_id == 50:
|
||||
return StringDict(
|
||||
key=self.read_string(reader),
|
||||
key=self.read_uint(reader),
|
||||
value=self.read_string(reader)
|
||||
)
|
||||
|
||||
if message_id == 51:
|
||||
return SetNodeAttributeDict(
|
||||
id=self.read_uint(reader),
|
||||
name=self.read_string(reader),
|
||||
value=self.read_string(reader)
|
||||
name_key=self.read_uint(reader),
|
||||
value_key=self.read_uint(reader)
|
||||
)
|
||||
|
||||
if message_id == 52:
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ export default class DOMManager extends ListWalker<Message> {
|
|||
private activeIframeRoots: Map<number, number> = new Map()
|
||||
private styleSheets: Map<number, CSSStyleSheet> = new Map()
|
||||
private ppStyleSheets: Map<number, PostponedStyleSheet> = new Map()
|
||||
private stringDict: Record<string,string> = {}
|
||||
private stringDict: Record<number,string> = {}
|
||||
|
||||
|
||||
private upperBodyId: number = -1;
|
||||
|
|
@ -233,13 +233,13 @@ export default class DOMManager extends ListWalker<Message> {
|
|||
this.stringDict[msg.key] = msg.value
|
||||
return
|
||||
case MType.SetNodeAttributeDict:
|
||||
this.stringDict[msg.name] === undefined && logger.error("No dictionary key for msg 'name': ", msg)
|
||||
this.stringDict[msg.value] === undefined && logger.error("No dictionary key for msg 'value': ", msg)
|
||||
if (!this.stringDict[msg.name] || !this.stringDict[msg.value]) { return }
|
||||
this.stringDict[msg.nameKey] === undefined && logger.error("No dictionary key for msg 'name': ", msg)
|
||||
this.stringDict[msg.valueKey] === undefined && logger.error("No dictionary key for msg 'value': ", msg)
|
||||
if (this.stringDict[msg.nameKey] === undefined || this.stringDict[msg.valueKey] === undefined ) { return }
|
||||
this.setNodeAttribute({
|
||||
id: msg.id,
|
||||
name: this.stringDict[msg.name],
|
||||
value: this.stringDict[msg.value],
|
||||
name: this.stringDict[msg.nameKey],
|
||||
value: this.stringDict[msg.valueKey],
|
||||
})
|
||||
return
|
||||
case MType.RemoveNodeAttribute:
|
||||
|
|
|
|||
|
|
@ -372,7 +372,7 @@ export default class RawMessageReader extends PrimitiveReader {
|
|||
}
|
||||
|
||||
case 50: {
|
||||
const key = this.readString(); if (key === null) { return resetPointer() }
|
||||
const key = this.readUint(); if (key === null) { return resetPointer() }
|
||||
const value = this.readString(); if (value === null) { return resetPointer() }
|
||||
return {
|
||||
tp: MType.StringDict,
|
||||
|
|
@ -383,13 +383,13 @@ export default class RawMessageReader extends PrimitiveReader {
|
|||
|
||||
case 51: {
|
||||
const id = this.readUint(); if (id === null) { return resetPointer() }
|
||||
const name = this.readString(); if (name === null) { return resetPointer() }
|
||||
const value = this.readString(); if (value === null) { return resetPointer() }
|
||||
const nameKey = this.readUint(); if (nameKey === null) { return resetPointer() }
|
||||
const valueKey = this.readUint(); if (valueKey === null) { return resetPointer() }
|
||||
return {
|
||||
tp: MType.SetNodeAttributeDict,
|
||||
id,
|
||||
name,
|
||||
value,
|
||||
nameKey,
|
||||
valueKey,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -271,15 +271,15 @@ export interface RawPerformanceTrack {
|
|||
|
||||
export interface RawStringDict {
|
||||
tp: MType.StringDict,
|
||||
key: string,
|
||||
key: number,
|
||||
value: string,
|
||||
}
|
||||
|
||||
export interface RawSetNodeAttributeDict {
|
||||
tp: MType.SetNodeAttributeDict,
|
||||
id: number,
|
||||
name: string,
|
||||
value: string,
|
||||
nameKey: number,
|
||||
valueKey: number,
|
||||
}
|
||||
|
||||
export interface RawResourceTiming {
|
||||
|
|
|
|||
|
|
@ -260,15 +260,15 @@ type TrPerformanceTrack = [
|
|||
|
||||
type TrStringDict = [
|
||||
type: 50,
|
||||
key: string,
|
||||
key: number,
|
||||
value: string,
|
||||
]
|
||||
|
||||
type TrSetNodeAttributeDict = [
|
||||
type: 51,
|
||||
id: number,
|
||||
name: string,
|
||||
value: string,
|
||||
nameKey: number,
|
||||
valueKey: number,
|
||||
]
|
||||
|
||||
type TrResourceTiming = [
|
||||
|
|
@ -705,8 +705,8 @@ export default function translate(tMsg: TrackerMessage): RawMessage | null {
|
|||
return {
|
||||
tp: MType.SetNodeAttributeDict,
|
||||
id: tMsg[1],
|
||||
name: tMsg[2],
|
||||
value: tMsg[3],
|
||||
nameKey: tMsg[2],
|
||||
valueKey: tMsg[3],
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -279,14 +279,14 @@ message 49, 'PerformanceTrack' do #, :replayer => :devtools --> requires player
|
|||
end
|
||||
# since 4.1.9
|
||||
message 50, "StringDict" do
|
||||
string "Key"
|
||||
uint "Key"
|
||||
string "Value"
|
||||
end
|
||||
# since 4.1.9
|
||||
message 51, "SetNodeAttributeDict" do
|
||||
uint 'ID'
|
||||
string 'Name'
|
||||
string 'Value'
|
||||
uint 'NameKey'
|
||||
uint 'ValueKey'
|
||||
end
|
||||
|
||||
## 50,51
|
||||
|
|
|
|||
|
|
@ -321,15 +321,15 @@ export type PerformanceTrack = [
|
|||
|
||||
export type StringDict = [
|
||||
/*type:*/ Type.StringDict,
|
||||
/*key:*/ string,
|
||||
/*key:*/ number,
|
||||
/*value:*/ string,
|
||||
]
|
||||
|
||||
export type SetNodeAttributeDict = [
|
||||
/*type:*/ Type.SetNodeAttributeDict,
|
||||
/*id:*/ number,
|
||||
/*name:*/ string,
|
||||
/*value:*/ string,
|
||||
/*nameKey:*/ number,
|
||||
/*valueKey:*/ number,
|
||||
]
|
||||
|
||||
export type ResourceTiming = [
|
||||
|
|
|
|||
|
|
@ -475,7 +475,7 @@ export function PerformanceTrack(
|
|||
}
|
||||
|
||||
export function StringDict(
|
||||
key: string,
|
||||
key: number,
|
||||
value: string,
|
||||
): Messages.StringDict {
|
||||
return [
|
||||
|
|
@ -487,14 +487,14 @@ export function StringDict(
|
|||
|
||||
export function SetNodeAttributeDict(
|
||||
id: number,
|
||||
name: string,
|
||||
value: string,
|
||||
nameKey: number,
|
||||
valueKey: number,
|
||||
): Messages.SetNodeAttributeDict {
|
||||
return [
|
||||
Messages.Type.SetNodeAttributeDict,
|
||||
id,
|
||||
name,
|
||||
value,
|
||||
nameKey,
|
||||
valueKey,
|
||||
]
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ export default class BatchWriter {
|
|||
this.beaconSizeLimit = limit
|
||||
}
|
||||
|
||||
private applyDict(str: string): string {
|
||||
private applyDict(str: string): number {
|
||||
const [key, isNew] = this.strDict.getKey(str)
|
||||
if (isNew) {
|
||||
this.writeMessage([Messages.Type.StringDict, key, str])
|
||||
|
|
|
|||
|
|
@ -159,11 +159,11 @@ export default class MessageEncoder extends PrimitiveEncoder {
|
|||
break
|
||||
|
||||
case Messages.Type.StringDict:
|
||||
return this.string(msg[1]) && this.string(msg[2])
|
||||
return this.uint(msg[1]) && this.string(msg[2])
|
||||
break
|
||||
|
||||
case Messages.Type.SetNodeAttributeDict:
|
||||
return this.uint(msg[1]) && this.string(msg[2]) && this.string(msg[3])
|
||||
return this.uint(msg[1]) && this.uint(msg[2]) && this.uint(msg[3])
|
||||
break
|
||||
|
||||
case Messages.Type.ResourceTiming:
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
export default class StringDictionary {
|
||||
private idx = 0
|
||||
private backDict: Record<string, string> = {}
|
||||
private backDict: Record<string, number> = {}
|
||||
|
||||
getKey(str: string): [string, boolean] {
|
||||
getKey(str: string): [number, boolean] {
|
||||
let isNew = false
|
||||
if (!this.backDict[str]) {
|
||||
isNew = true
|
||||
this.backDict[str] = `${this.idx++}`
|
||||
this.backDict[str] = this.idx++
|
||||
}
|
||||
return [this.backDict[str], isNew]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue