Salut,
hier j'ai mis en place ma routine pour compresser et je fesais les tests sur 4 byte et la pas de problème puis je me suis dis passons a 256 ... et la VLAN ...
VLAN en entré j'ai mes 256 byte tous a 1 ... et en sortie j'ai 23 byte ... tous a 1 mais bon 23 ...
Pour information sans la compression (Level = 0) tout ce passe bien ...
Voici mon code pour les tests :
Dim L_oZLib As New cZLib
Dim L_AbByte() As Byte
Dim i As Long
Dim tmpStr As String
ReDim L_AbByte(255)
For i = 0 To 255
L_AbByte(i) = 1
Next i
tmpStr = ""
For i = 0 To UBound(L_AbByte)
If (i > 0) Then tmpStr = tmpStr & ":"
tmpStr = tmpStr & CStr(L_AbByte(i))
Next i
Debug.Print "Avant Compression :" & UBound(L_AbByte) & ":" & tmpStr
Debug.Print "Resultat de la Compression :" & L_oZLib.CompressByteArray(L_AbByte, 9)
tmpStr = ""
For i = 0 To UBound(L_AbByte)
If (i > 0) Then tmpStr = tmpStr & ":"
tmpStr = tmpStr & CStr(L_AbByte(i))
Next i
Debug.Print "Après Compression:" & UBound(L_AbByte) & ":" & tmpStr
Debug.Print "Resultat de la Décompression :" & L_oZLib.DecompressByteArray(L_AbByte)
tmpStr = ""
For i = 0 To UBound(L_AbByte)
If (i > 0) Then tmpStr = tmpStr & ":"
tmpStr = tmpStr & CStr(L_AbByte(i))
Next i
Debug.Print "Après Décompression :" & UBound(L_AbByte) & ":" & tmpStr
et voila ma classe cZlib
Private Declare Function CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
ByRef P_AbDest As Byte, _
ByRef P_AbSource As Byte, _
ByVal P_lLenght As Long _
) As Long
Private Declare Function Compress Lib "zlib.dll" Alias "compress" ( _
ByRef P_AbDest As Byte, _
ByRef P_lDestLen As Long, _
ByRef P_AbSrc As Byte, _
ByVal P_lSrcLen As Long _
) As Long
Private Declare Function CompressWithLevel Lib "zlib.dll" Alias "compress2" ( _
ByRef P_AbDest As Byte, _
ByRef P_lDestLen As Long, _
ByRef P_AbSrc As Byte, _
ByVal P_lSrcLen As Long, _
ByVal P_lLevel As Long _
) As Long
Private Declare Function UnCompress Lib "zlib.dll" Alias "uncompress" ( _
ByRef P_AbDest As Byte, _
ByRef P_lDestLen As Long, _
ByRef P_AbSrc As Byte, _
ByVal P_lSrcLen As Long _
) As Long
Public Function CompressByteArray(ByRef P_AbSrc() As Byte, ByVal P_lLevel As Long) As Long
Dim L_lSrcLenght As Long
Dim L_lDestLenght As Long
Dim L_AbDest() As Byte
Dim L_lResult As Long
Dim L_lMax As Long
On Error GoTo CompressByteArray_Error
' Allocate Byte Array
L_lSrcLenght = UBound(P_AbSrc) + 1
L_lMax = ((((256 ^ 4) / 2) - 16) / 1.01)
If (L_lSrcLenght > L_lMax) Then CompressByteArray = -1: Exit Function
L_lDestLenght = (L_lSrcLenght * 1.01) + 12
ReDim L_AbDest(L_lDestLenght)
' Compress Byte Array
L_lResult = CompressWithLevel(L_AbDest(0), L_lDestLenght, P_AbSrc(0), L_lSrcLenght, P_lLevel)
' Truncate to compressed size
ReDim P_AbSrc(L_lDestLenght - 1)
CopyMemory P_AbSrc(0), L_AbDest(0), L_lDestLenght
' Return error code (if any)
CompressByteArray = L_lResult
Exit Function
CompressByteArray_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure CompressByteArray of Module de classe cZLib"
End Function
Public Function DecompressByteArray(ByRef P_AbSrc() As Byte) As Long
Dim L_lSrcLenght As Long
Dim L_lDestLenght As Long
Dim L_AbDest() As Byte
Dim L_lResult As Long
Dim L_lMax As Long
On Error GoTo DecompressByteArray_Error
' Allocate Byte Array
L_lSrcLenght = UBound(P_AbSrc) + 1
L_lMax = ((((256 ^ 4) / 2) - 16) / 1.01)
If (L_lSrcLenght > L_lMax) Then DecompressByteArray = -1: Exit Function
L_lDestLenght = (L_lSrcLenght * 1.01) + 12
ReDim L_AbDest(L_lDestLenght)
' Decompress data
L_lResult = UnCompress(L_AbDest(0), L_lDestLenght, P_AbSrc(0), L_lSrcLenght)
' Truncate buffer to compressed size
ReDim P_AbSrc(L_lDestLenght - 1)
CopyMemory P_AbSrc(0), L_AbDest(0), L_lDestLenght
' Return error code (if any)
DecompressByteArray = L_lResult
Exit Function
DecompressByteArray_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure DecompressByteArray of Module de classe cZLib"
End FunctionQuelqu'un aurais t'il une solution ... je suis encore en train de cherché sur le net ...