CreateBankStream Littleendian
BlitzMax Forums/BlitzMax Programming/CreateBankStream Littleendian
| ||
How would I convert a bankstream to be littleendian? The following doesn't work for me - file=LittleEndianStream(CreateBankStream(bank)) Thanks |
| ||
nvm... |
| ||
This works for me:b:TBank = CreateBank( 4 ) PokeInt b, 0, $12345678 Print Print Hex( PeekInt( b, 0 ) ) Local TS:TStream = BigEndianStream( CreateBankStream( b ) ) Print Hex( ReadInt( TS ) ) I'm on an Intel PC, so little-endian is the default. The program converts the stream to big-endian and the displays these numbers: 12345678 78563412 I guess your second post implies this was already solved. |
| ||
Yes and no, that part works but I'm getting an exception later when calling ReadLong(). Works when using OpenStream but not from a BankStream. |
| ||
You're not running off the end of the bank are you? ReadLong needs eight bytes available. Or maybe it's a data alignment issue. If you are on a PowerPC then maybe a Long needs to be eight-byte aligned. |
| ||
A more complete story of what I'm attempting to do... http://blitzmax.com/Community/posts.php?topic=101238 I don't see why this would be any different from OpenStream. |
| ||
I can't think of anything but memory alignment, which would not be an issue with a stream, but might be with bank. What if you read the Long a byte at a time and build the result manually: Function MyReadLong:Long( stream:TStream ) Local b:Byte, val:Long, n:Int For n = 1 To 8 b = ReadByte( stream ) val = ( val Shr 8 ) | ( Long(b) Shl 56 ) Next Return val End Function |
| ||
Ok I figured out why this isn't working, silly but I still don't have a solution LoadBank needs a URL, I was passing the contents in AS the URL so the bank wasn't storing properly. So the question is how to I "create a url" for a string that I can pass into LoadBank. |
| ||
You could use CStrings and CreateStaticBank. Just remember that the bank needs to be 1 element longer than the string length because of the 0 at the end.SuperStrict Local Numbers:String = "1234" Local MyString:Byte Ptr = Numbers.ToCString() Local Bank:TBank = CreateStaticBank(MyString,Numbers.Length+1) For Local i:Int = 0 To 3 Print PeekByte(Bank,i) Next MemFree MyString |