Byte conversion?
Byte conversion?
Byte conversion?
Byte conversion?
Byte conversion?
Byte conversion? Byte conversion? Byte conversion? Byte conversion? Byte conversion? Byte conversion? Byte conversion? Byte conversion?
Byte conversion? Byte conversion?
Byte conversion?
Go Back  Xtreme Visual Basic Talk > > > Byte conversion?


Reply
 
Thread Tools Display Modes
  #1  
Old 11-01-2015, 03:47 AM
Jmann84 Jmann84 is offline
Newcomer
 
Join Date: Nov 2015
Posts: 2
Default Byte conversion?


Ok I'm not really sure if I am even approaching this issue correctly as I am not 100% sure what I am dealing with in my project but I will do my best to explain.

I am working on an RTMP client project. There is one packet that I send to the server containing a unique ID. There are multiple unique ID's and the returned packet has what appears to be the unique ID put into a byte array.

Here is the outgoing packet I am sending:

Send: Return Code: 0x00000000
00000000 83 00 0B 5C 02 00 07 61 63 63 6F 75 6E 74 00 00 ...\...account..
00000010 00 00 00 00 00 00 00 05 02 00 05 34 38 32 37 32 ...........48272

and here is the incoming packet I receive back from the server:

Receive: Return Code: 0x00000000
00000000 C3 02 00 07 61 63 63 6F 75 6E 74 00 00 00 00 00 ....account.....
00000010 00 00 00 00 05 03 00 07 61 63 63 6F 75 6E 74 02 ........account.
00000020 00 09 6B 75 73 68 69 73 66 69 67 00 02 69 64 00 ..kushisfig..id.
00000030 40 E7 92 00 00 00 00 00 00 00 09 @..........

Now "kushisfig" is the account that corresponds to the unique ID "48272" that I have sent in the first packet.

What I need to do is read the "id" at the end of the packet to know what ID that account belongs to, but I am not really that familiar with byte arrays in VB6.

Any help would be greatly appreciated as I've been wracking my brain over here for hours.
Reply With Quote
  #2  
Old 11-01-2015, 05:06 AM
dilettante's Avatar
dilettanteByte conversion? dilettante is offline
Underclocked lifestyle

Forum Leader
* Guru *
 
Join Date: Feb 2005
Location: Michigan, USA
Posts: 4,517
Default

You can use the MidB$() function on the array to extract a substring, then convert that to Unicode. To do this the offset will be a 1-based value, so keep that in mind.

You can also use InStrB() if necessary to search for the ending NUL to get the length to extract.


The real question is why are you using VB6 if you don't know VB6? It is not legally available for free and expensive to acquire legitimately now so newcomers have no excuse for tampering with it.
Reply With Quote
  #3  
Old 11-01-2015, 07:21 AM
Jmann84 Jmann84 is offline
Newcomer
 
Join Date: Nov 2015
Posts: 2
Default

Quote:
Originally Posted by dilettante View Post
You can use the MidB$() function on the array to extract a substring, then convert that to Unicode. To do this the offset will be a 1-based value, so keep that in mind.

You can also use InStrB() if necessary to search for the ending NUL to get the length to extract.


The real question is why are you using VB6 if you don't know VB6? It is not legally available for free and expensive to acquire legitimately now so newcomers have no excuse for tampering with it.
I have been developing in VB since 5.0, I have just not really ever had to read byte arrays from a protocol stream. Thanks for the answer tho, I will try this out and let you know how it goes.
Reply With Quote
  #4  
Old 11-02-2015, 02:24 PM
passel's Avatar
passelByte conversion? passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,015
Default

RTMP uses doubles for identifying a number of things (e.g. audioCodec, videoCodec, videoFunction etc...).
I don't know anything about RTMP, really, but looking at the sequence of bytes after id
40 E7 92 00 00 00 00 00 00 00
looked like a Big Endian Double format (a lot of Doubles holding integer values will start with exponent 40 xx ...).
Sure enough, if you byte swap the eight bytes into a double and display it in VB, the value is 48272, which is the number you passed to the server.

Since you gave the server the number that it is passing back to you, I don't see that you're getting a lot of additional information at this point, just in a different format (ASCII in, Big Endian Double out).
A quick, hardcoded, conversion as proof
Code:
Option Explicit
  Private Type dblBytesType
    b(7) As Byte
  End Type
  
  Private Type dblType
    d As Double
  End Type
  
Private Sub Command1_Click()
  Dim b As dblBytesType
  Dim d As dblType
  
  With b
    .b(7) = &H40 'reversing the bytes, going from BigEndian to LittleEndian order
    .b(6) = &HE7
    .b(5) = &H92
  End With
  LSet d = b       'Copy the eight bytes from the byte array into a Double
  Debug.Print d.d  'Print the double value out in the "debug" window.
End Sub
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

Last edited by passel; 11-02-2015 at 04:50 PM.
Reply With Quote
Reply

Tags
packet, account, unique, byte, kushisfig, code, server, send, receive, return, project, hours, familiar, arrays, belongs, vb6, appreciated, greatly, wracking, corresponds, brain, read, explain, rtmp, client


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Byte conversion?
Byte conversion?
Byte conversion? Byte conversion?
Byte conversion?
Byte conversion?
Byte conversion? Byte conversion? Byte conversion? Byte conversion? Byte conversion? Byte conversion? Byte conversion?
Byte conversion?
Byte conversion?
 
Byte conversion?
Byte conversion?
 
-->