@@ -7,6 +7,8 @@ namespace NetScape.Abstractions.Extensions
77{
88 public static class ByteBufferExtensions
99 {
10+ static Encoding Iso_8859 { get ; } = Encoding . GetEncoding ( "ISO-8859-1" ) ;
11+
1012 public static string ReadString ( this IByteBuffer buffer )
1113 {
1214 return ReadString ( buffer , 10 ) ;
@@ -23,6 +25,21 @@ public static string ReadString(this IByteBuffer buffer, int terminator)
2325 return strBldr . ToString ( ) ;
2426 }
2527
28+ public static void WriteSmart ( this IByteBuffer buffer , int value )
29+ {
30+ if ( value < 128 )
31+ buffer . WriteByte ( value ) ;
32+ else
33+ buffer . WriteShort ( 32768 + value ) ;
34+ }
35+
36+ public static void Write8859String ( this IByteBuffer buffer , string str )
37+ {
38+ byte [ ] bytes = Iso_8859 . GetBytes ( str ) ;
39+ buffer . WriteBytes ( bytes ) ;
40+ buffer . WriteByte ( 0 ) ;
41+ }
42+
2643 public static IByteBuffer CompressGzip ( this IByteBuffer buffer )
2744 {
2845 var data = buffer . GetBytes ( ) ;
@@ -79,8 +96,8 @@ public static void DecodeXtea(this IByteBuffer buffer, uint[] keys, int start, i
7996 k1 -= ( l1 >> 5 ^ l1 << 4 ) + l1 ^ keys [ sum & 3 ] + sum ;
8097 }
8198 buffer . SetReaderIndex ( buffer . ReaderIndex - 8 ) ;
82- buffer . WriteInt ( ( int ) k1 ) ;
83- buffer . WriteInt ( ( int ) l1 ) ;
99+ buffer . WriteInt ( ( int ) k1 ) ;
100+ buffer . WriteInt ( ( int ) l1 ) ;
84101 }
85102 buffer . SetReaderIndex ( l ) ;
86103 }
@@ -105,8 +122,8 @@ public static void EncodeXtea(this IByteBuffer buffer, uint[] keys, int start, i
105122 }
106123
107124 buffer . SetWriterIndex ( buffer . WriterIndex - 8 ) ;
108- buffer . WriteInt ( ( int ) l ) ;
109- buffer . WriteInt ( ( int ) i1 ) ;
125+ buffer . WriteInt ( ( int ) l ) ;
126+ buffer . WriteInt ( ( int ) i1 ) ;
110127 }
111128 buffer . SetWriterIndex ( o ) ;
112129 }
0 commit comments