small tweak to proto stuff
This commit is contained in:
1 parent
1ce9410565
commit
e20fb7df90
4 files changed
+35
-18
No files matched your search
@@ -43,7 +43,7 @@ namespace Protobuf
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
function encodeFilters(message as dynamic) as string
|
function encodeFilters(message as dynamic, asByteArray = false as boolean) as dynamic
|
||||||
buffer = CreateObject("roByteArray")
|
buffer = CreateObject("roByteArray")
|
||||||
writer = new Protobuf.BinaryWriter()
|
writer = new Protobuf.BinaryWriter()
|
||||||
writer.SetBuffer(buffer)
|
writer.SetBuffer(buffer)
|
||||||
@@ -104,10 +104,14 @@ namespace Protobuf
|
|||||||
value = message["features_vr180"]
|
value = message["features_vr180"]
|
||||||
encoder.EncodeBool(26, value)
|
encoder.EncodeBool(26, value)
|
||||||
end if
|
end if
|
||||||
return buffer.ToBase64String().EncodeUriComponent()
|
if asByteArray
|
||||||
|
return buffer
|
||||||
|
else
|
||||||
|
return buffer.ToBase64String().EncodeUriComponent()
|
||||||
|
end if
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function encodeSearchFilter(message as dynamic) as string
|
function encodeSearchFilter(message as dynamic, asByteArray = false as boolean) as dynamic
|
||||||
buffer = CreateObject("roByteArray")
|
buffer = CreateObject("roByteArray")
|
||||||
writer = new Protobuf.BinaryWriter()
|
writer = new Protobuf.BinaryWriter()
|
||||||
writer.SetBuffer(buffer)
|
writer.SetBuffer(buffer)
|
||||||
@@ -118,9 +122,13 @@ namespace Protobuf
|
|||||||
end if
|
end if
|
||||||
if message.DoesExist("filters")
|
if message.DoesExist("filters")
|
||||||
value = message["filters"]
|
value = message["filters"]
|
||||||
encoder.EncodeMessage(2, Protobuf.Generated.misc.encodeFilters(value))
|
encoder.EncodeMessage(2, Protobuf.Generated.misc.encodeFilters(value, true))
|
||||||
|
end if
|
||||||
|
if asByteArray
|
||||||
|
return buffer
|
||||||
|
else
|
||||||
|
return buffer.ToBase64String().EncodeUriComponent()
|
||||||
end if
|
end if
|
||||||
return buffer.ToBase64String().EncodeUriComponent()
|
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -48,10 +48,12 @@ namespace Protobuf
|
|||||||
strBuffer = CreateObject("roByteArray")
|
strBuffer = CreateObject("roByteArray")
|
||||||
strBuffer.FromAsciiString(value)
|
strBuffer.FromAsciiString(value)
|
||||||
m.WriteVarInt(strBuffer.Count())
|
m.WriteVarInt(strBuffer.Count())
|
||||||
for i = 0 to strBuffer.Count() - 1
|
m.WriteByteArrayRaw(strBuffer, 0, strBuffer.Count())
|
||||||
m.buffer[m.position + i] = strBuffer[i]
|
end function
|
||||||
end for
|
|
||||||
m.position += strBuffer.Count()
|
function WriteProtoByteArray(value as dynamic) as void
|
||||||
|
m.WriteVarInt(value.Count())
|
||||||
|
m.WriteByteArrayRaw(value, 0, value.Count())
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function WriteBool(value as dynamic) as void
|
function WriteBool(value as dynamic) as void
|
||||||
@@ -61,6 +63,14 @@ namespace Protobuf
|
|||||||
m.WriteByte(0)
|
m.WriteByte(0)
|
||||||
end if
|
end if
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
function WriteByteArrayRaw(buffer as dynamic, index as dynamic, size as dynamic) as void
|
||||||
|
position = m.position
|
||||||
|
for i = 0 to size - 1
|
||||||
|
m.buffer[position + i] = buffer[index + i]
|
||||||
|
end for
|
||||||
|
m.position += size
|
||||||
|
end function
|
||||||
end class
|
end class
|
||||||
|
|
||||||
end namespace
|
end namespace
|
||||||
@@ -39,12 +39,7 @@ namespace Protobuf
|
|||||||
|
|
||||||
function EncodeMessage(tag as integer, value as dynamic) as void
|
function EncodeMessage(tag as integer, value as dynamic) as void
|
||||||
m.writer.WriteByte((tag << 3) or 2)
|
m.writer.WriteByte((tag << 3) or 2)
|
||||||
buffer = CreateObject("roByteArray")
|
m.writer.WriteProtoByteArray(value)
|
||||||
buffer.FromBase64String(value.DecodeUriComponent())
|
|
||||||
m.writer.WriteVarInt(buffer.Count())
|
|
||||||
for i = 0 to buffer.Count() - 1
|
|
||||||
m.writer.WriteByte(buffer[i])
|
|
||||||
end for
|
|
||||||
end function
|
end function
|
||||||
|
|
||||||
end class
|
end class
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ end function`;
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (innerTypes.includes(field.type)) {
|
if (innerTypes.includes(field.type)) {
|
||||||
fieldEncode += `encoder.EncodeMessage(${field.tag}, ${fullNameSpace}.encode${field.type}(value))\n`;
|
fieldEncode += `encoder.EncodeMessage(${field.tag}, ${fullNameSpace}.encode${field.type}(value, true))\n`;
|
||||||
}
|
}
|
||||||
else if (enums.includes(field.type)) {
|
else if (enums.includes(field.type)) {
|
||||||
fieldEncode += `encoder.EncodeInt32(${field.tag}, value)\n`;
|
fieldEncode += `encoder.EncodeInt32(${field.tag}, value)\n`;
|
||||||
@@ -169,13 +169,17 @@ end function`;
|
|||||||
return fieldEncode + 'end if';
|
return fieldEncode + 'end if';
|
||||||
}).join('\n');
|
}).join('\n');
|
||||||
|
|
||||||
return `function encode${message.name}(message as dynamic) as string
|
return `function encode${message.name}(message as dynamic, asByteArray = false as boolean) as dynamic
|
||||||
buffer = CreateObject("roByteArray")
|
buffer = CreateObject("roByteArray")
|
||||||
writer = new Protobuf.BinaryWriter()
|
writer = new Protobuf.BinaryWriter()
|
||||||
writer.SetBuffer(buffer)
|
writer.SetBuffer(buffer)
|
||||||
encoder = new Protobuf.Encoder(writer)
|
encoder = new Protobuf.Encoder(writer)
|
||||||
${encodeFields}
|
${encodeFields}
|
||||||
return buffer.ToBase64String().EncodeUriComponent()
|
if asByteArray
|
||||||
|
return buffer
|
||||||
|
else
|
||||||
|
return buffer.ToBase64String().EncodeUriComponent()
|
||||||
|
end if
|
||||||
end function`;
|
end function`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user